Java Code Examples for javafx.scene.Scene#setCamera()

The following examples show how to use javafx.scene.Scene#setCamera() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MarsViewer.java    From mars-sim with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void start(Stage stage) {
	Group group = buildScene();

    Scene scene = new Scene(
      new StackPane(group),
      VIEWPORT_SIZE, VIEWPORT_SIZE,
      true,
      SceneAntialiasing.BALANCED
    );

    scene.setFill(Color.rgb(10, 10, 40));

    scene.setCamera(new PerspectiveCamera());

    stage.setScene(scene);
    stage.show();

    stage.setFullScreen(true);

    rotateAroundYAxis(group).play();
}
 
Example 2
Source File: Curbstone3D.java    From SmartCity-ParkingManagement with Apache License 2.0 5 votes vote down vote up
@Override
public void start(final Stage s) throws Exception {
	s.setTitle("Curbstone 3D");
	final Curbstone c = new Curbstone(50, Color.web("#DC143C"), 1);
	c.setTranslateX(0);
	c.rx.setAngle(25);
	c.ry.setAngle(45);

	final Timeline animation = new Timeline();
	animation.getKeyFrames().addAll(new KeyFrame(Duration.ZERO, new KeyValue(c.ry.angleProperty(), 0d)),
			new KeyFrame(Duration.valueOf("20000ms"), new KeyValue(c.ry.angleProperty(), 360d)));
	animation.setCycleCount(Animation.INDEFINITE);
	// create root group
	final Parent root = c;
	// translate and rotate group so that origin is center and +Y is up
	root.setTranslateX(200);
	root.setTranslateY(75);
	final Line line = new Line(200, 200, 200, 200);
	final Rotate rotation = new Rotate(1, Rotate.Y_AXIS);
	rotation.pivotXProperty().bind(line.startXProperty());
	rotation.pivotYProperty().bind(line.startYProperty());
	root.getTransforms().add(rotation);
	// create scene
	final Scene scene = new Scene(root, 400, 150);
	scene.setCamera(new PerspectiveCamera());
	s.setScene(scene);
	s.show();
	// start spining animation
	animation.play();
}
 
Example 3
Source File: TilesFxDemo.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start(Stage stage) {
	FlowGridPane pane = new FlowGridPane(7, 4, percentageTile, clockTile, gaugeTile, sparkLineTile, areaChartTile,
			lineChartTile, timerControlTile, numberTile, textTile, highLowTile, plusMinusTile, sliderTile,
			switchTile, timeTile, barChartTile, customTile, leaderBoardTile, worldTile, mapTile, radialChartTile,
			donutChartTile, circularProgressTile, stockTile, gaugeSparkLineTile, radarChartTile1, radarChartTile2,
			smoothAreaChartTile, countryTile, flipTile);// , weatherTile);

	pane.setHgap(5);
	pane.setVgap(5);
	pane.setAlignment(Pos.CENTER);
	pane.setCenterShape(true);
	pane.setPadding(new Insets(5));
	// pane.setPrefSize(800, 600);
	pane.setBackground(new Background(new BackgroundFill(Color.web("#101214"), CornerRadii.EMPTY, Insets.EMPTY)));

	PerspectiveCamera camera = new PerspectiveCamera();
	camera.setFieldOfView(7);
	
	Scene scene = new Scene(pane);
	scene.setCamera(camera);
	
	stage.setTitle("TilesFX");
	stage.setScene(scene);
	stage.show();

	timer.start();

	mapTile.addPoiLocation(new Location(51.85, 7.75, "Test"));
	mapTile.removePoiLocation(new Location(51.85, 7.75, "Test"));
}
 
Example 4
Source File: TilesDemo.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override public void start(Stage stage) {
    FlowGridPane pane = new FlowGridPane(7, 5,
                                         percentageTile, clockTile, gaugeTile, sparkLineTile, areaChartTile,
                                         lineChartTile, timerControlTile, numberTile, textTile,
                                         highLowTile, plusMinusTile, sliderTile, switchTile, timeTile,
                                         barChartTile, customTile, leaderBoardTile, worldTile, mapTile,
                                         radialChartTile, donutChartTile, circularProgressTile, stockTile,
                                         gaugeSparkLineTile, radarChartTile1, radarChartTile2,
                                         smoothAreaChartTile, countryTile, ephemerisTile, characterTile,
                                         flipTile, switchSliderTile, dateTile, calendarTile);//, weatherTile);

    pane.setHgap(5);
    pane.setVgap(5);
    pane.setAlignment(Pos.CENTER);
    pane.setCenterShape(true);
    pane.setPadding(new Insets(5));
    //pane.setPrefSize(800, 600);
    pane.setBackground(new Background(new BackgroundFill(Color.web("#101214"), CornerRadii.EMPTY, Insets.EMPTY)));

    PerspectiveCamera camera = new PerspectiveCamera();
    camera.setFieldOfView(10);

    Scene scene = new Scene(pane);
    scene.setCamera(camera);

    stage.setTitle("TilesFX");
    stage.setScene(scene);
    stage.show();

    timer.start();

    mapTile.addPoiLocation(new Location(51.85, 7.75, "Test"));
    mapTile.removePoiLocation(new Location(51.85, 7.75, "Test"));
}
 
