View3D perspective camera is now operational
#story[1196]
This commit is contained in:
@@ -7,6 +7,7 @@ import javafx.scene.control.SplitPane;
|
|||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.shape.Box;
|
||||||
import mock.app.Event;
|
import mock.app.Event;
|
||||||
import mock.exceptions.EventConstructionException;
|
import mock.exceptions.EventConstructionException;
|
||||||
import visualiser.model.View3D;
|
import visualiser.model.View3D;
|
||||||
@@ -57,7 +58,7 @@ public class HostController extends Controller {
|
|||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
fancyStuff = new View3D();
|
fancyStuff = new View3D();
|
||||||
playerContainer.add(fancyStuff, 0,0);
|
playerContainer.add(fancyStuff, 0,0);
|
||||||
fancyStuff.spinBox();
|
fancyStuff.addShape(new Box(100,100,100));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,49 +1,43 @@
|
|||||||
package visualiser.model;
|
package visualiser.model;
|
||||||
|
|
||||||
import javafx.animation.AnimationTimer;
|
|
||||||
import javafx.scene.Group;
|
import javafx.scene.Group;
|
||||||
import javafx.scene.PerspectiveCamera;
|
import javafx.scene.PerspectiveCamera;
|
||||||
import javafx.scene.SubScene;
|
import javafx.scene.SubScene;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.shape.Box;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.CullFace;
|
import javafx.scene.shape.Shape3D;
|
||||||
import javafx.scene.transform.Rotate;
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by connortaylorbrown on 30/08/17.
|
* Created by connortaylorbrown on 30/08/17.
|
||||||
*/
|
*/
|
||||||
public class View3D extends Pane {
|
public class View3D extends Pane {
|
||||||
SubScene scene;
|
SubScene scene;
|
||||||
PerspectiveCamera camera;
|
Group world;
|
||||||
Box box;
|
List<Shape3D> shapes;
|
||||||
|
|
||||||
public View3D() {
|
public View3D() {
|
||||||
scene = new SubScene(this, 500, 500);
|
shapes = new ArrayList<>();
|
||||||
camera = new PerspectiveCamera();
|
world = new Group();
|
||||||
|
|
||||||
|
scene = new SubScene(world, 300, 300);
|
||||||
|
scene.widthProperty().bind(this.widthProperty());
|
||||||
|
scene.heightProperty().bind(this.heightProperty());
|
||||||
|
scene.setFill(Color.BLACK);
|
||||||
|
|
||||||
|
PerspectiveCamera camera = new PerspectiveCamera(true);
|
||||||
|
camera.setNearClip(0.1);
|
||||||
|
camera.setFarClip(1000.0);
|
||||||
|
camera.setTranslateZ(-500);
|
||||||
scene.setCamera(camera);
|
scene.setCamera(camera);
|
||||||
|
|
||||||
|
this.getChildren().add(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spinBox() {
|
public void addShape(Shape3D shape) {
|
||||||
camera.getTransforms().add(new Rotate(-20, Rotate.X_AXIS));
|
shapes.add(shape);
|
||||||
|
world.getChildren().add(shape);
|
||||||
box = new Box(50,50,50);
|
|
||||||
box.setTranslateX(100);
|
|
||||||
box.setTranslateY(100);
|
|
||||||
box.setCullFace(CullFace.BACK);
|
|
||||||
|
|
||||||
Rotate ry = new Rotate(0, 0,0,0, Rotate.Y_AXIS);
|
|
||||||
box.getTransforms().add(ry);
|
|
||||||
|
|
||||||
this.getChildren().add(camera);
|
|
||||||
this.getChildren().add(box);
|
|
||||||
|
|
||||||
AnimationTimer rotation = new AnimationTimer() {
|
|
||||||
@Override
|
|
||||||
public void handle(long now) {
|
|
||||||
ry.setAngle(ry.getAngle() + 0.1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
rotation.start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user