プロジェクト

全般

プロフィール

« | » 

リビジョン 555769fd

高徹 高橋 徹 さんが12年以上前に追加

  • ID 555769fd699f089f4a824f1a2be88228ae4d8313
  • dd2b0a2e

アニメーションの実現をTransitionに替えた最初の一歩(円軌道)、うまくいかない

差分を表示:

learn/java/javafx/Hello3d/Hello3d.java
import javafx.animation.PathTransition;
import javafx.application.Application;
import javafx.scene.AmbientLight;
import javafx.scene.Group;
......
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.ArcTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.Sphere;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Translate;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Hello3d extends Application {
......
// カメラの定義
final PerspectiveCamera camera = new PerspectiveCamera(true);
camera.setFieldOfView(45.0);
camera.setFieldOfView(60.0);
camera.setFarClip(1000);
camera.getTransforms().addAll(
new Translate(0, 0, -260)
camera.getTransforms().addAll(
new Translate(0, 0, -200)
);
// 点光源の定義
......
final AmbientLight ambientLight = new AmbientLight(Color.rgb(80, 80, 80, 0.5));
root.getChildren().add(ambientLight);
// カメラ移動の定義
// Pathは2次元での定義しかないので!、XY平面で定義後回転させる
final ArcTo arcTo = new ArcTo();
arcTo.setX(0);
arcTo.setY(-200);
arcTo.setRadiusX(100);
arcTo.setRadiusY(100);
final MoveTo moveTo = new MoveTo();
moveTo.setX(0);
moveTo.setY(200);
final Path path = new Path();
path.getElements().addAll(moveTo, arcTo);
path.setRotationAxis(Rotate.X_AXIS);
path.setRotate(-90);
final PathTransition orbit = new PathTransition();
orbit.setDuration(Duration.millis(9000));
orbit.setPath(path);
orbit.setNode(camera);
final Scene scene = new Scene(root, 800, 600, Color.BLACK);
scene.setCamera(camera);
stage.setScene(scene);
stage.setTitle("Hello JavaFX 3D World");
stage.show();
root.setOnMouseClicked(event -> orbit.play());
}
public static void main(final String... args) {

他の形式にエクスポート: Unified diff