Advertisement
Bjornir90

Tutorial JavaFX code

May 25th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. //create a Pane et graph scene root for the 3D cont
  2.         Group root3D = new Group();
  3.         Pane pane3D = new Pane( root3D);
  4. //Create cube shape
  5.         Box cube = new Box(1, 1, 1);
  6. //Create Material
  7.         final PhongMaterial blueMaterial = new PhongMaterial();
  8.         blueMaterial.setDiffuseColor(Color.BLUE);
  9.         blueMaterial.setSpecularColor(Color.BLUE);
  10. //Set it to the cube
  11.         cube.setMaterial(blueMaterial);
  12.         //Add the cube to this node
  13.         root3D.getChildren().add(cube);
  14.         //a camera group
  15.         PerspectiveCamera camera = new PerspectiveCamera(true);
  16.         Group cameraGroup = new Group(camera);
  17.         root3D.getChildren().add(cameraGroup);
  18.         //ate then move the camera
  19.         Rotate ry = new Rotate();
  20.         ry.setAxis(Rotate.Y_AXIS);
  21.         ry.setAngle(-15);
  22.         Translate tz = new Translate();
  23.         tz.setZ(-10);
  24.         tz.setY(-1);
  25.         cameraGroup.getTransforms().addAll(ry,tz);
  26. // Add point light
  27.         PointLight light = new PointLight(Color.WHITE);
  28.         light.setTranslateX(-180);
  29.         light.setTranslateY(-90);
  30.         light.setTranslateZ(-120);
  31.         light.getScope().addAll(root3D);
  32.         root3D.getChildren().add(light);
  33. // Create scene
  34.         Scene scene = new Scene(pane3D, 600, 600, true);
  35.         scene.setCamera(camera);
  36.         scene.setFill(Color.GREY);
  37. //Add the scene to the stage and show it
  38.         primaryStage.setTitle("Cubes Test");
  39.         primaryStage.setScene(scene);
  40.         primaryStage.show();
  41.         primaryStage.show();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement