public void animate() {
   Timeline timeline =
       new Timeline(
           new KeyFrame(
               Duration.seconds(0),
               new KeyValue(translateZ.zProperty(), -20),
               new KeyValue(rotateX.angleProperty(), 90),
               new KeyValue(rotateY.angleProperty(), 90),
               new KeyValue(rotateZ.angleProperty(), 90)),
           new KeyFrame(
               Duration.seconds(5),
               new KeyValue(translateZ.zProperty(), -80),
               new KeyValue(rotateX.angleProperty(), -90),
               new KeyValue(rotateY.angleProperty(), -90),
               new KeyValue(rotateZ.angleProperty(), -90)));
   timeline.setCycleCount(Animation.INDEFINITE);
   timeline.play();
 }
Beispiel #2
0
  @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();
  }