Merge remote-tracking branch 'origin/storyD-3D' into storyD-3D
This commit is contained in:
@@ -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.shape.Box;
|
||||
import javafx.scene.shape.MeshView;
|
||||
import javafx.scene.shape.Shape3D;
|
||||
import javafx.scene.shape.TriangleMesh;
|
||||
import visualiser.utils.PerlinNoiseGenerator;
|
||||
|
||||
/**
|
||||
* Creates a SeaSurface
|
||||
*/
|
||||
public class SeaSurface {
|
||||
private float[][] noiseArray;
|
||||
private Subject3D surface;
|
||||
|
||||
public class SeaSurface extends Subject3D {
|
||||
/**
|
||||
* Sea Surface Constructor
|
||||
* @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 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){
|
||||
noiseArray = PerlinNoiseGenerator.createNoise(size, freq);
|
||||
createSurface();
|
||||
surface.setZ(z);
|
||||
surface.setY(y);
|
||||
surface.setX(x);
|
||||
public SeaSurface(int size, double freq){
|
||||
super(createSurface(size, freq));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
PhongMaterial material = new PhongMaterial();
|
||||
material.setDiffuseMap(diffuseMap);
|
||||
//material.setSpecularColor(Color.WHITE);
|
||||
|
||||
Plane3D seaPlane = new Plane3D(noiseArray.length, noiseArray.length, 10, 10);
|
||||
MeshView seaSurface = new MeshView(seaPlane);
|
||||
// Box seaSurface = new Box(noiseArray.length, 0.1, noiseArray.length);
|
||||
seaSurface.setMaterial(material);
|
||||
seaSurface.setMouseTransparent(true);
|
||||
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
|
||||
* @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 height = (int) size;
|
||||
@@ -129,11 +118,9 @@ public class SeaSurface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get surface
|
||||
* @return the surface so it can be drawn
|
||||
* Prevent rescaling of sea surface
|
||||
* @param scale ignored
|
||||
*/
|
||||
public Subject3D getSurface(){
|
||||
return surface;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScale(double scale) {}
|
||||
}
|
||||
|
||||
@@ -148,8 +148,11 @@ public class SkyBox {
|
||||
}
|
||||
|
||||
private void addSeaOverlay() {
|
||||
SeaSurface seaSurface = new SeaSurface(size * 3, freq, x, y - size/4 + 1, z);
|
||||
skyBoxPlanes.add(seaSurface.getSurface());
|
||||
SeaSurface seaSurface = new SeaSurface(size * 3, freq);
|
||||
seaSurface.setX(x);
|
||||
seaSurface.setY(y - size/4 + 1);
|
||||
seaSurface.setZ(z);
|
||||
skyBoxPlanes.add(seaSurface);
|
||||
}
|
||||
|
||||
public List<Subject3D> getSkyBoxPlanes() {
|
||||
|
||||
@@ -83,7 +83,11 @@ public class View3D extends Pane {
|
||||
/**
|
||||
* 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.
|
||||
@@ -162,11 +166,37 @@ public class View3D extends Pane {
|
||||
scene.setOnMousePressed(e -> {
|
||||
PickResult result = e.getPickResult();
|
||||
if(result != null && result.getIntersectedNode() != null && result.getIntersectedNode() instanceof Shape3D) {
|
||||
untrackSubject();
|
||||
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
|
||||
*/
|
||||
@@ -184,7 +214,6 @@ public class View3D extends Pane {
|
||||
* @param subject to track
|
||||
*/
|
||||
private void trackSubject(Subject3D subject) {
|
||||
untrackSubject();
|
||||
target = subject;
|
||||
|
||||
updatePivot(target.getPosition());
|
||||
@@ -194,9 +223,6 @@ public class View3D extends Pane {
|
||||
target.getPosition().yProperty().addListener(pivotY);
|
||||
target.getPosition().zProperty().addListener(pivotZ);
|
||||
target.getHeading().angleProperty().addListener(pivotHeading);
|
||||
|
||||
this.setDistance(THIRD_PERSON_LIMIT);
|
||||
this.setPitch(20);
|
||||
}
|
||||
|
||||
public void setNearClip(double nearClip) {
|
||||
@@ -234,13 +260,12 @@ public class View3D extends Pane {
|
||||
public void updateDistance(double delta) {
|
||||
double distance = -this.distance.getZ() + delta;
|
||||
|
||||
if(distance <= 0) {
|
||||
this.setDistance(0);
|
||||
if(distance <= FIRST_PERSON_LIMIT) {
|
||||
this.setDistance(FIRST_PERSON_LIMIT);
|
||||
} else if(distance > THIRD_PERSON_LIMIT) {
|
||||
untrackSubject();
|
||||
this.setYaw(0);
|
||||
this.setPitch(60);
|
||||
this.setDistance(distance);
|
||||
untrackSubject();
|
||||
setBirdsEye();
|
||||
} else {
|
||||
this.setDistance(distance);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user