Search in sources :

Example 16 with MouseEvent

use of javafx.scene.input.MouseEvent in project Gargoyle by callakrsos.

the class Clock method start.

public void start(final Stage stage) throws Exception {
    // construct the analogueClock pieces.
    final Circle face = new Circle(100, 100, 100);
    face.setId("face");
    final Label brand = new Label("Splotch");
    brand.setId("brand");
    brand.layoutXProperty().bind(face.centerXProperty().subtract(brand.widthProperty().divide(2)));
    brand.layoutYProperty().bind(face.centerYProperty().add(face.radiusProperty().divide(2)));
    final Line hourHand = new Line(0, 0, 0, -50);
    hourHand.setTranslateX(100);
    hourHand.setTranslateY(100);
    hourHand.setId("hourHand");
    final Line minuteHand = new Line(0, 0, 0, -75);
    minuteHand.setTranslateX(100);
    minuteHand.setTranslateY(100);
    minuteHand.setId("minuteHand");
    final Line secondHand = new Line(0, 15, 0, -88);
    secondHand.setTranslateX(100);
    secondHand.setTranslateY(100);
    secondHand.setId("secondHand");
    final Circle spindle = new Circle(100, 100, 5);
    spindle.setId("spindle");
    Group ticks = new Group();
    for (int i = 0; i < 12; i++) {
        Line tick = new Line(0, -83, 0, -93);
        tick.setTranslateX(100);
        tick.setTranslateY(100);
        tick.getStyleClass().add("tick");
        tick.getTransforms().add(new Rotate(i * (360 / 12)));
        ticks.getChildren().add(tick);
    }
    final Group analogueClock = new Group(face, brand, ticks, spindle, hourHand, minuteHand, secondHand);
    // construct the digitalClock pieces.
    final Label digitalClock = new Label();
    digitalClock.setId("digitalClock");
    // determine the starting time.
    Calendar calendar = GregorianCalendar.getInstance();
    final double seedSecondDegrees = calendar.get(Calendar.SECOND) * (360 / 60);
    final double seedMinuteDegrees = (calendar.get(Calendar.MINUTE) + seedSecondDegrees / 360.0) * (360 / 60);
    final double seedHourDegrees = (calendar.get(Calendar.HOUR) + seedMinuteDegrees / 360.0) * (360 / 12);
    // define rotations to map the analogueClock to the current time.
    final Rotate hourRotate = new Rotate(seedHourDegrees);
    final Rotate minuteRotate = new Rotate(seedMinuteDegrees);
    final Rotate secondRotate = new Rotate(seedSecondDegrees);
    hourHand.getTransforms().add(hourRotate);
    minuteHand.getTransforms().add(minuteRotate);
    secondHand.getTransforms().add(secondRotate);
    // the hour hand rotates twice a day.
    final Timeline hourTime = new Timeline(new KeyFrame(Duration.hours(12), new KeyValue(hourRotate.angleProperty(), 360 + seedHourDegrees, Interpolator.LINEAR)));
    // the minute hand rotates once an hour.
    final Timeline minuteTime = new Timeline(new KeyFrame(Duration.minutes(60), new KeyValue(minuteRotate.angleProperty(), 360 + seedMinuteDegrees, Interpolator.LINEAR)));
    // move second hand rotates once a minute.
    final Timeline secondTime = new Timeline(new KeyFrame(Duration.seconds(60), new KeyValue(secondRotate.angleProperty(), 360 + seedSecondDegrees, Interpolator.LINEAR)));
    // the digital clock updates once a second.
    final Timeline digitalTime = new Timeline(new KeyFrame(Duration.seconds(0), new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent actionEvent) {
            Calendar calendar = GregorianCalendar.getInstance();
            String hourString = pad(2, '0', calendar.get(Calendar.HOUR) == 0 ? "12" : calendar.get(Calendar.HOUR) + "");
            String minuteString = pad(2, '0', calendar.get(Calendar.MINUTE) + "");
            String secondString = pad(2, '0', calendar.get(Calendar.SECOND) + "");
            String ampmString = calendar.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM";
            digitalClock.setText(hourString + ":" + minuteString + ":" + secondString + " " + ampmString);
        }
    }), new KeyFrame(Duration.seconds(1)));
    // time never ends.
    hourTime.setCycleCount(Animation.INDEFINITE);
    minuteTime.setCycleCount(Animation.INDEFINITE);
    secondTime.setCycleCount(Animation.INDEFINITE);
    digitalTime.setCycleCount(Animation.INDEFINITE);
    // start the analogueClock.
    digitalTime.play();
    secondTime.play();
    minuteTime.play();
    hourTime.play();
    stage.initStyle(StageStyle.TRANSPARENT);
    // add a glow effect whenever the mouse is positioned over the clock.
    final Glow glow = new Glow();
    analogueClock.setOnMouseEntered(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent mouseEvent) {
            analogueClock.setEffect(glow);
        }
    });
    analogueClock.setOnMouseExited(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent mouseEvent) {
            analogueClock.setEffect(null);
        }
    });
    // fade out the scene and shut it down when the mouse is clicked on the
    // clock.
    analogueClock.setOnMouseClicked(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent mouseEvent) {
            analogueClock.setMouseTransparent(true);
            FadeTransition fade = new FadeTransition(Duration.seconds(1.2), analogueClock);
            fade.setOnFinished(new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent actionEvent) {
                    stage.close();
                }
            });
            fade.setFromValue(1);
            fade.setToValue(0);
            fade.play();
        }
    });
    // layout the scene.
    final VBox layout = new VBox();
    layout.getChildren().addAll(analogueClock, digitalClock);
    layout.setAlignment(Pos.CENTER);
    final Scene scene = new Scene(layout, Color.TRANSPARENT);
    scene.getStylesheets().add(getResource("clock.css"));
    stage.setScene(scene);
    // allow the clock background to be used to drag the clock around.
    final Delta dragDelta = new Delta();
    layout.setOnMousePressed(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent mouseEvent) {
            // record a delta distance for the drag and drop operation.
            dragDelta.x = stage.getX() - mouseEvent.getScreenX();
            dragDelta.y = stage.getY() - mouseEvent.getScreenY();
            scene.setCursor(Cursor.MOVE);
        }
    });
    layout.setOnMouseReleased(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent mouseEvent) {
            scene.setCursor(Cursor.HAND);
        }
    });
    layout.setOnMouseDragged(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent mouseEvent) {
            stage.setX(mouseEvent.getScreenX() + dragDelta.x);
            stage.setY(mouseEvent.getScreenY() + dragDelta.y);
        }
    });
    layout.setOnMouseEntered(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent mouseEvent) {
            if (!mouseEvent.isPrimaryButtonDown()) {
                scene.setCursor(Cursor.HAND);
            }
        }
    });
    layout.setOnMouseExited(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent mouseEvent) {
            if (!mouseEvent.isPrimaryButtonDown()) {
                scene.setCursor(Cursor.DEFAULT);
            }
        }
    });
    // show the scene.
    stage.show();
}
Also used : MouseEvent(javafx.scene.input.MouseEvent) Rotate(javafx.scene.transform.Rotate) Label(javafx.scene.control.Label) Glow(javafx.scene.effect.Glow) VBox(javafx.scene.layout.VBox)