Example 5
Source File: Snake3dApp.java    From FXTutorials with MIT License 5 votes vote down vote up
private Scene createScene() {
    Cube cube = new Cube(Color.BLUE);
    snake.getChildren().add(cube);

    moveFood();

    root.getChildren().addAll(snake, food);

    Scene scene = new Scene(root, 1280, 720, true);

    PerspectiveCamera camera = new PerspectiveCamera(true);
    camera.getTransforms().addAll(new Translate(0, -20, -20), new Rotate(-45, Rotate.X_AXIS));

    scene.setCamera(camera);

    timer = new AnimationTimer() {
        @Override
        public void handle(long now) {
            t += 0.016;

            if (t > 0.1) {
                onUpdate();
                t = 0;
            }
        }
    };

    timer.start();

    return scene;
}
 
Example 6
Source File: OctahedronTest.java    From FXyzLib with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start(Stage stage) {
    shapeGroup.getChildren().clear();
    generateShapes();
    root.getChildren().add(shapeGroup);
            
    camera = new AdvancedCamera();
    controller = new FPSController();
    
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setFieldOfView(42);
    camera.setController(controller);
    
    Scene scene = new Scene(new StackPane(root), 1024, 668, true, SceneAntialiasing.BALANCED);
    scene.setCamera(camera);
    scene.setFill(Color.BLACK);
    
    controller.setScene(scene);
    scene.setOnKeyPressed(event -> {
        //What key did the user press?
        KeyCode keycode = event.getCode();
        if(keycode == KeyCode.SPACE) {
            shapeGroup.getChildren().clear();
            generateShapes();                
        }
    });
    
    stage.setTitle("Random Octahedrons!");
    stage.setScene(scene);
    stage.show();
    stage.setFullScreen(false);
    stage.setFullScreenExitHint("");
}
 
Example 7
Source File: Demo.java    From Enzo with Apache License 2.0 5 votes vote down vote up
@Override public void start(Stage stage) {
    StackPane pane = new StackPane();
    pane.getChildren().addAll(control);

    Scene scene = new Scene(pane);
    scene.setCamera(new PerspectiveCamera(false));

    stage.setScene(scene);
    stage.show();

    timer.start();
}
 
Example 8
Source File: TrapezoidTest.java    From FXyzLib with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start(Stage stage) {
    shapeGroup.getChildren().clear();
    generateShapes();
    root.getChildren().add(shapeGroup);
            
    camera = new AdvancedCamera();
    controller = new FPSController();
    
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setFieldOfView(42);
    camera.setController(controller);
    
    Scene scene = new Scene(new StackPane(root), 1024, 668, true, SceneAntialiasing.BALANCED);
    scene.setCamera(camera);
    scene.setFill(Color.BLACK);
    
    controller.setScene(scene);
    scene.setOnKeyPressed(event -> {
        //What key did the user press?
        KeyCode keycode = event.getCode();
        if(keycode == KeyCode.SPACE) {
            shapeGroup.getChildren().clear();
            generateShapes();                
        }
    });
    
    stage.setTitle("Random Trapezoids!");
    stage.setScene(scene);
    stage.show();
    stage.setFullScreen(false);
    stage.setFullScreenExitHint("");
}
 
