Merge remote-tracking branch 'origin/master' into game_start_button_1352
This commit is contained in:
@@ -16,6 +16,9 @@
|
||||
# https://www.kernel.org/pub/software/scm/git/docs/git-shortlog.html
|
||||
# http://stacktoheap.com/blog/2013/01/06/using-mailmap-to-fix-authors-list-in-git/
|
||||
Erika Savell <[email protected]>
|
||||
Connor Taylor-Brown <cbt24@cs17086jp.canterbury.ac.nz> <cbt24@uclive.canterbury.ac.nz>
|
||||
Connor Taylor-Brown <cbt24@uclive.ac.nz> <cbt24@cs17086jp.canterbury.ac.nz>
|
||||
Fraser Cope <[email protected]>
|
||||
Jessica Syder <[email protected]> Jessica Syder <[email protected]>
|
||||
Jessica Syder <[email protected]> <[email protected]>
|
||||
Joseph Gardner <[email protected]>
|
||||
Hamish Ball <[email protected]>
|
||||
David Wu <[email protected]>
|
||||
@@ -390,7 +390,7 @@ public class RaceViewController extends Controller {
|
||||
}
|
||||
}
|
||||
}
|
||||
view3D.updateDistance(-10);
|
||||
view3D.zoomIn();
|
||||
break;
|
||||
case "Zoom Out":
|
||||
//Check if race is a tutorial
|
||||
@@ -405,7 +405,7 @@ public class RaceViewController extends Controller {
|
||||
}
|
||||
}
|
||||
}
|
||||
view3D.updateDistance(10);
|
||||
view3D.zoomOut();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package visualiser.layout;
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.*;
|
||||
@@ -78,11 +77,17 @@ public class View3D extends Pane {
|
||||
/**
|
||||
* Distance to switch from third person to bird's eye
|
||||
*/
|
||||
private final double THIRD_PERSON_LIMIT = 100;
|
||||
private final double THIRD_PERSON_LIMIT = 500;
|
||||
/**
|
||||
* Distance to stop zoom
|
||||
*/
|
||||
private final double FIRST_PERSON_LIMIT = 2;
|
||||
private final double ZOOM_IN_LIMIT = 30;
|
||||
private final double ZOOM_OUT_LIMIT = 700;
|
||||
private final double MAX_ZOOM_LIMIT = 1500;
|
||||
private final double MAX_PITCH = 60; // birds eye view
|
||||
private final double MIN_PITCH = 5; // third person view
|
||||
private final double ZOOM_PER_KEYPRESS = 5; // distance changed per zoom
|
||||
private double itemScale = 1;
|
||||
|
||||
/**
|
||||
* Default constructor for View3D. Sets up Scene and PerspectiveCamera.
|
||||
@@ -183,12 +188,9 @@ public class View3D extends Pane {
|
||||
* 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);
|
||||
}
|
||||
this.setDistance(ZOOM_IN_LIMIT * 2);
|
||||
adjustPitchForZoom();
|
||||
adjustScaleForZoom();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,17 +198,14 @@ public class View3D extends Pane {
|
||||
*/
|
||||
public void setBirdsEye() {
|
||||
this.setYaw(0);
|
||||
this.setPitch(60);
|
||||
|
||||
for(Subject3D item: items) {
|
||||
item.setScale(1);
|
||||
}
|
||||
this.setPitch(MAX_PITCH);
|
||||
adjustScaleForZoom();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop camera from following the last selected subject
|
||||
*/
|
||||
private void untrackSubject() {
|
||||
public void untrackSubject() {
|
||||
if(target.get() != null) {
|
||||
trackBoat.stop();
|
||||
target.setValue(null);
|
||||
@@ -217,7 +216,7 @@ public class View3D extends Pane {
|
||||
* Set camera to follow the selected subject
|
||||
* @param subject to track
|
||||
*/
|
||||
private void trackSubject(Subject3D subject) {
|
||||
public void trackSubject(Subject3D subject) {
|
||||
target.set(subject);
|
||||
|
||||
this.trackBoat = new AnimationTimer() {
|
||||
@@ -267,17 +266,79 @@ public class View3D extends Pane {
|
||||
* @param delta amount to change distance by
|
||||
*/
|
||||
public void updateDistance(double delta) {
|
||||
double distance = -this.distance.getZ() + delta;
|
||||
|
||||
if(distance <= FIRST_PERSON_LIMIT) {
|
||||
this.setDistance(FIRST_PERSON_LIMIT);
|
||||
} else if(distance > THIRD_PERSON_LIMIT) {
|
||||
this.setDistance(distance);
|
||||
untrackSubject();
|
||||
setBirdsEye();
|
||||
double newDistance = -this.distance.getZ() + delta;
|
||||
if (target.get() == null){
|
||||
if (newDistance > MAX_ZOOM_LIMIT){
|
||||
setDistance(MAX_ZOOM_LIMIT);
|
||||
} else {
|
||||
this.setDistance(distance);
|
||||
setDistance(newDistance);
|
||||
}
|
||||
} else if(newDistance <= ZOOM_IN_LIMIT) {
|
||||
setDistance(ZOOM_IN_LIMIT);
|
||||
} else if (newDistance > ZOOM_OUT_LIMIT){
|
||||
untrackSubject();
|
||||
setDistance(1050);
|
||||
updatePivot(new Translate(250, 0, 210));
|
||||
setYaw(0);
|
||||
} else {
|
||||
setDistance(newDistance);
|
||||
}
|
||||
adjustPitchForZoom();
|
||||
adjustScaleForZoom();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the scale size of boats and markers as a user zooms in or out,
|
||||
* to smooth the change between third person to birds eye view.
|
||||
*/
|
||||
private void adjustScaleForZoom(){
|
||||
double itemScale = (((-distance.getZ() - (ZOOM_IN_LIMIT * 2)) /
|
||||
((THIRD_PERSON_LIMIT - (ZOOM_IN_LIMIT * 2)) /
|
||||
(1 - 0.1))) + 0.1);
|
||||
// if zoomed right in
|
||||
if (itemScale < 0.1){
|
||||
itemScale = 0.1;
|
||||
// if zoomed right out
|
||||
} else if (itemScale > 1) {
|
||||
itemScale = 1;
|
||||
}
|
||||
|
||||
// update scale
|
||||
for (Subject3D item : items) {
|
||||
item.setScale(itemScale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the pitch as a user zooms in or out, to smooth the change
|
||||
* between third person to birds eye view.
|
||||
*/
|
||||
private void adjustPitchForZoom(){
|
||||
double pitch = (((-distance.getZ() - (ZOOM_IN_LIMIT*2)) /
|
||||
((THIRD_PERSON_LIMIT - (ZOOM_IN_LIMIT*2)) / (MAX_PITCH -
|
||||
MIN_PITCH))) + MIN_PITCH);
|
||||
|
||||
// if pitch is out of bounds, set it to the min/max
|
||||
if (pitch < MIN_PITCH) {
|
||||
pitch = MIN_PITCH;
|
||||
} else if (pitch > MAX_PITCH){
|
||||
pitch = MAX_PITCH;
|
||||
}
|
||||
setPitch(pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to be called when the zoom in key is pressed.
|
||||
*/
|
||||
public void zoomIn(){
|
||||
updateDistance(-ZOOM_PER_KEYPRESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to be called when the zoom out key is pressed.
|
||||
*/
|
||||
public void zoomOut(){
|
||||
updateDistance(ZOOM_PER_KEYPRESS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user