Search in sources :

Example 36 with PerspectiveCamera

use of javafx.scene.PerspectiveCamera in project FXyzLib by Birdasaur.

the class SpheroidTest method start.

@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();
}
Also used : Group(javafx.scene.Group) Rotate(javafx.scene.transform.Rotate) Color(javafx.scene.paint.Color) Spheroid(org.fxyz.shapes.Spheroid) PerspectiveCamera(javafx.scene.PerspectiveCamera) Scene(javafx.scene.Scene) Random(java.util.Random) PointLight(javafx.scene.PointLight) Translate(javafx.scene.transform.Translate) StackPane(javafx.scene.layout.StackPane)

Example 37 with PerspectiveCamera

use of javafx.scene.PerspectiveCamera in project FXyzLib by Birdasaur.

the class SurfacePlotTest method start.

@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();
}
Also used : Group(javafx.scene.Group) Rotate(javafx.scene.transform.Rotate) SurfacePlot(org.fxyz.shapes.composites.SurfacePlot) KeyCode(javafx.scene.input.KeyCode) PerspectiveCamera(javafx.scene.PerspectiveCamera) Scene(javafx.scene.Scene) PointLight(javafx.scene.PointLight)

Example 38 with PerspectiveCamera

use of javafx.scene.PerspectiveCamera in project FXyzLib by Birdasaur.

the class SimpleRayTest method start.