Example 9
Source File: ScatterPlotColorTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    Group sceneRoot = new Group();
    Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED);
    scene.setFill(Color.BLACK);
    camera = new PerspectiveCamera(true);        
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setTranslateZ(-1000);
    scene.setCamera(camera);
    
    scatterPlot = new ScatterPlot(1000, 1, true);
    sceneRoot.getChildren().addAll(scatterPlot);
    
    List<Double> dataX = new ArrayList<>();
    List<Double> dataY = new ArrayList<>();
    List<Double> dataZ = new ArrayList<>();
    List<Color> colors = new ArrayList<>();
    int k = 0;
    for(int i=-250;i<250;i++) {
        dataX.add(new Double(i));
        dataY.add(Math.sin(i)*50+i);
        dataZ.add(Math.cos(i)*50+i);
        colors.add(new Color(Math.abs(i) / 250D, Math.abs(dataY.get(k)) / 300D, Math.abs(dataZ.get(k) / 300D), 0.25));
        k++;
    }
        
    scatterPlot.setXYZData(dataX, dataY, dataZ, colors);

    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        //Add shift modifier to simulate "Running Speed"
        if(event.isShiftDown()) { change = 50.0; }
        //What key did the user press?
        KeyCode keycode = event.getCode();
        //Step 2c: Add Zoom controls
        if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); }
        if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); }
        //Step 2d:  Add Strafe controls
        if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); }
        if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); }
    });        
    
    //Add a Mouse Handler for Rotations
    Rotate xRotate = new Rotate(0, Rotate.X_AXIS);
    Rotate yRotate = new Rotate(0, Rotate.Y_AXIS);
    Rotate zRotate = new Rotate(0, Rotate.Z_AXIS);
    
    scatterPlot.getTransforms().addAll(xRotate, yRotate);
    //Use Binding so your rotation doesn't have to be recreated
    xRotate.angleProperty().bind(angleX);
    yRotate.angleProperty().bind(angleY);
    zRotate.angleProperty().bind(angleZ);
    
    //Start Tracking mouse movements only when a button is pressed
    scene.setOnMousePressed(event -> {
        scenex = event.getSceneX();
        sceney = event.getSceneY();
        fixedXAngle = angleX.get();
        fixedYAngle = angleY.get();
        if(event.isMiddleButtonDown()) {
            scenez = event.getSceneX();
            fixedZAngle = angleZ.get();
        }
        
    });
    //Angle calculation will only change when the button has been pressed
    scene.setOnMouseDragged(event -> {
        if(event.isMiddleButtonDown()) 
            angleZ.set(fixedZAngle - (scenez - event.getSceneY()));
        else
            angleX.set(fixedXAngle - (scenex - event.getSceneY()));
            
        
        angleY.set(fixedYAngle + sceney - event.getSceneX());
    });        
    
    primaryStage.setTitle("F(X)yz ScatterPlotColorTest");
    primaryStage.setScene(scene);
    primaryStage.show();        
}
 
Example 10
Source File: JavaFX3D.java    From JavaFX-Tutorial-Codes with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    Box box = new Box(100, 20, 50);

    SmartGroup group = new SmartGroup();
    group.getChildren().add(box);

    Camera camera = new PerspectiveCamera();
    Scene scene = new Scene(group, WIDTH, HEIGHT);
    scene.setFill(Color.SILVER);
    scene.setCamera(camera);

    group.translateXProperty().set(WIDTH / 2);
    group.translateYProperty().set(HEIGHT / 2);
    group.translateZProperty().set(-1500);

    initMouseControl(group, scene);

    primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
        switch (event.getCode()) {
            case W:
                group.translateZProperty().set(group.getTranslateZ() + 100);
                break;
            case S:
                group.translateZProperty().set(group.getTranslateZ() - 100);
                break;
            case Q:
                group.rotateByX(10);
                break;
            case E:
                group.rotateByX(-10);
                break;
            case NUMPAD6:
                group.rotateByY(10);
                break;
            case NUMPAD4:
                group.rotateByY(-10);
                break;
        }
    });

    primaryStage.setTitle("Genuine Coder");
    primaryStage.setScene(scene);
    primaryStage.show();
}
 
Example 11
Source File: ScatterPlotMeshTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    Group sceneRoot = new Group();
    Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED);
    scene.setFill(Color.BLACK);
    camera = new PerspectiveCamera(true);        
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setTranslateZ(-1000);
    scene.setCamera(camera);
    
    scatterPlotMesh = new ScatterPlotMesh(1000, 1, true);
    sceneRoot.getChildren().addAll(scatterPlotMesh);
    
    ArrayList<Double> dataX = new ArrayList<>();
    ArrayList<Double> dataY = new ArrayList<>();
    ArrayList<Double> dataZ = new ArrayList<>();
    for(int i=-250;i<250;i++) {
        dataX.add(new Double(i));
        dataY.add(new Double(Math.sin(i)*50)+i);
        dataZ.add(new Double(Math.cos(i)*50)+i);
    }
        
    scatterPlotMesh.setXYZData(dataX, dataY, dataZ);

    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        //Add shift modifier to simulate "Running Speed"
        if(event.isShiftDown()) { change = 50.0; }
        //What key did the user press?
        KeyCode keycode = event.getCode();
        //Step 2c: Add Zoom controls
        if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); }
        if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); }
        //Step 2d:  Add Strafe controls
        if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); }
        if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); }
    });        
    
    //Add a Mouse Handler for Rotations
    Rotate xRotate = new Rotate(0, Rotate.X_AXIS);
    Rotate yRotate = new Rotate(0, Rotate.Y_AXIS);
    Rotate zRotate = new Rotate(0, Rotate.Z_AXIS);
    
    scatterPlotMesh.getTransforms().addAll(xRotate, yRotate);
    //Use Binding so your rotation doesn't have to be recreated
    xRotate.angleProperty().bind(angleX);
    yRotate.angleProperty().bind(angleY);
    zRotate.angleProperty().bind(angleZ);
    
    //Start Tracking mouse movements only when a button is pressed
    scene.setOnMousePressed(event -> {
        scenex = event.getSceneX();
        sceney = event.getSceneY();
        fixedXAngle = angleX.get();
        fixedYAngle = angleY.get();
        if(event.isMiddleButtonDown()) {
            scenez = event.getSceneX();
            fixedZAngle = angleZ.get();
        }
        
    });
    //Angle calculation will only change when the button has been pressed
    scene.setOnMouseDragged(event -> {
        if(event.isMiddleButtonDown()) 
            angleZ.set(fixedZAngle - (scenez - event.getSceneY()));
        else
            angleX.set(fixedXAngle - (scenex - event.getSceneY()));
            
        
        angleY.set(fixedYAngle + sceney - event.getSceneX());
    });        
    
    primaryStage.setTitle("F(X)yz ScatterPlotTest");
    primaryStage.setScene(scene);
    primaryStage.show();        
}
 