Example 17 with MouseEvent

use of javafx.scene.input.MouseEvent in project Gargoyle by callakrsos.

the class Drag3DObject method loadControls.

private void loadControls(Scene scene) {
    //First person shooter keyboard movement  
    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        if (event.isShiftDown()) {
            change = 50.0;
        }
        KeyCode keycode = event.getCode();
        if (keycode == KeyCode.W) {
            camera.setTranslateZ(camera.getTranslateZ() + change);
        }
        if (keycode == KeyCode.S) {
            camera.setTranslateZ(camera.getTranslateZ() - change);
        }
        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();
        PickResult pr = me.getPickResult();
        if (pr != null && pr.getIntersectedNode() != null && pr.getIntersectedNode() instanceof Sphere) {
            distance = pr.getIntersectedDistance();
            s = (Sphere) pr.getIntersectedNode();
            isPicking = true;
            vecIni = unProjectDirection(mousePosX, mousePosY, scene.getWidth(), scene.getHeight());
        }
    });
    scene.setOnMouseDragged((MouseEvent me) -> {
        mouseOldX = mousePosX;
        mouseOldY = mousePosY;
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseDeltaX = (mousePosX - mouseOldX);
        mouseDeltaY = (mousePosY - mouseOldY);
        if (RUN_JASON) {
            //objPos += mouseMovementx*scale*RightAxis 
            if (isPicking) {
                if (mousePosX < mouseOldX) {
                    System.out.println("moving left");
                    Point3D pos = CameraHelper.pickProjectPlane(camera, mousePosX, mousePosY);
                    s.setTranslateX(s.getTranslateX() + (pos.getX() - mouseOldX) * camera.getNearClip());
                    return;
                } else if (mousePosX > mouseOldX) {
                    System.err.println("moving right");
                    Point3D pos = CameraHelper.pickProjectPlane(camera, mousePosX, mousePosY);
                    s.setTranslateX(s.getTranslateX() - (pos.getX() - mouseOldX) * camera.getNearClip());
                    return;
                }
                if (mousePosY < mouseOldY) {
                    System.out.println("moving up");
                } else if (mousePosY > mouseOldY) {
                    System.err.println("moving down");
                }
                return;
            }
        } else {
            if (isPicking) {
                double modifier = (me.isControlDown() ? 0.2 : me.isAltDown() ? 2.0 : 1) * (30d / camera.getFieldOfView());
                modifier *= (30d / camera.getFieldOfView());
                vecPos = unProjectDirection(mousePosX, mousePosY, scene.getWidth(), scene.getHeight());
                Point3D p = new Point3D(distance * (vecPos.x - vecIni.x), distance * (vecPos.y - vecIni.y), distance * (vecPos.z - vecIni.z));
                s.getTransforms().add(new Translate(modifier * p.getX(), 0, modifier * p.getZ()));
                vecIni = vecPos;
            } else {
                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);
                }
            }
        }
    });
    scene.setOnMouseReleased((MouseEvent me) -> {
        if (isPicking) {
            isPicking = false;
        }
    });
}
Also used : Sphere(javafx.scene.shape.Sphere) MouseEvent(javafx.scene.input.MouseEvent) Point3D(javafx.geometry.Point3D) PickResult(javafx.scene.input.PickResult) KeyCode(javafx.scene.input.KeyCode) Translate(javafx.scene.transform.Translate)

Example 18 with MouseEvent

use of javafx.scene.input.MouseEvent in project trex-stateless-gui by cisco-system-traffic-generator.

the class NotificationPanel method buildUI.

/**
     * Build component UI
     */
private void buildUI() {
    this.setSpacing(5);
    // add notification message
    notificationContainer = new Pane();
    notificationContainer.setPrefSize(184, 64);
    notificationContainer.getStyleClass().add("notificationContainer");
    notificationLabel = new Label();
    notificationLabel.setPrefSize(155, 60);
    notificationLabel.setWrapText(true);
    notificationLabel.getStyleClass().add("notificationMsg");
    notificationContainer.getChildren().add(notificationLabel);
    getChildren().add(notificationContainer);
    // add notification icon
    VBox iconHolder = new VBox();
    iconHolder.setPrefHeight(68);
    iconHolder.setAlignment(Pos.CENTER);
    ImageView notificationIcon = new ImageView(new Image("/icons/info_icon.png"));
    notificationIcon.getStyleClass().add("notificationIcon");
    notificationIcon.setOnMouseClicked((MouseEvent event) -> {
        notificationContainer.setVisible(!notificationContainer.isVisible());
    });
    iconHolder.getChildren().add(notificationIcon);
    getChildren().add(iconHolder);
}
Also used : MouseEvent(javafx.scene.input.MouseEvent) Label(javafx.scene.control.Label) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image) Pane(javafx.scene.layout.Pane) VBox(javafx.scene.layout.VBox)

Example 19 with MouseEvent

use of javafx.scene.input.MouseEvent in project FXyzLib by Birdasaur.

