swe_primus/learn/java/javafx/Hello3d/Hello3d.java @ 555769fd
| 555769fd | torutk | import javafx.animation.PathTransition;
|
||
| 29192059 | torutk | import javafx.application.Application;
|
||
| 685d257b | torutk | import javafx.scene.AmbientLight;
|
||
| 29192059 | torutk | import javafx.scene.Group;
|
||
import javafx.scene.PerspectiveCamera;
|
||||
| 38b62b0a | torutk | import javafx.scene.PointLight;
|
||
| 29192059 | torutk | import javafx.scene.Scene;
|
||
| 5775a464 | torutk | import javafx.scene.image.Image;
|
||
| 29192059 | torutk | import javafx.scene.paint.Color;
|
||
import javafx.scene.paint.PhongMaterial;
|
||||
| 555769fd | torutk | import javafx.scene.shape.ArcTo;
|
||
import javafx.scene.shape.MoveTo;
|
||||
import javafx.scene.shape.Path;
|
||||
| 29192059 | torutk | import javafx.scene.shape.Sphere;
|
||
import javafx.scene.transform.Rotate;
|
||||
import javafx.scene.transform.Translate;
|
||||
import javafx.stage.Stage;
|
||||
| 555769fd | torutk | import javafx.util.Duration;
|
||
| 29192059 | torutk | |||
public class Hello3d extends Application {
|
||||
| 5775a464 | torutk | private final Image earthImage = new Image(getClass().getResourceAsStream("physical-free-world-map-b1.jpg"));
|
||
| 29192059 | torutk | @Override
|
||
public void start(final Stage stage) {
|
||||
final Group root = new Group();
|
||||
// 球体の定義
|
||||
final Sphere earth = new Sphere(100);
|
||||
root.getChildren().add(earth);
|
||||
| a87c4319 | torutk | // 材質の定義
|
||
final PhongMaterial material = new PhongMaterial();
|
||||
| 5775a464 | torutk | material.setDiffuseMap(earthImage);
|
||
| a87c4319 | torutk | earth.setMaterial(material);
|
||
| 29192059 | torutk | // カメラの定義
|
||
final PerspectiveCamera camera = new PerspectiveCamera(true);
|
||||
| 555769fd | torutk | camera.setFieldOfView(60.0);
|
||
| dd2b0a2e | torutk | camera.setFarClip(1000);
|
||
| 555769fd | torutk | camera.getTransforms().addAll(
|
||
new Translate(0, 0, -200)
|
||||
| 29192059 | torutk | );
|
||
| 38b62b0a | torutk | // 点光源の定義
|
||
final PointLight pointLight = new PointLight(Color.WHITE);
|
||||
pointLight.setTranslateX(240);
|
||||
pointLight.setTranslateY(0);
|
||||
pointLight.setTranslateZ(-250);
|
||||
root.getChildren().add(pointLight);
|
||||
| 685d257b | torutk | // 環境光の定義
|
||
final AmbientLight ambientLight = new AmbientLight(Color.rgb(80, 80, 80, 0.5));
|
||||
root.getChildren().add(ambientLight);
|
||||
| 555769fd | torutk | // カメラ移動の定義
|
||
// 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);
|
||||
| 29192059 | torutk | final Scene scene = new Scene(root, 800, 600, Color.BLACK);
|
||
scene.setCamera(camera);
|
||||
stage.setScene(scene);
|
||||
stage.setTitle("Hello JavaFX 3D World");
|
||||
stage.show();
|
||||
| 555769fd | torutk | |||
root.setOnMouseClicked(event -> orbit.play());
|
||||
| 29192059 | torutk | }
|
||
public static void main(final String... args) {
|
||||
launch(args);
|
||||
}
|
||||
| 3cf7d266 | torutk | }
|