Example 12
Source File: SurfacePlotTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    Group sceneRoot = new Group();
    Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED);
    scene.setFill(Color.BLACK);
    camera = new PerspectiveCamera(true);        
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setTranslateZ(-1000);
    scene.setCamera(camera);
    int size = 10;
    float [][] arrayY = new float[2*size][2*size];
    //The Sombrero
    for(int i=-size;i<size;i++) {
        for(int j=-size;j<size;j++) {
            double R = Math.sqrt((i * i)  + (j * j)) + 0.00000000000000001;
            arrayY[i+size][j+size] = ((float) -(Math.sin(R)/R)) * 100;
        }
    }
    surfacePlot = new SurfacePlot(arrayY, 10, Color.AQUA, false, false);

    sceneRoot.getChildren().addAll(surfacePlot);

    PointLight light = new PointLight(Color.WHITE);
    sceneRoot.getChildren().add(light);
    light.setTranslateZ(sceneWidth / 2);
    light.setTranslateY(-sceneHeight + 10);

    PointLight light2 = new PointLight(Color.WHITE);
    sceneRoot.getChildren().add(light2);
    light2.setTranslateZ(-sceneWidth + 10);
    light2.setTranslateY(-sceneHeight + 10);
    
    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        //Add shift modifier to simulate "Running Speed"
        if(event.isShiftDown()) { change = 50.0; }
        //What key did the user press?
        KeyCode keycode = event.getCode();
        //Step 2c: Add Zoom controls
        if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); }
        if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); }
        //Step 2d:  Add Strafe controls
        if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); }
        if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); }
    });        
    
    //Add a Mouse Handler for Rotations
    Rotate xRotate = new Rotate(0, Rotate.X_AXIS);
    Rotate yRotate = new Rotate(0, Rotate.Y_AXIS);
    Rotate zRotate = new Rotate(0, Rotate.Z_AXIS);
    
    surfacePlot.getTransforms().addAll(xRotate, yRotate, zRotate);
    //Use Binding so your rotation doesn't have to be recreated
    xRotate.angleProperty().bind(angleX);
    yRotate.angleProperty().bind(angleY);
    zRotate.angleProperty().bind(angleZ);
    
    //Start Tracking mouse movements only when a button is pressed
    scene.setOnMousePressed(event -> {
        scenex = event.getSceneX();
        sceney = event.getSceneY();
        fixedXAngle = angleX.get();
        fixedYAngle = angleY.get();
        if(event.isMiddleButtonDown()) {
            scenez = event.getSceneX();
            fixedZAngle = angleZ.get();
        }
        
    });
    //Angle calculation will only change when the button has been pressed
    scene.setOnMouseDragged(event -> {
        if(event.isMiddleButtonDown()) 
            angleZ.set(fixedZAngle - (scenez - event.getSceneY()));
        else
            angleX.set(fixedXAngle - (scenex - event.getSceneY()));
        angleY.set(fixedYAngle + sceney - event.getSceneX());
    });        
    
    primaryStage.setTitle("F(X)yz SurfacePlotTest");
    primaryStage.setScene(scene);
    primaryStage.show();        
}
 
