// EarthShape.java
// See copyright.txt for license and terms of use.

package earthshape;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.SceneAntialiasing;
import javafx.scene.SubScene;
import javafx.scene.image.Image;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.Material;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;
import javafx.scene.shape.DrawMode;
import javafx.scene.shape.Sphere;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Translate;
import javafx.stage.Stage;

/** This application demonstrates a procedure for inferring the shape
  * of a surface (such as the Earth) based on the observed locations of
  * stars from various locations at a fixed point in time. */
public class EarthShape extends Application {
    // Try holding a persistent Translate object so I can move
    // the camera.
    private Translate cameraTranslate = new Translate(0, 0, -15);

    public Parent createContent() throws Exception {

        // Texture?
        Image img = new Image("earthshape/textures/compass-rose.png");

        // Material
        PhongMaterial mat = new PhongMaterial();
        mat.setDiffuseMap(img);

        // Box
        Box testBox = new Box(5, 5, 5);
        testBox.setMaterial(mat);
        //testBox.setMaterial(new PhongMaterial(Color.RED));
        //testBox.setDrawMode(DrawMode.LINE);

        // X axis
        PhongMaterial axisColor = new PhongMaterial(Color.RED);
        Box xaxis = new Box(100, 0.1, 0.1);
        xaxis.setMaterial(axisColor);

        // Some sphere
        Sphere s = new Sphere(2.7);
        s.setMaterial(new PhongMaterial(Color.BLUE));

        // Create and position camera
        PerspectiveCamera camera = new PerspectiveCamera(true);
        camera.getTransforms().addAll (
                new Rotate(-20, Rotate.Y_AXIS),
                new Rotate(-20, Rotate.X_AXIS),
                this.cameraTranslate);

        // Build the Scene Graph
        Group root = new Group();
        root.getChildren().add(camera);
        root.getChildren().add(xaxis);
        root.getChildren().add(s);
        root.getChildren().add(testBox);

        // Use a SubScene
        SubScene subScene = new SubScene(root, 300,300, true /*depth buffer*/,
                                         SceneAntialiasing.BALANCED);
        subScene.setFill(Color.ALICEBLUE);
        subScene.setCamera(camera);

        // Put the sub-scene into a group.  (I do not understand this.)
        Group group = new Group();
        group.getChildren().add(subScene);
        return group;
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setResizable(false);
        Scene scene = new Scene(createContent());

        // Specify keyboard handling for the scene.
        scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
            @Override
            public void handle(KeyEvent event) {
                // Very rudimentary WASD response.
                Translate t = EarthShape.this.cameraTranslate;
                switch (event.getCode()) {
                    case W:
                        t.setZ(t.getZ() + 1);
                        break;

                    case A:
                        t.setX(t.getX() - 1);
                        break;

                    case S:
                        t.setZ(t.getZ() - 1);
                        break;

                    case D:
                        t.setX(t.getX() + 1);
                        break;

                    default:
                        break;
                }
            }
        });

        primaryStage.setTitle("Simple 3D Box App");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args)
    {
        Application.launch(args);
    }
}

@@ -189,36 +189,8 @@
 up;%0A
-import javafx.scene.Parent;%0A
 impo
@@ -255,77 +255,8 @@
 ne;%0A
-import javafx.scene.SceneAntialiasing;%0Aimport javafx.scene.SubScene;%0A
 impo
@@ -357,44 +357,8 @@
 or;%0A
-import javafx.scene.paint.Material;%0A
 impo
@@ -429,78 +429,8 @@
 ox;%0A
-import javafx.scene.shape.DrawMode;%0Aimport javafx.scene.shape.Sphere;%0A
 impo
@@ -946,28 +946,32 @@
 lic 
-Parent
+Group
  create
-Content
+SceneObjects
 () t
@@ -1560,421 +1560,37 @@
  // 
-Some sphere%0A        Sphere s = new Sphere(2.7);%0A        s.setMaterial(new PhongMaterial(Color.BLUE));%0A%0A        // Create and position camera%0A        PerspectiveCamera camera = new PerspectiveCamera(true);%0A        camera.getTransforms().addAll (%0A                new Rotate(-20, Rotate.Y_AXIS),%0A                new Rotate(-20, Rotate.X_AXIS),%0A                this.cameraTranslate);%0A%0A        // Build the Scene Graph
+Collect the objects together.
 %0A   
@@ -1651,22 +1651,21 @@
 n().add(
-camera
+xaxis
 );%0A     
@@ -1682,37 +1682,39 @@
 tChildren().add(
-xaxis
+testBox
 );%0A        root.
@@ -1713,101 +1713,162 @@
    r
-oot.getChildren().add(s)
+eturn root
 ;%0A    
+%7D%0A%0A
     
-root.getChildren().add(testBox);%0A%0A        // Use a SubScene
+@Override%0A    public void start(Stage primaryStage) throws Exception %7B%0A        // Create a scene containing the scene object graph.
 %0A   
@@ -1876,21 +1876,15 @@
     
-Sub
 Scene s
-ubS
 cene
@@ -1894,122 +1894,100 @@
 new 
-Sub
 Scene(
-root, 300,300, true /*depth buffer*/,%0A                                         SceneAntialiasing.BALANCED
+createSceneObjects(), 1024, 768,%0A                                true /*depth buffer*/
 );%0A 
@@ -1986,35 +1986,32 @@
 er*/);%0A        s
-ubS
 cene.setFill(Col
@@ -2025,24 +2025,25 @@
 EBLUE);%0A
+%0A
         
 subScene
@@ -2038,36 +2038,37 @@
     
-subScene.setCamera(
+// Create and position 
 camera
-);%0A
 %0A   
@@ -2076,343 +2076,269 @@
     
-// Put the sub-scene into a group.  (I do not understand this.)%0A        Group group = new Group();%0A        group.getChildren().add(subScene);%0A        return group;%0A
+PerspectiveCamera camera = new PerspectiveCamera(true);%0A        camera.getTransforms().addAll (%0A                new Rotate(-20, Rotate.Y_AXIS),%0A 
     
-%7D%0A%0A
     
-@Override%0A    public void start(Stage primaryStage) throws Exception %7B%0A        primaryStage.setResizable(false);%0A        Scene scene = new Scene(createContent()
+       new Rotate(-20, Rotate.X_AXIS),%0A                this.cameraTranslate);%0A        scene.setCamera(camera
 );%0A%0A
@@ -3242,25 +3242,19 @@
 le(%22
-Simple 3D Box App
+Earth Shape
 %22);%0A

Allow window to resize; remove SubScene; remove sphere. This is some cleanup of things from first3d I do not want.