Merge remote-tracking branch 'origin/storyD-3D' into storyD-3D
This commit is contained in:
@@ -202,11 +202,10 @@ public class RaceController extends Controller {
|
|||||||
StlMeshImporter importerBurgerBoat = new StlMeshImporter();
|
StlMeshImporter importerBurgerBoat = new StlMeshImporter();
|
||||||
importerBurgerBoat.read(alternateBoatAsset);
|
importerBurgerBoat.read(alternateBoatAsset);
|
||||||
|
|
||||||
|
|
||||||
view3D = new View3D(false);
|
view3D = new View3D(false);
|
||||||
|
view3D.setItems(viewSubjects);
|
||||||
view3D.setDistance(1050);
|
view3D.setDistance(1050);
|
||||||
view3D.setYaw(0);
|
view3D.setBirdsEye();
|
||||||
view3D.setPitch(60);
|
|
||||||
view3D.enableTracking();
|
view3D.enableTracking();
|
||||||
view3D.addAmbientLight(ambientLight);
|
view3D.addAmbientLight(ambientLight);
|
||||||
view3D.addPointLight(pointLight);
|
view3D.addPointLight(pointLight);
|
||||||
@@ -216,14 +215,13 @@ public class RaceController extends Controller {
|
|||||||
RaceDataSource raceData = visualiserRace.getVisualiserRaceState().getRaceDataSource();
|
RaceDataSource raceData = visualiserRace.getVisualiserRaceState().getRaceDataSource();
|
||||||
final GPSConverter gpsConverter = new GPSConverter(raceData, 450, 450);
|
final GPSConverter gpsConverter = new GPSConverter(raceData, 450, 450);
|
||||||
|
|
||||||
view3D.setItems(viewSubjects);
|
// Set up sea surface
|
||||||
|
SeaSurface sea = new SeaSurface(750, 200);
|
||||||
|
sea.setX(250);
|
||||||
|
sea.setZ(210);
|
||||||
|
viewSubjects.add(sea);
|
||||||
|
|
||||||
//viewSubjects.add(new Subject3D(new MeshView(new Plane3D(50, 50, 1, 1))));
|
|
||||||
|
|
||||||
|
|
||||||
SeaSurface sea = new SeaSurface(750, 200, 250, 0, 210);
|
|
||||||
SkyBox skyBox = new SkyBox(750, 200, 250, 0, 210);
|
SkyBox skyBox = new SkyBox(750, 200, 250, 0, 210);
|
||||||
viewSubjects.add(sea.getSurface());
|
|
||||||
viewSubjects.addAll(skyBox.getSkyBoxPlanes());
|
viewSubjects.addAll(skyBox.getSkyBoxPlanes());
|
||||||
|
|
||||||
Boundary3D boundary3D = new Boundary3D(visualiserRace.getVisualiserRaceState().getRaceDataSource().getBoundary(), gpsConverter);
|
Boundary3D boundary3D = new Boundary3D(visualiserRace.getVisualiserRaceState().getRaceDataSource().getBoundary(), gpsConverter);
|
||||||
@@ -234,20 +232,11 @@ public class RaceController extends Controller {
|
|||||||
for(Mark mark: race.getVisualiserRaceState().getMarks()) {
|
for(Mark mark: race.getVisualiserRaceState().getMarks()) {
|
||||||
MeshView mesh = new MeshView(importerMark.getImport());
|
MeshView mesh = new MeshView(importerMark.getImport());
|
||||||
Subject3D markModel = new Subject3D(mesh);
|
Subject3D markModel = new Subject3D(mesh);
|
||||||
// Subject3D markRadius = new MarkRadius(3);
|
|
||||||
|
|
||||||
double x = gpsConverter.convertGPS(mark.getPosition()).getX();
|
markModel.setX(gpsConverter.convertGPS(mark.getPosition()).getX());
|
||||||
double z = gpsConverter.convertGPS(mark.getPosition()).getY();
|
markModel.setZ(gpsConverter.convertGPS(mark.getPosition()).getY());
|
||||||
|
|
||||||
markModel.setX(x);
|
|
||||||
markModel.setZ(z);
|
|
||||||
markModel.setScale(3.5);
|
|
||||||
|
|
||||||
// markRadius.setX(x);
|
|
||||||
// markRadius.setZ(z);
|
|
||||||
|
|
||||||
viewSubjects.add(markModel);
|
viewSubjects.add(markModel);
|
||||||
// viewSubjects.add(markRadius);
|
|
||||||
}
|
}
|
||||||
// Position and add each boat to view
|
// Position and add each boat to view
|
||||||
for(VisualiserBoat boat: race.getVisualiserRaceState().getBoats()) {
|
for(VisualiserBoat boat: race.getVisualiserRaceState().getBoats()) {
|
||||||
@@ -258,28 +247,16 @@ public class RaceController extends Controller {
|
|||||||
mesh = new MeshView(importerBurgerBoat.getImport());
|
mesh = new MeshView(importerBurgerBoat.getImport());
|
||||||
}
|
}
|
||||||
Subject3D boatModel = new Subject3D(mesh);
|
Subject3D boatModel = new Subject3D(mesh);
|
||||||
//Subject3D boatArrow = new BoatArrow(12);
|
|
||||||
|
|
||||||
boatModel.setScale(1.5);
|
|
||||||
|
|
||||||
viewSubjects.add(boatModel);
|
viewSubjects.add(boatModel);
|
||||||
//viewSubjects.add(boatArrow);
|
|
||||||
|
|
||||||
// Track this boat's movement with the new subject
|
// Track this boat's movement with the new subject
|
||||||
AnimationTimer trackBoat = new AnimationTimer() {
|
AnimationTimer trackBoat = new AnimationTimer() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(long now) {
|
public void handle(long now) {
|
||||||
double heading = boat.getBearing().degrees();
|
boatModel.setHeading(boat.getBearing().degrees());
|
||||||
double x = gpsConverter.convertGPS(boat.getPosition()).getX();
|
boatModel.setX(gpsConverter.convertGPS(boat.getPosition()).getX());
|
||||||
double z = gpsConverter.convertGPS(boat.getPosition()).getY();
|
boatModel.setZ(gpsConverter.convertGPS(boat.getPosition()).getY());
|
||||||
|
|
||||||
boatModel.setHeading(heading);
|
|
||||||
boatModel.setX(x);
|
|
||||||
boatModel.setZ(z);
|
|
||||||
|
|
||||||
// boatArrow.setHeading(heading);
|
|
||||||
// boatArrow.setX(x);
|
|
||||||
// boatArrow.setZ(z);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
trackBoat.start();
|
trackBoat.start();
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
package visualiser.layout;
|
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import javafx.scene.paint.PhongMaterial;
|
|
||||||
import javafx.scene.shape.Box;
|
|
||||||
import javafx.scene.transform.Rotate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by cbt24 on 9/09/17.
|
|
||||||
*/
|
|
||||||
public class BoatArrow extends Subject3D {
|
|
||||||
public BoatArrow(double length) {
|
|
||||||
super(new Box(length/3, 0, length));
|
|
||||||
this.getMesh().getTransforms().add(new Rotate(-90, Rotate.X_AXIS));
|
|
||||||
this.getMesh().setMaterial(new PhongMaterial(new Color(1, 0, 0, 0.5)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package visualiser.layout;
|
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import javafx.scene.paint.PhongMaterial;
|
|
||||||
import javafx.scene.shape.Cylinder;
|
|
||||||
import javafx.scene.transform.Rotate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by cbt24 on 9/09/17.
|
|
||||||
*/
|
|
||||||
public class MarkRadius extends Subject3D {
|
|
||||||
public MarkRadius(double radius) {
|
|
||||||
super(new Cylinder(radius, 0));
|
|
||||||
this.getMesh().getTransforms().add(new Rotate(-90, Rotate.X_AXIS));
|
|
||||||
this.getMesh().setMaterial(new PhongMaterial(new Color(1, 0, 0, 0.5)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,51 +9,40 @@ import javafx.scene.paint.Color;
|
|||||||
import javafx.scene.paint.PhongMaterial;
|
import javafx.scene.paint.PhongMaterial;
|
||||||
import javafx.scene.shape.Box;
|
import javafx.scene.shape.Box;
|
||||||
import javafx.scene.shape.MeshView;
|
import javafx.scene.shape.MeshView;
|
||||||
|
import javafx.scene.shape.Shape3D;
|
||||||
import javafx.scene.shape.TriangleMesh;
|
import javafx.scene.shape.TriangleMesh;
|
||||||
import visualiser.utils.PerlinNoiseGenerator;
|
import visualiser.utils.PerlinNoiseGenerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a SeaSurface
|
* Creates a SeaSurface
|
||||||
*/
|
*/
|
||||||
public class SeaSurface {
|
public class SeaSurface extends Subject3D {
|
||||||
private float[][] noiseArray;
|
|
||||||
private Subject3D surface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sea Surface Constructor
|
* Sea Surface Constructor
|
||||||
* @param size size of the sea surface (has to be square for simplicity's sake)
|
* @param size size of the sea surface (has to be square for simplicity's sake)
|
||||||
* @param freq frequency the perlin noise is to be generated at
|
* @param freq frequency the perlin noise is to be generated at
|
||||||
* @param x offset that the sea should be set at position-wise
|
|
||||||
* @param z offset that the sea should be set at position-wise
|
|
||||||
*/
|
*/
|
||||||
public SeaSurface(int size, double freq, double x, double y, double z){
|
public SeaSurface(int size, double freq){
|
||||||
noiseArray = PerlinNoiseGenerator.createNoise(size, freq);
|
super(createSurface(size, freq));
|
||||||
createSurface();
|
|
||||||
surface.setZ(z);
|
|
||||||
surface.setY(y);
|
|
||||||
surface.setX(x);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the sea surface
|
* Creates the sea surface
|
||||||
*/
|
*/
|
||||||
private void createSurface(){
|
private static Shape3D createSurface(int size, double freq){
|
||||||
|
float[][] noiseArray = PerlinNoiseGenerator.createNoise(size, freq);
|
||||||
Image diffuseMap = createImage(noiseArray.length, noiseArray);
|
Image diffuseMap = createImage(noiseArray.length, noiseArray);
|
||||||
|
|
||||||
PhongMaterial material = new PhongMaterial();
|
PhongMaterial material = new PhongMaterial();
|
||||||
material.setDiffuseMap(diffuseMap);
|
material.setDiffuseMap(diffuseMap);
|
||||||
//material.setSpecularColor(Color.WHITE);
|
|
||||||
|
|
||||||
Plane3D seaPlane = new Plane3D(noiseArray.length, noiseArray.length, 10, 10);
|
Plane3D seaPlane = new Plane3D(noiseArray.length, noiseArray.length, 10, 10);
|
||||||
MeshView seaSurface = new MeshView(seaPlane);
|
MeshView seaSurface = new MeshView(seaPlane);
|
||||||
// Box seaSurface = new Box(noiseArray.length, 0.1, noiseArray.length);
|
|
||||||
seaSurface.setMaterial(material);
|
seaSurface.setMaterial(material);
|
||||||
seaSurface.setMouseTransparent(true);
|
seaSurface.setMouseTransparent(true);
|
||||||
seaSurface.toFront();
|
seaSurface.toFront();
|
||||||
//seaSurface.setRotationAxis(new Point3D(1, 0, 0));
|
|
||||||
//seaSurface.setRotate(90);
|
|
||||||
|
|
||||||
surface = new Subject3D(seaSurface);
|
return seaSurface;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +51,7 @@ public class SeaSurface {
|
|||||||
* @param noise array of noise
|
* @param noise array of noise
|
||||||
* @return image that is created
|
* @return image that is created
|
||||||
*/
|
*/
|
||||||
private Image createImage(double size, float[][] noise) {
|
private static Image createImage(double size, float[][] noise) {
|
||||||
|
|
||||||
int width = (int) size;
|
int width = (int) size;
|
||||||
int height = (int) size;
|
int height = (int) size;
|
||||||
@@ -129,11 +118,9 @@ public class SeaSurface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get surface
|
* Prevent rescaling of sea surface
|
||||||
* @return the surface so it can be drawn
|
* @param scale ignored
|
||||||
*/
|
*/
|
||||||
public Subject3D getSurface(){
|
@Override
|
||||||
return surface;
|
public void setScale(double scale) {}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,8 +148,11 @@ public class SkyBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addSeaOverlay() {
|
private void addSeaOverlay() {
|
||||||
SeaSurface seaSurface = new SeaSurface(size * 3, freq, x, y - size/4 + 1, z);
|
SeaSurface seaSurface = new SeaSurface(size * 3, freq);
|
||||||
skyBoxPlanes.add(seaSurface.getSurface());
|
seaSurface.setX(x);
|
||||||
|
seaSurface.setY(y - size/4 + 1);
|
||||||
|
seaSurface.setZ(z);
|
||||||
|
skyBoxPlanes.add(seaSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Subject3D> getSkyBoxPlanes() {
|
public List<Subject3D> getSkyBoxPlanes() {
|
||||||
|
|||||||
@@ -83,7 +83,11 @@ public class View3D extends Pane {
|
|||||||
/**
|
/**
|
||||||
* Distance to switch from third person to bird's eye
|
* Distance to switch from third person to bird's eye
|
||||||
*/
|
*/
|
||||||
private double THIRD_PERSON_LIMIT = 100;
|
private final double THIRD_PERSON_LIMIT = 100;
|
||||||
|
/**
|
||||||
|
* Distance to stop zoom
|
||||||
|
*/
|
||||||
|
private final double FIRST_PERSON_LIMIT = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for View3D. Sets up Scene and PerspectiveCamera.
|
* Default constructor for View3D. Sets up Scene and PerspectiveCamera.
|
||||||
@@ -162,11 +166,37 @@ public class View3D extends Pane {
|
|||||||
scene.setOnMousePressed(e -> {
|
scene.setOnMousePressed(e -> {
|
||||||
PickResult result = e.getPickResult();
|
PickResult result = e.getPickResult();
|
||||||
if(result != null && result.getIntersectedNode() != null && result.getIntersectedNode() instanceof Shape3D) {
|
if(result != null && result.getIntersectedNode() != null && result.getIntersectedNode() instanceof Shape3D) {
|
||||||
|
untrackSubject();
|
||||||
trackSubject(selectionMap.get(result.getIntersectedNode()));
|
trackSubject(selectionMap.get(result.getIntersectedNode()));
|
||||||
|
setThirdPerson();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures camera to third person view
|
||||||
|
*/
|
||||||
|
public void setThirdPerson() {
|
||||||
|
this.setDistance(THIRD_PERSON_LIMIT / 2);
|
||||||
|
this.setPitch(10);
|
||||||
|
|
||||||
|
for(Subject3D item: items) {
|
||||||
|
item.setScale(0.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures camera to bird's eye view
|
||||||
|
*/
|
||||||
|
public void setBirdsEye() {
|
||||||
|
this.setYaw(0);
|
||||||
|
this.setPitch(60);
|
||||||
|
|
||||||
|
for(Subject3D item: items) {
|
||||||
|
item.setScale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop camera from following the last selected subject
|
* Stop camera from following the last selected subject
|
||||||
*/
|
*/
|
||||||
@@ -184,7 +214,6 @@ public class View3D extends Pane {
|
|||||||
* @param subject to track
|
* @param subject to track
|
||||||
*/
|
*/
|
||||||
private void trackSubject(Subject3D subject) {
|
private void trackSubject(Subject3D subject) {
|
||||||
untrackSubject();
|
|
||||||
target = subject;
|
target = subject;
|
||||||
|
|
||||||
updatePivot(target.getPosition());
|
updatePivot(target.getPosition());
|
||||||
@@ -194,9 +223,6 @@ public class View3D extends Pane {
|
|||||||
target.getPosition().yProperty().addListener(pivotY);
|
target.getPosition().yProperty().addListener(pivotY);
|
||||||
target.getPosition().zProperty().addListener(pivotZ);
|
target.getPosition().zProperty().addListener(pivotZ);
|
||||||
target.getHeading().angleProperty().addListener(pivotHeading);
|
target.getHeading().angleProperty().addListener(pivotHeading);
|
||||||
|
|
||||||
this.setDistance(THIRD_PERSON_LIMIT);
|
|
||||||
this.setPitch(20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNearClip(double nearClip) {
|
public void setNearClip(double nearClip) {
|
||||||
@@ -234,13 +260,12 @@ public class View3D extends Pane {
|
|||||||
public void updateDistance(double delta) {
|
public void updateDistance(double delta) {
|
||||||
double distance = -this.distance.getZ() + delta;
|
double distance = -this.distance.getZ() + delta;
|
||||||
|
|
||||||
if(distance <= 0) {
|
if(distance <= FIRST_PERSON_LIMIT) {
|
||||||
this.setDistance(0);
|
this.setDistance(FIRST_PERSON_LIMIT);
|
||||||
} else if(distance > THIRD_PERSON_LIMIT) {
|
} else if(distance > THIRD_PERSON_LIMIT) {
|
||||||
untrackSubject();
|
|
||||||
this.setYaw(0);
|
|
||||||
this.setPitch(60);
|
|
||||||
this.setDistance(distance);
|
this.setDistance(distance);
|
||||||
|
untrackSubject();
|
||||||
|
setBirdsEye();
|
||||||
} else {
|
} else {
|
||||||
this.setDistance(distance);
|
this.setDistance(distance);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user