@Override
public void start(Stage primaryStage) throws Exception {
    // add cameraTransform so it doesn't affect all nodes
    rayLight.getScope().add(cameraTransform);
    camera = new PerspectiveCamera(true);
    cameraTransform.setTranslate(0, 0, 0);
    cameraTransform.getChildren().addAll(camera);
    camera.setNearClip(0.1);
    camera.setFarClip(1000000.0);
    camera.setFieldOfView(42);
    camera.setTranslateZ(-5000);
    PointLight light = new PointLight(Color.GAINSBORO);
    PointLight light2 = new PointLight(Color.YELLOW);
    light2.setTranslateY(-2000);
    // create a target
    target1 = new Sphere(100);
    target1.setTranslateX(300);
    target1.setTranslateY(300);
    target1.setTranslateZ(1000);
    target1.setMaterial(red);
    // create another target
    target2 = new Sphere(100);
    target2.setTranslateX(800);
    target2.setTranslateY(-1200);
    target2.setTranslateZ(-500);
    target2.setMaterial(blue);
    root.getChildren().addAll(cameraTransform, target1, target2, light, light2, rayLight);
    root.setAutoSizeChildren(false);
    Scene scene = new Scene((root), 1200, 800, true, SceneAntialiasing.BALANCED);
    scene.setCamera(camera);
    Stop[] stops = new Stop[] { new Stop(0, Color.BLACK), new Stop(0.5, Color.DEEPSKYBLUE.darker()), new Stop(1.0, Color.BLACK) };
    LinearGradient lg = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, stops);
    scene.setFill(lg);
    // First person shooter keyboard movement
    scene.setOnKeyPressed(ke -> {
        double change = 10.0;
        // Add shift modifier to simulate "Running Speed"
        if (ke.isShiftDown()) {
            change = 50.0;
        }
        // What key did the user press?
        KeyCode keycode = ke.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 flag so we can still move the camera
        if (keycode == KeyCode.CONTROL) {
            fireRay = false;
        }
    });
    scene.setOnKeyReleased(ke -> {
        // release flag
        if (ke.getCode().equals(KeyCode.CONTROL)) {
            fireRay = true;
        }
    });
    scene.setOnMousePressed(e -> {
        mousePosX = e.getSceneX();
        mousePosY = e.getSceneY();
        mouseOldX = e.getSceneX();
        mouseOldY = e.getSceneY();
        if (fireRay) {
            // use PickResult because it is already transformed
            Point3D o = e.getPickResult().getIntersectedPoint();
            if (e.isPrimaryButtonDown()) {
                // set Target and Direction
                Point3D t = Point3D.ZERO.add(target2.getTranslateX(), target2.getTranslateY(), target2.getTranslateZ()), d = t.subtract(o);
                // Build the Ray
                Ray r = new Ray(o, d);
                double dist = t.distance(o);
                // If ray intersects node, spawn and animate
                if (target2.getBoundsInParent().contains(r.project(dist))) {
                    animateRayTo(r, target2, Duration.seconds(2));
                    System.out.println("Target Contains Ray!\n" + r + "\nTarget Bounds: " + target2.getBoundsInParent() + "\nDistance: " + dist + "\n");
                }
                e.consume();
            } else // repeat for other target as well
            if (e.isSecondaryButtonDown()) {
                Point3D tgt = Point3D.ZERO.add(target1.getTranslateX(), target1.getTranslateY(), target1.getTranslateZ()), dir = tgt.subtract(o);
                Ray r = new Ray(o, dir);
                double dist = tgt.distance(o);
                if (target1.getBoundsInParent().contains(r.project(dist))) {
                    animateRayTo(r, target1, Duration.seconds(2));
                    System.out.println("Target Contains Ray: " + target1.getBoundsInParent().contains(r.project(dist)) + "\n" + r + "\nTarget Bounds: " + target1.getBoundsInParent() + "\nDistance: " + dist + "\n");
                }
                e.consume();
            }
        }
    });
    scene.setOnMouseDragged(e -> {
        if (!fireRay) {
            mouseOldX = mousePosX;
            mouseOldY = mousePosY;
            mousePosX = e.getSceneX();
            mousePosY = e.getSceneY();
            mouseDeltaX = (mousePosX - mouseOldX);
            mouseDeltaY = (mousePosY - mouseOldY);
            double modifier = 10.0;
            double modifierFactor = 0.1;
            if (e.isControlDown()) {
                modifier = 0.1;
            }
            if (e.isShiftDown()) {
                modifier = 50.0;
            }
            if (e.isPrimaryButtonDown()) {
                // +
                cameraTransform.ry.setAngle(((cameraTransform.ry.getAngle() + mouseDeltaX * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
                // -
                cameraTransform.rx.setAngle(((cameraTransform.rx.getAngle() - mouseDeltaY * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
            } else if (e.isSecondaryButtonDown()) {
                double z = camera.getTranslateZ();
                double newZ = z + mouseDeltaX * modifierFactor * modifier;
                camera.setTranslateZ(newZ);
            } else if (e.isMiddleButtonDown()) {
                // -
                cameraTransform.t.setX(cameraTransform.t.getX() + mouseDeltaX * modifierFactor * modifier * 0.3);
                // -
                cameraTransform.t.setY(cameraTransform.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3);
            }
        }
    });
    primaryStage.setTitle("Hello Ray! Animated Visual of a Ray casting");
    primaryStage.setScene(scene);
    primaryStage.show();
}
Also used : Sphere(javafx.scene.shape.Sphere) LinearGradient(javafx.scene.paint.LinearGradient) Stop(javafx.scene.paint.Stop) Point3D(javafx.geometry.Point3D) KeyCode(javafx.scene.input.KeyCode) PerspectiveCamera(javafx.scene.PerspectiveCamera) Ray(org.fxyz.geometry.Ray) PointLight(javafx.scene.PointLight) Scene(javafx.scene.Scene)

Example 39 with PerspectiveCamera

use of javafx.scene.PerspectiveCamera in project FXyzLib by Birdasaur.

the class SphereSegmentTest method start.

@Override
public void start(Stage primaryStage) throws Exception {
    Group sceneRoot = new Group();
    Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight);
    scene.setFill(Color.BLACK);
    camera = new PerspectiveCamera(true);
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setTranslateZ(-1000);
    scene.setCamera(camera);
    // Make a bunch of semi random sphere segments and stuff
    Group sphereGroup = 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() * 150) + 10);
        float randomThetaMax = (float) ((r.nextFloat() * 360) + 1);
        float randomThetaMin = (float) ((r.nextFloat()) + 1);
        if (randomThetaMin > randomThetaMax) {
            float swap = randomThetaMin;
            randomThetaMin = randomThetaMax;
            randomThetaMax = swap;
        }
        float randomPolarMax = (float) ((r.nextFloat() * 90) + 1);
        float randomPolarMin = (float) ((r.nextFloat()) + 1);
        if (randomPolarMin > randomPolarMax) {
            float swap = randomPolarMin;
            randomPolarMin = randomPolarMax;
            randomPolarMax = swap;
        }
        int randomSegments = (int) ((r.nextFloat() * 15) + 5);
        Color randomColor = new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble());
        boolean ambientRandom = r.nextBoolean();
        boolean fillRandom = r.nextBoolean();
        SphereSegment sphereSegment = new SphereSegment(randomRadius, randomColor, Math.toRadians(0), Math.toRadians(360), Math.toRadians(randomPolarMin), Math.toRadians(randomPolarMax), randomSegments, ambientRandom, fillRandom);
        double translationX = Math.random() * sceneWidth / 2;
        if (Math.random() >= 0.5)
            translationX *= -1;
        double translationY = Math.random() * sceneWidth / 2;
        if (Math.random() >= 0.5)
            translationY *= -1;
        double translationZ = Math.random() * sceneWidth / 2;
        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);
        sphereSegment.getTransforms().addAll(translate, rotateX, rotateY, rotateZ);
        sphereSegment.getTransforms().add(translate);
        sphereGroup.getChildren().add(sphereSegment);
    }
    sceneRoot.getChildren().addAll(sphereGroup);
    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);
    sphereGroup.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 SphereSegmentTest");
    primaryStage.setScene(scene);
    primaryStage.show();
}
Also used : Group(javafx.scene.Group) Rotate(javafx.scene.transform.Rotate) SphereSegment(org.fxyz.shapes.SphereSegment) Color(javafx.scene.paint.Color) PerspectiveCamera(javafx.scene.PerspectiveCamera) Scene(javafx.scene.Scene) Random(java.util.Random) KeyCode(javafx.scene.input.KeyCode) Translate(javafx.scene.transform.Translate)

