diff --git a/.mailmap b/.mailmap index 7498647c..b774add7 100644 --- a/.mailmap +++ b/.mailmap @@ -18,4 +18,6 @@ Erika Savell Connor Taylor-Brown Fraser Cope -Jessica Syder Jessica Syder \ No newline at end of file +Jessica Syder Jessica Syder +Joseph Gardner +Hamish Ball hba56 \ No newline at end of file diff --git a/racevisionGame/src/main/java/visualiser/Controllers/RaceViewController.java b/racevisionGame/src/main/java/visualiser/Controllers/RaceViewController.java index e9b45a3d..d1f6601c 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/RaceViewController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/RaceViewController.java @@ -467,7 +467,7 @@ public class RaceViewController extends Controller { } } } - view3D.updateDistance(-10); + view3D.zoomIn(); break; case "Zoom Out": //Check if race is a tutorial @@ -482,7 +482,7 @@ public class RaceViewController extends Controller { } } } - view3D.updateDistance(10); + view3D.zoomOut(); break; } } diff --git a/racevisionGame/src/main/java/visualiser/layout/View3D.java b/racevisionGame/src/main/java/visualiser/layout/View3D.java index fd5e0881..7277ac5f 100644 --- a/racevisionGame/src/main/java/visualiser/layout/View3D.java +++ b/racevisionGame/src/main/java/visualiser/layout/View3D.java @@ -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,19 +266,81 @@ 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); + double newDistance = -this.distance.getZ() + delta; + if (target.get() == null){ + if (newDistance > MAX_ZOOM_LIMIT){ + setDistance(MAX_ZOOM_LIMIT); + } else { + setDistance(newDistance); + } + } else if(newDistance <= ZOOM_IN_LIMIT) { + setDistance(ZOOM_IN_LIMIT); + } else if (newDistance > ZOOM_OUT_LIMIT){ untrackSubject(); - setBirdsEye(); + setDistance(1050); + updatePivot(new Translate(250, 0, 210)); + setYaw(0); } else { - this.setDistance(distance); + 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); + } + /** * Set angle of camera from z-axis along ground * @param yaw in degrees