added first ideas

This commit is contained in:
Hendrik Schutter 2019-04-01 00:43:06 +02:00
parent d287e27776
commit 22bdaaba45
3 changed files with 83 additions and 107 deletions

View File

@ -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);
}
}
}

View File

@ -1 +0,0 @@
/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */

View File

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.SeparatorMenuItem?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<AnchorPane fx:id="mainAnchorpane" maxHeight="400.0" maxWidth="500.0" minHeight="400.0" minWidth="500.0" prefHeight="400.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="main.java.com.ThreeDtest.application.Main">
<children>
<BorderPane prefHeight="400.0" prefWidth="500.0">
<bottom>
<HBox prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
</bottom>
<top>
<MenuBar BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="Aktion">
<items>
<MenuItem fx:id="menuItemStart" mnemonicParsing="false" onAction="#menuItemStartAction" text="Start" />
<MenuItem fx:id="menuItemReset" mnemonicParsing="false" onAction="#menuItemResetAction" text="Reset" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem fx:id="menuItemClose" mnemonicParsing="false" onAction="#menuItemCloseAction" text="Beenden" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Hilfe">
<items>
<MenuItem fx:id="menuItemHilfe" mnemonicParsing="false" onAction="#menuItemHilfeAction" text="Info" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
</BorderPane>
</children>
</AnchorPane>