Example 13
Source File: SpheroidTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void start(Stage stage) {
    
    Group spheroidGroup = new Group();        
    for (int i = 0; i < 50; i++) {
        Random r = new Random();
        //A lot of magic numbers in here that just artificially constrain the math
        float randomMajorRadius = (float) ((r.nextFloat() * 300) + 50);
        float randomMinorRadius = (float) ((r.nextFloat() * 300) + 50);
        int randomDivisions = (int) ((r.nextFloat() * 64) + 1);
        Color randomColor = new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble());
        
        Spheroid sm = new Spheroid(randomDivisions, randomMajorRadius, randomMinorRadius, randomColor);               
        sm.setDrawMode(DrawMode.LINE);
        double translationX = Math.random() * 1024 * 1.95;
        if (Math.random() >= 0.5) {
            translationX *= -1;
        }
        double translationY = Math.random() * 1024 * 1.95;
        if (Math.random() >= 0.5) {
            translationY *= -1;
        }
        double translationZ = Math.random() * 1024 * 1.95;
        if (Math.random() >= 0.5) {
            translationZ *= -1;
        }
        Translate translate = new Translate(translationX, translationY, translationZ);
        Rotate rotateX = new Rotate(Math.random() * 360, Rotate.X_AXIS);
        Rotate rotateY = new Rotate(Math.random() * 360, Rotate.Y_AXIS);
        Rotate rotateZ = new Rotate(Math.random() * 360, Rotate.Z_AXIS);

        sm.getTransforms().addAll(translate, rotateX, rotateY, rotateZ);
        
        spheroidGroup.getChildren().add(sm);
    }
    root.getChildren().add(spheroidGroup);
    
    System.out.println(spheroidGroup.getChildren().size());
    
    camera = new PerspectiveCamera(true);
    cameraTransform.setTranslate(0, 0, 0);
    cameraTransform.getChildren().addAll(camera);
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setFieldOfView(42);
    camera.setTranslateZ(cameraDistance);
    cameraTransform.ry.setAngle(-45.0);
    cameraTransform.rx.setAngle(-10.0);
    //add a Point Light for better viewing of the grid coordinate system
    PointLight light = new PointLight(Color.WHITE);
    
    cameraTransform.getChildren().add(light);
    light.setTranslateX(camera.getTranslateX());
    light.setTranslateY(camera.getTranslateY());
    light.setTranslateZ(camera.getTranslateZ());
    root.getChildren().add(cameraTransform);
    
    Scene scene = new Scene(new StackPane(root), 1024, 668, true, SceneAntialiasing.BALANCED);
    scene.setCamera(camera);
    scene.setFill(Color.BLACK);
    initFirstPersonControls(scene);
    
    stage.setTitle("Hello World!");
    stage.setScene(scene);
    stage.show();
}
 
Example 14
Source File: PolyLine3DTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    Group sceneRoot = new Group();
    Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED);
    scene.setFill(Color.BLACK);
    camera = new PerspectiveCamera(true);        
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setTranslateZ(-1000);
    scene.setCamera(camera);
    
    ArrayList<Point3D> points = new ArrayList<>();
    for(int i=-250;i<250;i++) {
        points.add(new Point3D(
                    (float) i,
                    (float) Math.sin(i)*50+i,
                    (float) Math.cos(i)*50+i));
    }
    polyLine3D = new PolyLine3D(points,3,Color.STEELBLUE);    
    sceneRoot.getChildren().addAll(polyLine3D);

    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        //Add shift modifier to simulate "Running Speed"
        if(event.isShiftDown()) { change = 50.0; }
        //What key did the user press?
        KeyCode keycode = event.getCode();
        //Step 2c: Add Zoom controls
        if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); }
        if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); }
        //Step 2d:  Add Strafe controls
        if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); }
        if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); }
    });        
    
    //Add a Mouse Handler for Rotations
    Rotate xRotate = new Rotate(0, Rotate.X_AXIS);
    Rotate yRotate = new Rotate(0, Rotate.Y_AXIS);
    Rotate zRotate = new Rotate(0, Rotate.Z_AXIS);
    
    polyLine3D.getTransforms().addAll(xRotate, yRotate);
    //Use Binding so your rotation doesn't have to be recreated
    xRotate.angleProperty().bind(angleX);
    yRotate.angleProperty().bind(angleY);
    zRotate.angleProperty().bind(angleZ);
    
    //Start Tracking mouse movements only when a button is pressed
    scene.setOnMousePressed(event -> {
        scenex = event.getSceneX();
        sceney = event.getSceneY();
        fixedXAngle = angleX.get();
        fixedYAngle = angleY.get();
        if(event.isMiddleButtonDown()) {
            scenez = event.getSceneX();
            fixedZAngle = angleZ.get();
        }
        
    });
    //Angle calculation will only change when the button has been pressed
    scene.setOnMouseDragged(event -> {
        if(event.isMiddleButtonDown()) 
            angleZ.set(fixedZAngle - (scenez - event.getSceneY()));
        else
            angleX.set(fixedXAngle - (scenex - event.getSceneY()));
        angleY.set(fixedYAngle + sceney - event.getSceneX());
    });        
    
    primaryStage.setTitle("F(X)yz ScatterPlotTest");
    primaryStage.setScene(scene);
    primaryStage.show();        
}
 
Example 15
Source File: ScatterPlotTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    Group sceneRoot = new Group();
    Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED);
    scene.setFill(Color.BLACK);
    camera = new PerspectiveCamera(true);        
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setTranslateZ(-1000);
    scene.setCamera(camera);
    
    scatterPlot = new ScatterPlot(1000, 1, true);
    sceneRoot.getChildren().addAll(scatterPlot);
    
    ArrayList<Double> dataX = new ArrayList<>();
    ArrayList<Double> dataY = new ArrayList<>();
    ArrayList<Double> dataZ = new ArrayList<>();
    for(int i=-250;i<250;i++) {
        dataX.add(new Double(i));
        dataY.add(new Double(Math.sin(i)*50)+i);
        dataZ.add(new Double(Math.cos(i)*50)+i);
    }
        
    scatterPlot.setXYZData(dataX, dataY, dataZ);

    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        //Add shift modifier to simulate "Running Speed"
        if(event.isShiftDown()) { change = 50.0; }
        //What key did the user press?
        KeyCode keycode = event.getCode();
        //Step 2c: Add Zoom controls
        if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); }
        if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); }
        //Step 2d:  Add Strafe controls
        if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); }
        if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); }
    });        
    
    //Add a Mouse Handler for Rotations
    Rotate xRotate = new Rotate(0, Rotate.X_AXIS);
    Rotate yRotate = new Rotate(0, Rotate.Y_AXIS);
    Rotate zRotate = new Rotate(0, Rotate.Z_AXIS);
    
    scatterPlot.getTransforms().addAll(xRotate, yRotate);
    //Use Binding so your rotation doesn't have to be recreated
    xRotate.angleProperty().bind(angleX);
    yRotate.angleProperty().bind(angleY);
    zRotate.angleProperty().bind(angleZ);
    
    //Start Tracking mouse movements only when a button is pressed
    scene.setOnMousePressed(event -> {
        scenex = event.getSceneX();
        sceney = event.getSceneY();
        fixedXAngle = angleX.get();
        fixedYAngle = angleY.get();
        if(event.isMiddleButtonDown()) {
            scenez = event.getSceneX();
            fixedZAngle = angleZ.get();
        }
        
    });
    //Angle calculation will only change when the button has been pressed
    scene.setOnMouseDragged(event -> {
        if(event.isMiddleButtonDown()) 
            angleZ.set(fixedZAngle - (scenez - event.getSceneY()));
        else
            angleX.set(fixedXAngle - (scenex - event.getSceneY()));
            
        
        angleY.set(fixedYAngle + sceney - event.getSceneX());
    });        
    
    primaryStage.setTitle("F(X)yz ScatterPlotTest");
    primaryStage.setScene(scene);
    primaryStage.show();        
}
 
Example 16
Source File: ConeTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void start(Stage stage) {
    
    Group coneGroup = new Group();        
    for (int i = 0; i < 100; i++) {
        Random r = new Random();
        //A lot of magic numbers in here that just artificially constrain the math
        float randomRadius = (float) ((r.nextFloat()*100) + 25);
        float randomHeight = (float) ((r.nextFloat()*300)+ 75);
        int randomDivisions = (int) ((r.nextFloat()*50) + 5);
        Color randomColor = new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble());
        
        Cone cone = new Cone(randomDivisions, randomRadius, randomHeight, randomColor);               
        cone.setEmissiveLightingColor(randomColor);
        cone.setEmissiveLightingOn(r.nextBoolean());
        cone.setDrawMode(r.nextBoolean() ? DrawMode.FILL : DrawMode.LINE);
        
        double translationX = Math.random() * 1024;
        if (Math.random() >= 0.5) {
            translationX *= -1;
        }
        double translationY = Math.random() * 1024;
        if (Math.random() >= 0.5) {
            translationY *= -1;
        }
        double translationZ = Math.random() * 1024;
        if (Math.random() >= 0.5) {
            translationZ *= -1;
        }
        Translate translate = new Translate(translationX, translationY, translationZ);
        Rotate rotateX = new Rotate(Math.random() * 360, Rotate.X_AXIS);
        Rotate rotateY = new Rotate(Math.random() * 360, Rotate.Y_AXIS);
        Rotate rotateZ = new Rotate(Math.random() * 360, Rotate.Z_AXIS);

        cone.getTransforms().addAll(translate, rotateX, rotateY, rotateZ);
        
        coneGroup.getChildren().add(cone);
    }
    root.getChildren().add(coneGroup);
    
    camera = new AdvancedCamera();
    controller = new FPSController();
    
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setFieldOfView(42);
    camera.setController(controller);
    
    Scene scene = new Scene(new StackPane(root), 1024, 668, true, SceneAntialiasing.BALANCED);
    scene.setCamera(camera);
    scene.setFill(Color.BLACK);
    
    controller.setScene(scene);
            
    stage.setTitle("Random Cones!");
    stage.setScene(scene);
    stage.show();
    stage.setFullScreen(false);
    stage.setFullScreenExitHint("");
}
 
