Rotation on Z index : Rotate « JavaFX « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » JavaFX » Rotate 




Rotation on Z index
 



import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.animation.TimelineBuilder;
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.geometry.Point3D;
import javafx.scene.GroupBuilder;
import javafx.scene.Parent;
import javafx.scene.PerspectiveCameraBuilder;
import javafx.scene.Scene;
import javafx.scene.SceneBuilder;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.CircleBuilder;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.RotateBuilder;
import javafx.stage.Stage;
import javafx.util.Duration;

public class Main extends Application {
    private DoubleProperty translateZForNode1 = new SimpleDoubleProperty();
    private DoubleProperty angle = new SimpleDoubleProperty();

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) {
        stage.setTitle("Rotations");
        stage.setScene(makeScene());
        stage.show();
        TimelineBuilder.create()
        .cycleCount(Timeline.INDEFINITE)
        .keyFrames(
            new KeyFrame(
                Duration.seconds(0),
                new KeyValue(translateZForNode1, -100),
                new KeyValue(angle, 0)
            ),
            new KeyFrame(
                Duration.seconds(2),
                new KeyValue(translateZForNode1, 100),
                new KeyValue(angle, 180)
            ),
            new KeyFrame(
                Duration.seconds(4),
                new KeyValue(translateZForNode1, -100),
                new KeyValue(angle, 360)
            )

        )
        .build().play();
    }

    private Scene makeScene() {
        return SceneBuilder.create()
            .width(500)
            .height(500)
            .root(createRoot())
            .camera(PerspectiveCameraBuilder.create()
                .build())
            .depthBuffer(true)
            .build();
    }

    private Parent createRoot() {
        Circle node1 = CircleBuilder.create()
            .centerX(-50)
            .centerY(-50)
            .radius(100)
            .fill(Color.RED)
            .build();
        node1.translateZProperty().bind(translateZForNode1);
        final Rotate rotate = RotateBuilder.create()
            .pivotX(0)
            .pivotY(0)
            .pivotZ(0)
            .axis(new Point3D(100))
            .build();
        rotate.angleProperty().bind(angle);

        return GroupBuilder.create()
            .children(node1)
            .translateX(250)
            .translateY(250)
            .transforms(rotate)
            .build();
    }
}

   
  














Related examples in the same category
1.rotate a text 30 degrees around the Z-axis at anchor point of (50,30)
2.rotate by 45 degrees
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.