diff --git a/src/main/java/com/ThreeDtest/application/Main.java b/src/main/java/com/ThreeDtest/application/Main.java index 75701a2..7a8ebec 100644 --- a/src/main/java/com/ThreeDtest/application/Main.java +++ b/src/main/java/com/ThreeDtest/application/Main.java @@ -1,56 +1,98 @@ package main.java.com.ThreeDtest.application; +import javafx.animation.Interpolator; +import javafx.animation.RotateTransition; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; +import javafx.geometry.Pos; import javafx.stage.Stage; +import javafx.util.Duration; +import javafx.scene.Node; +import javafx.scene.PointLight; import javafx.scene.Scene; +import javafx.scene.SceneAntialiasing; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.control.MenuItem; +import javafx.scene.image.Image; import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.StackPane; +import javafx.scene.paint.Color; +import javafx.scene.paint.PhongMaterial; +import javafx.scene.shape.Box; +import javafx.scene.transform.Rotate; public class Main extends Application { - @FXML - private AnchorPane mainAnchorpane; - - @FXML - private MenuItem menuItemStart; - - @FXML - private MenuItem menuItemReset; - - @FXML - private MenuItem menuItemClose; - - @FXML - private MenuItem menuItemHilfe; - - @FXML - private Button startStopButton; - - @FXML - private Button resetButton; - @Override public void start(Stage primaryStage) { try { - FXMLLoader loader = new FXMLLoader( - getClass().getResource("/fxml/MainWindow.fxml")); - AnchorPane pane = loader.load(); + + StackPane pane = new StackPane(); + primaryStage.setTitle("jFx3Dtest"); - Scene scene = new Scene(pane); - /** - * alle event listener mit fxml-loader - * - */ - scene.getStylesheets().add( - Main.class.getResource("/css/application.css").toExternalForm()); + Scene scene = new Scene(pane, 600, 600, true, + SceneAntialiasing.BALANCED); + + Box myBox = new Box(300, 300, 300); + + final String DIFFUSE_MAP = "https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/D%C3%BClmen%2C_Kreuzkapelle_--_2014_--_2731.jpg/640px-D%C3%BClmen%2C_Kreuzkapelle_--_2014_--_2731.jpg"; + + Image texture = new Image(DIFFUSE_MAP); + + PhongMaterial textureMaterial = new PhongMaterial(); + + textureMaterial.setDiffuseMap(texture); + + myBox.setMaterial(textureMaterial); + + PointLight pointLightFront = new PointLight(Color.WHITE); + pointLightFront.setTranslateX(100); + pointLightFront.setTranslateY(100); + pointLightFront.setTranslateZ(-300); + pointLightFront.setRotate(90); + + PointLight pointLightSky = new PointLight(Color.WHITE); + pointLightSky.setTranslateX(0); + pointLightSky.setTranslateY(-600); + pointLightSky.setTranslateZ(0); + pointLightSky.setRotate(90); + + PointLight pointLightGround = new PointLight(Color.WHITE); + pointLightSky.setTranslateX(0); + pointLightSky.setTranslateY(600); + pointLightSky.setTranslateZ(0); + pointLightSky.setRotate(90); + + pane.getChildren().add(pointLightFront); + pane.getChildren().add(pointLightSky); + pane.getChildren().add(pointLightGround); + + StackPane.setAlignment(pointLightFront, Pos.CENTER); + StackPane.setAlignment(pointLightSky, Pos.CENTER); + StackPane.setAlignment(pointLightGround, Pos.CENTER); + + Rotate rxBox = new Rotate(0, 0, 0, 0, Rotate.X_AXIS); + Rotate ryBox = new Rotate(0, 0, 0, 0, Rotate.Y_AXIS); + Rotate rzBox = new Rotate(0, 0, 0, 0, Rotate.Z_AXIS); + rxBox.setAngle(30); + ryBox.setAngle(50); + rzBox.setAngle(30); + myBox.getTransforms().addAll(rxBox, ryBox, rzBox); + + StackPane.setAlignment(myBox, Pos.CENTER); + + rotateAroundYAxis(myBox).play(); + + pane.getChildren().add(myBox); + primaryStage.setScene(scene); primaryStage.show(); @@ -59,44 +101,17 @@ public class Main extends Application } } - @FXML - public void menuItemStartAction(ActionEvent event) + private RotateTransition rotateAroundYAxis(Node node) { + RotateTransition rotate = new RotateTransition(Duration.seconds(36), + node); + rotate.setAxis(Rotate.Y_AXIS); + rotate.setFromAngle(360); + rotate.setToAngle(0); + rotate.setInterpolator(Interpolator.LINEAR); + rotate.setCycleCount(RotateTransition.INDEFINITE); - } - - @FXML - public void menuItemResetAction(ActionEvent event) - { - - } - - @FXML - public void menuItemCloseAction(ActionEvent event) - { - System.exit(0); - } - - @FXML - public void startStopButtonAction(ActionEvent event) - { - - } - - @FXML - public void resetButtonAction(ActionEvent event) - { - - } - - @FXML - public void menuItemHilfeAction(ActionEvent event) - { - Alert alert = new Alert(AlertType.INFORMATION); - alert.setTitle("Alert"); - alert.setHeaderText("Some info"); - alert.setContentText("Author: localhorst@mosad.xyz"); - alert.showAndWait(); + return rotate; } public static void main(String[] args) @@ -104,4 +119,4 @@ public class Main extends Application launch(args); } -} +} \ No newline at end of file diff --git a/src/main/resources/css/application.css b/src/main/resources/css/application.css deleted file mode 100644 index 83d6f33..0000000 --- a/src/main/resources/css/application.css +++ /dev/null @@ -1 +0,0 @@ -/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ \ No newline at end of file diff --git a/src/main/resources/fxml/MainWindow.fxml b/src/main/resources/fxml/MainWindow.fxml deleted file mode 100644 index 6fc598d..0000000 --- a/src/main/resources/fxml/MainWindow.fxml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -