プロジェクト

全般

プロフィール

« | » 

リビジョン e3ae6ff1

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

TimelineのKeyFrame間の補間で円軌道っぽくするためにInterpolate.SPLINEでがんばった。

差分を表示:

learn/java/javafx/Hello3d/Hello3d.java
import javafx.application.Application;
import javafx.animation.Timeline;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.scene.AmbientLight;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
......
private final Rotate cameraRotateX = new Rotate(0, Rotate.X_AXIS);
private final Rotate cameraRotateY = new Rotate(0, Rotate.Y_AXIS);
private final Rotate cameraRotateZ = new Rotate(0, Rotate.Z_AXIS);
private final Translate cameraTranslate = new Translate(0, 0, -160);
private final Translate cameraTranslate = new Translate(0, 0, -200);
@Override
public void start(final Stage stage) {
......
scene.setCamera(camera);
// アニメーション定義
// カメラを(0, 0, -200)から(200, 0, 0)に移a動する
// カメラを(0, 0, -200)から(200, 0, 0)に移動する
// その際、カメラの向きを(0, 0, 0)方向に維持するためY軸半時計回りに
// 90度回転させる
final Timeline animation = new Timeline();
final Interpolator fastSlowInterpolator = Interpolator.SPLINE(0.13, 0.5, 0.5, 0.87);
final Interpolator slowFastInterpolator = Interpolator.SPLINE(0.5, 0.13, 0.87, 0.5);
animation.getKeyFrames().addAll(
new KeyFrame(Duration.ZERO,
new KeyValue(cameraRotateY.angleProperty(), 0),
new KeyValue(cameraTranslate.xProperty(), 0),
new KeyValue(cameraTranslate.xProperty(), 0, fastSlowInterpolator),
new KeyValue(cameraTranslate.yProperty(), 0),
new KeyValue(cameraTranslate.zProperty(), -200)
new KeyValue(cameraTranslate.zProperty(), -200, slowFastInterpolator)
),
new KeyFrame(Duration.millis(3000),
new KeyValue(cameraRotateY.angleProperty(), -90),
new KeyValue(cameraTranslate.xProperty(), 200),
new KeyValue(cameraTranslate.xProperty(), 200, fastSlowInterpolator),
new KeyValue(cameraTranslate.yProperty(), 0),
new KeyValue(cameraTranslate.zProperty(), 0)
new KeyValue(cameraTranslate.zProperty(), 0, slowFastInterpolator)
)
);
......
stage.show();
root.setOnMouseClicked(event -> animation.play());
}
public static void main(final String... args) {

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