Example 17
Source File: HistogramTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    Group sceneRoot = new Group();
    Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED);
    scene.setFill(Color.BLACK);
    camera = new PerspectiveCamera(true);
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setTranslateZ(-1000);
    scene.setCamera(camera);

    histogram = new Histogram(1000, 1, true);
    sceneRoot.getChildren().addAll(histogram);

    int size = 30;
    float[][] arrayY = new float[2 * size][2 * size];
    for (int i = -size; i < size; i++) {
        for (int j = -size; j < size; j++) {
            //Transcedental Gradient
            double xterm = (Math.cos(Math.PI * i / size) * Math.cos(Math.PI * i / size));
            double yterm = (Math.cos(Math.PI * j / size) * Math.cos(Math.PI * j / size));
            arrayY[i + size][j + size] = (float) (10 * ((xterm + yterm) * (xterm + yterm)));
        }
    }
    histogram.setHeightData(arrayY, 1, 4, Color.SKYBLUE, false, true);

    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        //Add shift modifier to simulate "Running Speed"
        if (event.isShiftDown()) {
            change = 50.0;
        }
        //What key did the user press?
        KeyCode keycode = event.getCode();
        //Step 2c: Add Zoom controls
        if (keycode == KeyCode.W) {
            camera.setTranslateZ(camera.getTranslateZ() + change);
        }
        if (keycode == KeyCode.S) {
            camera.setTranslateZ(camera.getTranslateZ() - change);
        }
        //Step 2d:  Add Strafe controls
        if (keycode == KeyCode.A) {
            camera.setTranslateX(camera.getTranslateX() - change);
        }
        if (keycode == KeyCode.D) {
            camera.setTranslateX(camera.getTranslateX() + change);
        }
    });

    //Add a Mouse Handler for Rotations
    Rotate xRotate = new Rotate(0, Rotate.X_AXIS);
    Rotate yRotate = new Rotate(0, Rotate.Y_AXIS);
    Rotate zRotate = new Rotate(0, Rotate.Z_AXIS);

    histogram.getTransforms().addAll(xRotate, yRotate);
    //Use Binding so your rotation doesn't have to be recreated
    xRotate.angleProperty().bind(angleX);
    yRotate.angleProperty().bind(angleY);
    zRotate.angleProperty().bind(angleZ);

    //Start Tracking mouse movements only when a button is pressed
    scene.setOnMousePressed(event -> {
        scenex = event.getSceneX();
        sceney = event.getSceneY();
        fixedXAngle = angleX.get();
        fixedYAngle = angleY.get();
        if (event.isMiddleButtonDown()) {
            scenez = event.getSceneX();
            fixedZAngle = angleZ.get();
        }

    });
    //Angle calculation will only change when the button has been pressed
    scene.setOnMouseDragged(event -> {
        if (event.isMiddleButtonDown()) {
            angleZ.set(fixedZAngle - (scenez - event.getSceneY()));
        } else {
            angleX.set(fixedXAngle - (scenex - event.getSceneY()));
        }

        angleY.set(fixedYAngle + sceney - event.getSceneX());
    });

    primaryStage.setTitle("F(X)yz HistogramTest");
    primaryStage.setScene(scene);
    primaryStage.show();
}
 
Example 18
Source File: FPSControllerTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void start(Stage stage) {
    Group root = new Group();
    //Make a bunch of semi random Torusesessses(toroids?) and stuff : from torustest
    Group torusGroup = new Group();
    for (int i = 0; i < 30; i++) {
        Random r = new Random();
        //A lot of magic numbers in here that just artificially constrain the math
        float randomRadius = (float) ((r.nextFloat() * 300) + 50);
        float randomTubeRadius = (float) ((r.nextFloat() * 100) + 1);
        int randomTubeDivisions = (int) ((r.nextFloat() * 64) + 1);
        int randomRadiusDivisions = (int) ((r.nextFloat() * 64) + 1);
        Color randomColor = new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble());

        Torus torus = new Torus(randomTubeDivisions, randomRadiusDivisions, randomRadius, randomTubeRadius, randomColor);
        torus.setEmissiveLightingColor(randomColor);
        torus.setEmissiveLightingOn(r.nextBoolean());
        
        double translationX = Math.random() * 1024 * 1.95;
        if (Math.random() >= 0.5) {
            translationX *= -1;
        }
        double translationY = Math.random() * 1024 * 1.95;
        if (Math.random() >= 0.5) {
            translationY *= -1;
        }
        double translationZ = Math.random() * 1024 * 1.95;
        if (Math.random() >= 0.5) {
            translationZ *= -1;
        }
        Translate translate = new Translate(translationX, translationY, translationZ);
        Rotate rotateX = new Rotate(Math.random() * 360, Rotate.X_AXIS);
        Rotate rotateY = new Rotate(Math.random() * 360, Rotate.Y_AXIS);
        Rotate rotateZ = new Rotate(Math.random() * 360, Rotate.Z_AXIS);

        torus.getTransforms().addAll(translate, rotateX, rotateY, rotateZ);
        //torus.getTransforms().add(translate);
        torusGroup.getChildren().add(torus);

    }
    root.getChildren().add(torusGroup);
    
    
    Scene scene = new Scene(root, 1400, 1000, true, SceneAntialiasing.BALANCED);
    scene.setFill(Color.BLACK);
    
    stage.setTitle("SimpleFPSControllerTest");
    stage.setScene(scene);
    stage.show();
    //stage.setMaximized(true);
    
    FPSController controller = new FPSController();
    controller.setScene(scene);
    controller.setMouseLookEnabled(true);
    
    AdvancedCamera camera = new AdvancedCamera();
    camera.setController(controller);
    
    root.getChildren().add(camera);
    
    scene.setCamera(camera);
}
 
