File src/ui/Controller.java added (mode: 100644) (index 0000000..f1b0869) |
|
1 |
|
package ui; |
|
2 |
|
|
|
3 |
|
import javafx.fxml.FXML; |
|
4 |
|
import javafx.scene.canvas.Canvas; |
|
5 |
|
import javafx.scene.canvas.GraphicsContext; |
|
6 |
|
|
|
7 |
|
import data.Vector; |
|
8 |
|
import javafx.scene.control.CheckBox; |
|
9 |
|
import javafx.scene.control.Slider; |
|
10 |
|
import javafx.scene.paint.Color; |
|
11 |
|
import javafx.scene.paint.Paint; |
|
12 |
|
|
|
13 |
|
public class Controller { |
|
14 |
|
private int WIDTH,HEIGHT; |
|
15 |
|
private GraphicsContext gc; |
|
16 |
|
@FXML |
|
17 |
|
private Canvas canvasDraw; |
|
18 |
|
@FXML |
|
19 |
|
private Slider sliderX,sliderY,sliderZ; |
|
20 |
|
@FXML |
|
21 |
|
private CheckBox cBRotate; |
|
22 |
|
|
|
23 |
|
@FXML |
|
24 |
|
private void initialize(){ |
|
25 |
|
gc = canvasDraw.getGraphicsContext2D(); |
|
26 |
|
WIDTH=(int)Math.round(canvasDraw.getWidth()); |
|
27 |
|
HEIGHT=(int)Math.round(canvasDraw.getHeight()); |
|
28 |
|
} |
|
29 |
|
|
|
30 |
|
public void simulate(){ |
|
31 |
|
gc.setFill(Color.GRAY); |
|
32 |
|
gc.fillRect(0, 0, 600, 600); |
|
33 |
|
gc.setFill(Color.WHITE); |
|
34 |
|
gc.fillOval(WIDTH / 2, HEIGHT / 2, 10, 10); |
|
35 |
|
|
|
36 |
|
} |
|
37 |
|
|
|
38 |
|
private void drawPoint( Vector v){ |
|
39 |
|
gc.fillOval(v.get(0),v.get(1),5,5); |
|
40 |
|
} |
|
41 |
|
private void connect( Vector v1 , Vector v2){ |
|
42 |
|
gc.strokeLine(v1.get(0),v1.get(1),v2.get(0),v2.get(1)); |
|
43 |
|
} |
|
44 |
|
|
|
45 |
|
public class Draw implements Runnable{ |
|
46 |
|
@Override |
|
47 |
|
public void run() { |
|
48 |
|
simulate(); |
|
49 |
|
} |
|
50 |
|
} |
|
51 |
|
} |
File src/ui/Main.java added (mode: 100644) (index 0000000..38e2d6c) |
|
1 |
|
package ui; |
|
2 |
|
|
|
3 |
|
import javafx.application.Application; |
|
4 |
|
import javafx.application.Platform; |
|
5 |
|
import javafx.event.EventHandler; |
|
6 |
|
import javafx.fxml.FXMLLoader; |
|
7 |
|
import javafx.scene.Parent; |
|
8 |
|
import javafx.scene.Scene; |
|
9 |
|
import javafx.stage.Stage; |
|
10 |
|
import javafx.stage.WindowEvent; |
|
11 |
|
|
|
12 |
|
import java.util.Timer; |
|
13 |
|
import java.util.TimerTask; |
|
14 |
|
|
|
15 |
|
public class Main extends Application { |
|
16 |
|
|
|
17 |
|
@Override |
|
18 |
|
public void start(Stage primaryStage) throws Exception{ |
|
19 |
|
FXMLLoader loader =new FXMLLoader(getClass().getResource("sample.fxml")); |
|
20 |
|
Parent root = loader.load(); |
|
21 |
|
Controller c = loader.getController(); |
|
22 |
|
primaryStage.setTitle("3D-Simulation"); |
|
23 |
|
primaryStage.setScene(new Scene(root)); |
|
24 |
|
primaryStage.show(); |
|
25 |
|
Timer t = new Timer(); |
|
26 |
|
t.scheduleAtFixedRate(new TimerTask() { |
|
27 |
|
@Override |
|
28 |
|
public void run() { |
|
29 |
|
Platform.runLater(c.new Draw()); |
|
30 |
|
} |
|
31 |
|
},0,10); |
|
32 |
|
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() { |
|
33 |
|
@Override |
|
34 |
|
public void handle(WindowEvent event) { |
|
35 |
|
t.cancel(); |
|
36 |
|
} |
|
37 |
|
}); |
|
38 |
|
} |
|
39 |
|
|
|
40 |
|
|
|
41 |
|
public static void main(String[] args) { |
|
42 |
|
launch(args); |
|
43 |
|
} |
|
44 |
|
} |
File src/ui/sample.fxml added (mode: 100644) (index 0000000..62eb299) |
|
1 |
|
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
|
3 |
|
<?import javafx.scene.canvas.Canvas?> |
|
4 |
|
<?import javafx.scene.control.CheckBox?> |
|
5 |
|
<?import javafx.scene.control.Label?> |
|
6 |
|
<?import javafx.scene.control.Slider?> |
|
7 |
|
<?import javafx.scene.control.SplitPane?> |
|
8 |
|
<?import javafx.scene.layout.AnchorPane?> |
|
9 |
|
|
|
10 |
|
<SplitPane dividerPositions="0.25" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ui.Controller"> |
|
11 |
|
<items> |
|
12 |
|
<AnchorPane maxHeight="600.0" maxWidth="200.0" minHeight="600.0" minWidth="200.0" prefHeight="600.0" prefWidth="200.0"> |
|
13 |
|
<children> |
|
14 |
|
<Slider fx:id="sliderX" layoutX="14.0" layoutY="37.0" /> |
|
15 |
|
<Label layoutX="14.0" layoutY="14.0" text="X-Achse:" /> |
|
16 |
|
<Slider fx:id="sliderY" layoutX="14.0" layoutY="96.0" /> |
|
17 |
|
<Label layoutX="14.0" layoutY="73.0" text="Y-Achse:" /> |
|
18 |
|
<Slider fx:id="sliderZ" layoutX="14.0" layoutY="160.0" /> |
|
19 |
|
<Label layoutX="14.0" layoutY="137.0" text="Z-Achse:" /> |
|
20 |
|
<CheckBox fx:id="cBRotate" layoutX="14.0" layoutY="203.0" mnemonicParsing="false" text="Rotieren" /> |
|
21 |
|
</children></AnchorPane> |
|
22 |
|
<AnchorPane maxHeight="600.0" maxWidth="600.0" minHeight="600.0" minWidth="600.0" prefHeight="600.0" prefWidth="600.0"> |
|
23 |
|
<children> |
|
24 |
|
<Canvas fx:id="canvasDraw" height="600.0" layoutX="213.0" layoutY="154.0" width="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" /> |
|
25 |
|
</children></AnchorPane> |
|
26 |
|
</items> |
|
27 |
|
</SplitPane> |