the class FrustumTest 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);
    //        cylinder = new PrismMesh(2,5,4);
    //,new Point3D(-5,5,0),new Point3D(0,0,5));
    cylinder = new FrustumMesh(1, 0.2, 4, 3);
    //        cylinder.setDrawMode(DrawMode.LINE);
    // SECTION TYPE
    //        cylinder.setSectionType(TriangleMeshHelper.SectionType.TRIANGLE);
    // NONE
    //        cylinder.setTextureModeNone(Color.ROYALBLUE);
    // IMAGE
    //        cylinder.setTextureModeImage(getClass().getResource("res/netCylinder.png").toExternalForm());
    cylinder.setTextureModeVertices1D(1530, t -> t);
    //        cylinder.setColorPalette(ColorPalette.GREEN);
    // DENSITY
    //        cylinder.setTextureModeVertices3D(1530,p->(double)p.y);
    //        cylinder.setTextureModeVertices3D(1530,p->(double)cylinder.unTransform(p).magnitude());
    // FACES
    //        cylinder.setTextureModeFaces(1530);
    cylinder.getTransforms().addAll(new Rotate(0, Rotate.X_AXIS), rotateY);
    group.getChildren().add(cylinder);
    boolean showKnots = true;
    if (showKnots) {
        Sphere s = new Sphere(cylinder.getMajorRadius() / 10d);
        Point3D k0 = cylinder.getAxisOrigin();
        s.getTransforms().add(new Translate(k0.x, k0.y, k0.z));
        s.setMaterial(new PhongMaterial(Color.GREENYELLOW));
        group.getChildren().add(s);
        s = new Sphere(cylinder.getMinorRadius() / 10d);
        Point3D k3 = cylinder.getAxisEnd();
        s.getTransforms().add(new Translate(k3.x, k3.y, k3.z));
        s.setMaterial(new PhongMaterial(Color.ROSYBROWN));
        group.getChildren().add(s);
    }
    sceneRoot.getChildren().addAll(group);
    //First person shooter keyboard movement 
    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        if (event.isShiftDown()) {
            change = 50.0;
        }
        KeyCode keycode = event.getCode();
        if (keycode == KeyCode.W) {
            camera.setTranslateZ(camera.getTranslateZ() + change);
        }
        if (keycode == KeyCode.S) {
            camera.setTranslateZ(camera.getTranslateZ() - change);
        }
        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 - Cylinder 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) FrustumMesh(org.fxyz.shapes.primitives.FrustumMesh) PerspectiveCamera(javafx.scene.PerspectiveCamera) Scene(javafx.scene.Scene) Sphere(javafx.scene.shape.Sphere) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Point3D(org.fxyz.geometry.Point3D) KeyCode(javafx.scene.input.KeyCode) PointLight(javafx.scene.PointLight) PhongMaterial(javafx.scene.paint.PhongMaterial) Translate(javafx.scene.transform.Translate)

Example 20 with MouseEvent

use of javafx.scene.input.MouseEvent in project FXyzLib by Birdasaur.

the class Function2DPlotTest 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(-20);
    cameraTransform.ry.setAngle(-45.0);
    cameraTransform.rx.setAngle(-30.0);
    //add a Point Light for better viewing of the grid coordinate system
    PointLight light = new PointLight(Color.WHITE);
    cameraTransform.getChildren().add(light);
    //        cameraTransform.getChildren().add(new AmbientLight(Color.WHITE));
    light.setTranslateX(camera.getTranslateX());
    light.setTranslateY(camera.getTranslateY());
    light.setTranslateZ(camera.getTranslateZ());
    scene.setCamera(camera);
    rotateY = new Rotate(0, 0, 0, 0, Rotate.Y_AXIS);
    Group group = new Group();
    group.getChildren().add(cameraTransform);
    surface = new SurfacePlotMesh(p -> Math.sin(p.magnitude() + 0.00000000000000001) / (p.magnitude() + 0.00000000000000001), 10, 10, 10, 10, 5d);
    //        PhongMaterial matTorus = new PhongMaterial(Color.FIREBRICK);
    //        torus.setMaterial(matTorus);
    //        surface.setDrawMode(DrawMode.LINE);
    surface.setCullFace(CullFace.NONE);
    // NONE
    //        surface.setTextureModeNone(Color.FORESTGREEN);
    // IMAGE
    //        torus.setTextureModeImage(getClass().getResource("res/grid1.png").toExternalForm());
    //        banner.setTextureModeImage(getClass().getResource("res/Duke3DprogressionSmall.jpg").toExternalForm());
    // PATTERN
    surface.setTextureModePattern(CarbonPatterns.CARBON_KEVLAR, 1.0d);
    // DENSITY
    //        surface.setTextureModeVertices3D(1530,dens);
    // FACES
    //        torus.setTextureModeFaces(256*256);
    surface.getTransforms().addAll(new Rotate(0, Rotate.X_AXIS), rotateY);
    group.getChildren().addAll(surface);
    sceneRoot.getChildren().addAll(group);
    //First person shooter keyboard movement 
    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        if (event.isShiftDown()) {
            change = 50.0;
        }
        KeyCode keycode = event.getCode();
        if (keycode == KeyCode.W) {
            camera.setTranslateZ(camera.getTranslateZ() + change);
        }
        if (keycode == KeyCode.S) {
            camera.setTranslateZ(camera.getTranslateZ() - change);
        }
        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);
        }
    });
    lastEffect = System.nanoTime();
    AtomicInteger count = new AtomicInteger();
    AnimationTimer timerEffect = new AnimationTimer() {

        @Override
        public void handle(long now) {
            if (now > lastEffect + 1_000_000_000l) {
                //                    dens = p->(float)(p.x*Math.cos(count.get()%100d*2d*Math.PI/50d)+p.y*Math.sin(count.get()%100d*2d*Math.PI/50d));
                //                    torus.setDensity(dens);
                //                    if(count.get()%100<50){
                //                        torus.setDrawMode(DrawMode.LINE);
                //                    } else {
                //                        torus.setDrawMode(DrawMode.FILL);
                //                    }
                //                    spring.setLength(100+20*(count.get()%10));
                //                    torus.setColors((int)Math.pow(2,count.get()%16));
                //                    torus.setMajorRadius(500+100*(count.get()%10));
                //                    torus.setMinorRadius(150+10*(count.get()%10));
                //                    torus.setPatternScale(1d+(count.get()%10)*5d);
                count.getAndIncrement();
                lastEffect = now;
            }
        }
    };
    primaryStage.setTitle("F(X)yz - Surface Plot 2D");
    primaryStage.setScene(scene);
    primaryStage.show();
