Created
June 17, 2021 15:16
-
-
Save Da9el00/38a0219204e09a824acce286ca19d0a4 to your computer and use it in GitHub Desktop.
JavaFX 3D - Sphere
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample; | |
import javafx.application.Application; | |
import javafx.scene.Group; | |
import javafx.scene.PerspectiveCamera; | |
import javafx.scene.Scene; | |
import javafx.scene.input.KeyEvent; | |
import javafx.scene.paint.Color; | |
import javafx.scene.shape.Sphere; | |
import javafx.stage.Stage; | |
public class Main extends Application { | |
@Override | |
public void start(Stage primaryStage) throws Exception{ | |
Sphere sphere = new Sphere(100); | |
Group group = new Group(); | |
group.getChildren().add(sphere); | |
Scene scene = new Scene(group,1000,800); | |
scene.setCamera(new PerspectiveCamera()); | |
scene.setFill(Color.SILVER); | |
sphere.translateXProperty().set(500); | |
sphere.translateYProperty().set(400); | |
primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, e ->{ | |
switch (e.getCode()) { | |
case W -> { | |
sphere.translateZProperty().set(sphere.getTranslateZ() + 10); | |
System.out.println(sphere.getTranslateZ()); | |
} | |
case S -> { | |
sphere.translateZProperty().set(sphere.getTranslateZ() - 10); | |
System.out.println(sphere.getTranslateZ()); | |
} | |
} | |
}); | |
primaryStage.setTitle("3D World"); | |
primaryStage.setScene(scene); | |
primaryStage.show(); | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment