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]
main
Connor Taylor-Brown 8 years ago
parent 19f4d0fc06
commit d89186d8bf

@ -75,7 +75,6 @@ public class HostController extends Controller {
subjects.add(subject);
view3D.setPivot(subject);
view3D.setDistance(50);
view3D.setYaw(45);
view3D.setPitch(20);

@ -175,50 +175,47 @@ public class RaceController extends Controller {
}
private void initialiseView3D(VisualiserRaceEvent race) {
int scale = 5000;
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.setDistance(100);
view3D.setYaw(0);
view3D.setPitch(20);
view3D.setItems(subjects);
canvasBase.getChildren().add(0, view3D);
for(Mark mark: race.getVisualiserRaceState().getMarks()) {
Subject3D subject = new Subject3D(new Sphere(2));
subject.setX(mark.getPosition().getLongitude());
subject.setZ(mark.getPosition().getLatitude());
Subject3D subject = new Subject3D(new Sphere(5));
subject.setX(mark.getPosition().getLongitude() * scale);
subject.setZ(mark.getPosition().getLatitude() * scale);
System.out.println(subject.getPosition().toString());
subjects.add(subject);
}
try {
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);
for(VisualiserBoat boat: race.getVisualiserRaceState().getBoats()) {
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);
view3D.setPivot(subject);
view3D.setDistance(500);
view3D.setYaw(0);
view3D.setPitch(20);
AnimationTimer rotate = new AnimationTimer() {
AnimationTimer trackBoat = new AnimationTimer() {
@Override
public void handle(long now) {
subject.setHeading(boat.getBearing().degrees());
subject.setX(boat.getPosition().getLongitude());
subject.setZ(boat.getPosition().getLatitude());
subject.setX(boat.getPosition().getLongitude() * scale);
subject.setZ(boat.getPosition().getLatitude()* scale);
if(boat.getSourceID() == race.getVisualiserRaceState().getPlayerBoatID()) {
view3D.updatePivot(subject.getPosition());
}
view3D.setYaw(boat.getBearing().degrees());
}
};
rotate.start();
} catch(BoatNotFoundException e) {
e.printStackTrace();
trackBoat.start();
}
}

@ -17,6 +17,7 @@ public class Subject3D {
* Position translation updated by state listeners
*/
private Translate position;
/**
* Heading rotation updated by state listeners
*/
@ -31,7 +32,7 @@ public class Subject3D {
this.position = new Translate();
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() {

@ -34,7 +34,7 @@ public class View3D extends Pane {
*/
private double farClip;
/**
* Position camera pivots around
* Camera origin
*/
private Translate pivot;
/**
@ -112,14 +112,11 @@ public class View3D extends Pane {
this.farClip = farClip;
}
/**
* Set object to centre on camera
* @param pivot centred object
*/
public void setPivot(Subject3D pivot) {
this.pivot = pivot.getPosition();
public void updatePivot(Translate pivot) {
this.pivot.setX(pivot.getX());
this.pivot.setY(pivot.getY());
this.pivot.setZ(pivot.getZ());
}
/**
* Set distance of camera from pivot
* @param distance in units
@ -143,8 +140,4 @@ public class View3D extends Pane {
public void setPitch(double pitch) {
this.pitch.setAngle(-pitch);
}
public PerspectiveCamera getCamera() {
return camera;
}
}

Loading…
Cancel
Save