Example 40 with PerspectiveCamera

use of javafx.scene.PerspectiveCamera in project FXyzLib by Birdasaur.

the class TetrahedraTest method start.

@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.WHITESMOKE);
    camera = new PerspectiveCamera(true);
    // setup camera transform for rotational support
    cameraTransform.setTranslate(0, 0, 0);
    cameraTransform.getChildren().add(camera);
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setTranslateZ(-30);
    // 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(10 * camera.getTranslateZ());
    scene.setCamera(camera);
    rotateY = new Rotate(0, 0, 0, 0, Rotate.Y_AXIS);
    Group group = new Group();
    group.getChildren().add(cameraTransform);
    tetra = new TetrahedraMesh(10, 7, null);
    // cylinder = new PrismMesh(0.2,2,3); //,new Point3D(-5,5,0),new Point3D(0,0,5));
    tetra.setDrawMode(DrawMode.LINE);
    tetra.setCullFace(CullFace.NONE);
    // NONE
    // cylinder.setTextureModeNone(Color.ROYALBLUE);
    // IMAGE
    // tetra.setTextureModeImage(getClass().getResource("res/steel-mesh.jpg").toExternalForm());
    // tetra.setTextureModeVertices1D(6, t->t);
    // cylinder.setColorPalette(ColorPalette.GREEN);
    // DENSITY
    tetra.setTextureModeVertices3D(1530, p -> p.magnitude());
    // cylinder.setTextureModeVertices3D(1530,p->(double)cylinder.unTransform(p).magnitude());
    // FACES
    // tetra.setTextureModeFaces(1530);
    tetra.getTransforms().addAll(new Rotate(0, Rotate.X_AXIS), rotateY);
    group.getChildren().add(tetra);
    sceneRoot.getChildren().addAll(group);
    // First person shooter keyboard movement
    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);
        }
    });
    scene.setOnMousePressed((MouseEvent me) -> {
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseOldX = me.getSceneX();
        mouseOldY = me.getSceneY();
    });
    scene.setOnMouseDragged((MouseEvent me) -> {
        mouseOldX = mousePosX;
        mouseOldY = mousePosY;
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseDeltaX = (mousePosX - mouseOldX);
        mouseDeltaY = (mousePosY - mouseOldY);
        double modifier = 10.0;
        double modifierFactor = 0.1;
        if (me.isControlDown()) {
            modifier = 0.1;
        }
        if (me.isShiftDown()) {
            modifier = 50.0;
        }
        if (me.isPrimaryButtonDown()) {
            // +
            cameraTransform.ry.setAngle(((cameraTransform.ry.getAngle() + mouseDeltaX * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
            // -
            cameraTransform.rx.setAngle(((cameraTransform.rx.getAngle() - mouseDeltaY * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
        } else if (me.isSecondaryButtonDown()) {
            double z = camera.getTranslateZ();
            double newZ = z + mouseDeltaX * modifierFactor * modifier;
            camera.setTranslateZ(newZ);
        } else if (me.isMiddleButtonDown()) {
            // -
            cameraTransform.t.setX(cameraTransform.t.getX() + mouseDeltaX * modifierFactor * modifier * 0.3);
            // -
            cameraTransform.t.setY(cameraTransform.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3);
        }
    });
    primaryStage.setTitle("F(X)yz - Tetrahedra Test");
    primaryStage.setScene(scene);
    primaryStage.show();
    // OBJWriter writer=new OBJWriter((TriangleMesh) cylinder.getMesh(),"cylinder2");
    // //        writer.setMaterialColor(Color.AQUA);
    // //        writer.setTextureImage(getClass().getResource("res/netCylinder.png").toExternalForm());
    // writer.setTextureColors(6,ColorPalette.GREEN);
    // writer.exportMesh();
    lastEffect = System.nanoTime();
    AtomicInteger count = new AtomicInteger(0);
    AnimationTimer timerEffect = new AnimationTimer() {

        @Override
        public void handle(long now) {
            if (now > lastEffect + 100_000_000l) {
                // <=1/6d)?1d:0d;
                func = t -> Math.pow(Math.sin(8d * Math.PI * (10d * (1 - t.doubleValue()) + count.get() % 11) / 20d), 6);
                // cylinder.setFunction(func);
                // mapBez.values().forEach(b->b.setDensity(dens));
                count.getAndIncrement();
                lastEffect = now;
            }
        }
    };
// timerEffect.start();
}
Also used : Group(javafx.scene.Group) MouseEvent(javafx.scene.input.MouseEvent) Rotate(javafx.scene.transform.Rotate) AnimationTimer(javafx.animation.AnimationTimer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TetrahedraMesh(org.fxyz.shapes.primitives.TetrahedraMesh) KeyCode(javafx.scene.input.KeyCode) PerspectiveCamera(javafx.scene.PerspectiveCamera) Scene(javafx.scene.Scene) PointLight(javafx.scene.PointLight)

Aggregations

PerspectiveCamera (javafx.scene.PerspectiveCamera)51 Scene (javafx.scene.Scene)36 Group (javafx.scene.Group)31 KeyCode (javafx.scene.input.KeyCode)31 PointLight (javafx.scene.PointLight)28 Rotate (javafx.scene.transform.Rotate)25 MouseEvent (javafx.scene.input.MouseEvent)23 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 AnimationTimer (javafx.animation.AnimationTimer)14 KeyFrame (javafx.animation.KeyFrame)12 KeyValue (javafx.animation.KeyValue)12 Timeline (javafx.animation.Timeline)12 Point3D (org.fxyz.geometry.Point3D)11 AmbientLight (javafx.scene.AmbientLight)10 Translate (javafx.scene.transform.Translate)10 Color (javafx.scene.paint.Color)9 ArrayList (java.util.ArrayList)8 Interpolator (javafx.animation.Interpolator)7 OBJWriter (org.fxyz.utils.OBJWriter)7 PhongMaterial (javafx.scene.paint.PhongMaterial)6