Example 19
Source File: CapsuleTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void start(Stage stage) {
    
    Group capsuleGroup = new Group();        
    for (int i = 0; i < 50; i++) {
        Random r = new Random();
        //A lot of magic numbers in here that just artificially constrain the math
        float randomRadius = (float) ((r.nextFloat() * 100) + 25);
        float randomHeight = (float) ((r.nextFloat() * 300) + 75);
        Color randomColor = new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble());
        
        Capsule cap = new Capsule(randomRadius, randomHeight, randomColor);               
        cap.setEmissiveLightingColor(randomColor);
        cap.setEmissiveLightingOn(r.nextBoolean());
        cap.setDrawMode(r.nextBoolean() ? DrawMode.FILL : DrawMode.LINE);
        
        double translationX = Math.random() * 1024 * 1.95;
        if (Math.random() >= 0.5) {
            translationX *= -1;
        }
        double translationY = Math.random() * 1024 * 1.95;
        if (Math.random() >= 0.5) {
            translationY *= -1;
        }
        double translationZ = Math.random() * 1024 * 1.95;
        if (Math.random() >= 0.5) {
            translationZ *= -1;
        }
        Translate translate = new Translate(translationX, translationY, translationZ);
        Rotate rotateX = new Rotate(Math.random() * 360, Rotate.X_AXIS);
        Rotate rotateY = new Rotate(Math.random() * 360, Rotate.Y_AXIS);
        Rotate rotateZ = new Rotate(Math.random() * 360, Rotate.Z_AXIS);

        cap.getTransforms().addAll(translate, rotateX, rotateY, rotateZ);
        
        capsuleGroup.getChildren().add(cap);
    }
    
    root.getChildren().add(capsuleGroup);
            
    camera = new AdvancedCamera();
    controller = new FPSController();
    
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setFieldOfView(42);
    camera.setController(controller);
    
    Scene scene = new Scene(new StackPane(root), 1024, 668, true, SceneAntialiasing.BALANCED);
    scene.setCamera(camera);
    scene.setFill(Color.BLACK);
    
    controller.setScene(scene);
            
    stage.setTitle("Hello World!");
    stage.setScene(scene);
    stage.show();
    stage.setFullScreen(true);
    stage.setFullScreenExitHint("");
}
 
Example 20
Source File: MqttListener.java    From diozero with MIT License 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
	primaryStage.setResizable(false);
	Scene scene = new Scene(root, 1024, 800, true);
	
	// Create and position camera
	Camera camera = new PerspectiveCamera();
	camera.getTransforms().addAll(
			new Rotate(0, Rotate.Y_AXIS),
			new Rotate(0, Rotate.X_AXIS),
			new Translate(-500, -425, 1200));
	scene.setCamera(camera);
	scene.setFill(Paint.valueOf(Color.BLACK.toString()));
	
	// Box
	testObject = new Cylinder(10, 50);
	testObject.setMaterial(new PhongMaterial(Color.RED));
	testObject.getTransforms().addAll(new Translate(50, 0, 0));
	
	TdsModelImporter model_importer = new TdsModelImporter();
	model_importer.read(getClass().getResource("/models/SpaceLaunchSystem.3DS"));
	Node[] nodes = model_importer.getImport();
	model_importer.close();
	Group rocket = new Group(nodes);
	rocket.getTransforms().addAll(new Translate(0, 25, 0));

	// Build the Scene Graph
	root.getChildren().addAll(testObject, rocket);

	primaryStage.setScene(scene);
	primaryStage.show();
	
	primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
		@Override
		public void handle(WindowEvent event) {
			System.out.println(event);
			if (event.getEventType().equals(WindowEvent.WINDOW_CLOSE_REQUEST)) {
				System.exit(0);
			}
		}
	});
	
	mqttClient.subscribe(MQTT_TOPIC_IMU + "/#");
}