//        timerEffect.start();
}
Also used : Scene(javafx.scene.Scene) KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) CarbonPatterns(org.fxyz.utils.Patterns.CarbonPatterns) Rotate(javafx.scene.transform.Rotate) SurfacePlotMesh(org.fxyz.shapes.primitives.SurfacePlotMesh) MouseEvent(javafx.scene.input.MouseEvent) PointLight(javafx.scene.PointLight) Group(javafx.scene.Group) DrawMode(javafx.scene.shape.DrawMode) Function(java.util.function.Function) CullFace(javafx.scene.shape.CullFace) Application(javafx.application.Application) AnimationTimer(javafx.animation.AnimationTimer) PerspectiveCamera(javafx.scene.PerspectiveCamera) CameraTransformer(org.fxyz.cameras.CameraTransformer) Stage(javafx.stage.Stage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Patterns(org.fxyz.utils.Patterns) SceneAntialiasing(javafx.scene.SceneAntialiasing) Point3D(org.fxyz.geometry.Point3D) Group(javafx.scene.Group) MouseEvent(javafx.scene.input.MouseEvent) Rotate(javafx.scene.transform.Rotate) SurfacePlotMesh(org.fxyz.shapes.primitives.SurfacePlotMesh) AnimationTimer(javafx.animation.AnimationTimer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KeyCode(javafx.scene.input.KeyCode) PerspectiveCamera(javafx.scene.PerspectiveCamera) Scene(javafx.scene.Scene) PointLight(javafx.scene.PointLight)

Aggregations

MouseEvent (javafx.scene.input.MouseEvent)41 KeyCode (javafx.scene.input.KeyCode)32 Scene (javafx.scene.Scene)27 Group (javafx.scene.Group)24 PerspectiveCamera (javafx.scene.PerspectiveCamera)23 PointLight (javafx.scene.PointLight)22 Rotate (javafx.scene.transform.Rotate)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 AnimationTimer (javafx.animation.AnimationTimer)14 Point3D (org.fxyz.geometry.Point3D)10 KeyFrame (javafx.animation.KeyFrame)8 Timeline (javafx.animation.Timeline)8 AmbientLight (javafx.scene.AmbientLight)8 ArrayList (java.util.ArrayList)7 KeyValue (javafx.animation.KeyValue)7 Color (javafx.scene.paint.Color)7 Translate (javafx.scene.transform.Translate)7 OBJWriter (org.fxyz.utils.OBJWriter)7 List (java.util.List)6 Sphere (javafx.scene.shape.Sphere)5