Java Code Examples for javafx.scene.PerspectiveCamera#setNearClip()

The following examples show how to use javafx.scene.PerspectiveCamera#setNearClip() . 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: Drag3DObject.java    From FXyzLib with GNU General Public License v3.0 6 votes vote down vote up
private void loadCamera(Scene scene) {
    //initialize camera
    camera = new PerspectiveCamera(true);
    camera.setVerticalFieldOfView(RUN_JASON);

    //setup camera transform for rotational support
    cameraTransform.setTranslate(0, 0, 0);
    cameraTransform.getChildren().add(camera);
    camera.setNearClip(0.1);
    camera.setFarClip(100000.0);
    camera.setTranslateZ(-5000);
    cameraTransform.ry.setAngle(0.0);
    cameraTransform.rx.setAngle(-45.0);

    //add a Point Light for better viewing of the grid coordinate system
    PointLight light = new PointLight(Color.GAINSBORO);
    cameraTransform.getChildren().add(light);
    cameraTransform.getChildren().add(new AmbientLight(Color.WHITE));
    light.setTranslateX(camera.getTranslateX());
    light.setTranslateY(camera.getTranslateY());
    light.setTranslateZ(camera.getTranslateZ());
    //attach camera to scene
    scene.setCamera(camera);

}
 
Example 2
Source File: ViewFrustumTest.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Before
public void setUp()
{
	camera = new PerspectiveCamera(true);
	camera.setNearClip(0.1);
	camera.setFarClip(10.0);
	camera.setFieldOfView(45);
	camera.setVerticalFieldOfView(true);

	frustumCamera = new ViewFrustum(camera, new double[] {800, 600});

	cameraTransform = new AffineTransform3D();
	cameraTransform.setTranslation(0, 0, -1);

	sceneTransform = new AffineTransform3D();
	sceneTransform.set(
			-1.9735242914056459E-4, -1.0436920839427981E-4, -2.061953312972022E-4, 3.0306137875177632,
			-1.2649862727035413E-4, -1.7813723813362014E-4, 2.11240737752298E-4, 0.956379113095983,
			-1.9341029860978865E-4, 2.2300587509429097E-4, 7.223755022420857E-5, -1.1240682338705246
		);

	sourceToWorldTransform = new AffineTransform3D();
	sourceToWorldTransform.set(
			64.0, 0.0, 0.0, 3674.0,
			0.0, 64.0, 0.0, 3674.0,
			0.0, 0.0, 80.0, 1540.0
		);
}
 
Example 3
Source File: Qubit3D.java    From strangefx with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void createQubit() {
    PerspectiveCamera camera = new PerspectiveCamera(true);        
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.getTransforms().addAll(rotateX, rotateY, new Translate(0, 0, -200));
 
    FrustumMesh plane = new FrustumMesh(50, 50, 1, 1, new Point3D(0, -0.5f, 0), new Point3D(0, 0.5f, 0));
    plane.setMaterial(new PhongMaterial(Color.web("#ccdd3320")));
    
    SegmentedSphereMesh innerSphere = new SegmentedSphereMesh(40, 0, 0, 50, new Point3D(0, 0, 0));
    innerSphere.setMaterial(new PhongMaterial(Color.web("#ff800080")));
    
    SegmentedSphereMesh frameSphere = new SegmentedSphereMesh(20, 0, 0, 50, new Point3D(0, 0, 0));
    frameSphere.setMaterial(new PhongMaterial(Color.BLACK));
    frameSphere.setDrawMode(DrawMode.LINE);
    
    FrustumMesh rod = new FrustumMesh(2, 2, 1, 1, new Point3D(0, 0, 0), new Point3D(50, 0, 0));
    rod.setMaterial(new PhongMaterial(Color.web("#0080ff")));
    
    SegmentedSphereMesh smallSphere = new SegmentedSphereMesh(20, 0, 0, 4, new Point3D(50, 0, 0));
    smallSphere.setMaterial(new PhongMaterial(Color.web("#0080ff")));
    
    rodSphere = new Group(smallSphere, rod);
    Group group = new Group(plane, rodSphere, innerSphere, frameSphere, new AmbientLight(Color.BISQUE));
    
    SubScene subScene = new SubScene(group, 100, 100, true, SceneAntialiasing.BALANCED);
    subScene.setCamera(camera);
    
    subScene.setOnMousePressed(event -> {
        mouseOldX = event.getSceneX();
        mouseOldY = event.getSceneY();
    });

    subScene.setOnMouseDragged(event -> {
        rotateX.setAngle(rotateX.getAngle() - (event.getSceneY() - mouseOldY));
        rotateY.setAngle(rotateY.getAngle() + (event.getSceneX() - mouseOldX));
        mouseOldX = event.getSceneX();
        mouseOldY = event.getSceneY();
    });
    
    getChildren().add(subScene);
    
    rodSphere.getTransforms().setAll(myRotate);
}
 
Example 4
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 5
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 6
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 7
Source File: BillBoardBehaviorTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
private void createSubscene(){        
    subScene = new SubScene(root, 800, 600, true, SceneAntialiasing.BALANCED);
    
    camera = new PerspectiveCamera(true);
    cameraTransform.setTranslate(0, 0, 0);
    cameraTransform.getChildren().addAll(camera);
    camera.setNearClip(0.1);
    camera.setFarClip(100000.0);
    camera.setFieldOfView(35);
    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);
    subScene.setCamera(camera);
    
    initFirstPersonControls(subScene);
    
    skyBox = new Skybox(new Image("http://www.zfight.com/misc/images/textures/envmaps/violentdays_large.jpg"), 100000, camera);      
   
    //Make a bunch of semi random Torusesessses(toroids?) and stuff : from torustest
    Group torusGroup = new Group();        
    for (int i = 0; i < 10; 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());
        boolean ambientRandom = r.nextBoolean();
        boolean fillRandom = r.nextBoolean();
        
        if(i == 0){                
            torusGroup.getChildren().add(bill);
        }
        TorusMesh torus = new TorusMesh(randomTubeDivisions, randomRadiusDivisions, randomRadius, randomTubeRadius);
        
        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().addAll(skyBox, torusGroup);
    
    rootPane.getChildren().add(subScene);
    //Enable subScene resizing
    subScene.widthProperty().bind(rootPane.widthProperty());
    subScene.heightProperty().bind(rootPane.heightProperty());
    subScene.setFocusTraversable(true);
    
}
 
Example 8
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 9
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 10
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 11
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();        
}