Finished playable 3D race with first person camera
- Camera pivot must be manually updated - GPS coordinates are scaled by an arbitrary amount to make movement visible - Model has to be flipped 180 degrees to move forward #story[1261]
This commit is contained in:
@@ -75,7 +75,6 @@ public class HostController extends Controller {
|
|||||||
|
|
||||||
subjects.add(subject);
|
subjects.add(subject);
|
||||||
|
|
||||||
view3D.setPivot(subject);
|
|
||||||
view3D.setDistance(50);
|
view3D.setDistance(50);
|
||||||
view3D.setYaw(45);
|
view3D.setYaw(45);
|
||||||
view3D.setPitch(20);
|
view3D.setPitch(20);
|
||||||
|
|||||||
@@ -175,50 +175,47 @@ public class RaceController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initialiseView3D(VisualiserRaceEvent race) {
|
private void initialiseView3D(VisualiserRaceEvent race) {
|
||||||
|
int scale = 5000;
|
||||||
|
|
||||||
ObservableList<Subject3D> subjects = FXCollections.observableArrayList();
|
ObservableList<Subject3D> subjects = FXCollections.observableArrayList();
|
||||||
|
|
||||||
|
URL asset = HostController.class.getClassLoader().getResource("assets/V1.2 Complete Boat.stl");
|
||||||
|
StlMeshImporter importer = new StlMeshImporter();
|
||||||
|
importer.read(asset);
|
||||||
|
|
||||||
view3D = new View3D();
|
view3D = new View3D();
|
||||||
|
view3D.setDistance(100);
|
||||||
|
view3D.setYaw(0);
|
||||||
|
view3D.setPitch(20);
|
||||||
|
|
||||||
view3D.setItems(subjects);
|
view3D.setItems(subjects);
|
||||||
canvasBase.getChildren().add(0, view3D);
|
canvasBase.getChildren().add(0, view3D);
|
||||||
|
|
||||||
for(Mark mark: race.getVisualiserRaceState().getMarks()) {
|
for(Mark mark: race.getVisualiserRaceState().getMarks()) {
|
||||||
Subject3D subject = new Subject3D(new Sphere(2));
|
Subject3D subject = new Subject3D(new Sphere(5));
|
||||||
subject.setX(mark.getPosition().getLongitude());
|
subject.setX(mark.getPosition().getLongitude() * scale);
|
||||||
subject.setZ(mark.getPosition().getLatitude());
|
subject.setZ(mark.getPosition().getLatitude() * scale);
|
||||||
|
|
||||||
System.out.println(subject.getPosition().toString());
|
|
||||||
subjects.add(subject);
|
subjects.add(subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
for(VisualiserBoat boat: race.getVisualiserRaceState().getBoats()) {
|
||||||
VisualiserBoat boat = race.getVisualiserRaceState().getBoat(race.getVisualiserRaceState().getPlayerBoatID());
|
|
||||||
|
|
||||||
URL asset = HostController.class.getClassLoader().getResource("assets/V1.2 Complete Boat.stl");
|
|
||||||
|
|
||||||
StlMeshImporter importer = new StlMeshImporter();
|
|
||||||
importer.read(asset);
|
|
||||||
Subject3D subject = new Subject3D(new MeshView(importer.getImport()));
|
Subject3D subject = new Subject3D(new MeshView(importer.getImport()));
|
||||||
subject.setX(boat.getPosition().getLongitude());
|
|
||||||
subject.setZ(boat.getPosition().getLatitude());
|
|
||||||
|
|
||||||
System.out.println(subject.getPosition().toString());
|
|
||||||
subjects.add(subject);
|
subjects.add(subject);
|
||||||
|
|
||||||
view3D.setPivot(subject);
|
AnimationTimer trackBoat = new AnimationTimer() {
|
||||||
view3D.setDistance(500);
|
|
||||||
view3D.setYaw(0);
|
|
||||||
view3D.setPitch(20);
|
|
||||||
AnimationTimer rotate = new AnimationTimer() {
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(long now) {
|
public void handle(long now) {
|
||||||
subject.setHeading(boat.getBearing().degrees());
|
subject.setHeading(boat.getBearing().degrees());
|
||||||
subject.setX(boat.getPosition().getLongitude());
|
subject.setX(boat.getPosition().getLongitude() * scale);
|
||||||
subject.setZ(boat.getPosition().getLatitude());
|
subject.setZ(boat.getPosition().getLatitude()* scale);
|
||||||
|
if(boat.getSourceID() == race.getVisualiserRaceState().getPlayerBoatID()) {
|
||||||
|
view3D.updatePivot(subject.getPosition());
|
||||||
|
}
|
||||||
|
view3D.setYaw(boat.getBearing().degrees());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
rotate.start();
|
trackBoat.start();
|
||||||
} catch(BoatNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class Subject3D {
|
|||||||
* Position translation updated by state listeners
|
* Position translation updated by state listeners
|
||||||
*/
|
*/
|
||||||
private Translate position;
|
private Translate position;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Heading rotation updated by state listeners
|
* Heading rotation updated by state listeners
|
||||||
*/
|
*/
|
||||||
@@ -31,7 +32,7 @@ public class Subject3D {
|
|||||||
this.position = new Translate();
|
this.position = new Translate();
|
||||||
this.heading = new Rotate(0, Rotate.Y_AXIS);
|
this.heading = new Rotate(0, Rotate.Y_AXIS);
|
||||||
|
|
||||||
this.mesh.getTransforms().addAll(position, heading, new Rotate(-90, Rotate.X_AXIS));
|
this.mesh.getTransforms().addAll(position, heading, new Rotate(90, Rotate.X_AXIS), new Rotate(180, Rotate.Y_AXIS));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shape3D getMesh() {
|
public Shape3D getMesh() {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class View3D extends Pane {
|
|||||||
*/
|
*/
|
||||||
private double farClip;
|
private double farClip;
|
||||||
/**
|
/**
|
||||||
* Position camera pivots around
|
* Camera origin
|
||||||
*/
|
*/
|
||||||
private Translate pivot;
|
private Translate pivot;
|
||||||
/**
|
/**
|
||||||
@@ -112,14 +112,11 @@ public class View3D extends Pane {
|
|||||||
this.farClip = farClip;
|
this.farClip = farClip;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void updatePivot(Translate pivot) {
|
||||||
* Set object to centre on camera
|
this.pivot.setX(pivot.getX());
|
||||||
* @param pivot centred object
|
this.pivot.setY(pivot.getY());
|
||||||
*/
|
this.pivot.setZ(pivot.getZ());
|
||||||
public void setPivot(Subject3D pivot) {
|
|
||||||
this.pivot = pivot.getPosition();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set distance of camera from pivot
|
* Set distance of camera from pivot
|
||||||
* @param distance in units
|
* @param distance in units
|
||||||
@@ -143,8 +140,4 @@ public class View3D extends Pane {
|
|||||||
public void setPitch(double pitch) {
|
public void setPitch(double pitch) {
|
||||||
this.pitch.setAngle(-pitch);
|
this.pitch.setAngle(-pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PerspectiveCamera getCamera() {
|
|
||||||
return camera;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user