Zooming motion is more natural.
- added limits for zoom in, zoom out and when to change to birds eye - zooming smoothed by adjusting pitch each zoom - when zoom out limit is reached, view returns to original #story[1312]
This commit is contained in:
@@ -369,7 +369,8 @@ public class RaceViewController extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
view3D.updateDistance(-10);
|
// view3D.updateDistance(-10);
|
||||||
|
view3D.zoomIn();
|
||||||
break;
|
break;
|
||||||
case "Zoom Out":
|
case "Zoom Out":
|
||||||
//Check if race is a tutorial
|
//Check if race is a tutorial
|
||||||
@@ -384,7 +385,8 @@ public class RaceViewController extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
view3D.updateDistance(10);
|
// view3D.updateDistance(10);
|
||||||
|
view3D.zoomOut();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package visualiser.layout;
|
|||||||
import javafx.animation.AnimationTimer;
|
import javafx.animation.AnimationTimer;
|
||||||
import javafx.beans.property.ObjectProperty;
|
import javafx.beans.property.ObjectProperty;
|
||||||
import javafx.beans.property.SimpleObjectProperty;
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
import javafx.beans.value.ChangeListener;
|
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.scene.*;
|
import javafx.scene.*;
|
||||||
@@ -78,11 +77,15 @@ 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 final double THIRD_PERSON_LIMIT = 100;
|
private final double THIRD_PERSON_LIMIT = 200;
|
||||||
/**
|
/**
|
||||||
* Distance to stop zoom
|
* 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_PITCH = 60; // birds eye view
|
||||||
|
private final double MIN_PITCH = 10; // third person view
|
||||||
|
private final double ZOOM_PER_KEYPRESS = 5; // distance changed per zoom
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for View3D. Sets up Scene and PerspectiveCamera.
|
* Default constructor for View3D. Sets up Scene and PerspectiveCamera.
|
||||||
@@ -183,11 +186,11 @@ public class View3D extends Pane {
|
|||||||
* Configures camera to third person view
|
* Configures camera to third person view
|
||||||
*/
|
*/
|
||||||
public void setThirdPerson() {
|
public void setThirdPerson() {
|
||||||
this.setDistance(THIRD_PERSON_LIMIT / 2);
|
this.setDistance(ZOOM_IN_LIMIT * 2);
|
||||||
this.setPitch(10);
|
adjustPitchForZoom();
|
||||||
|
|
||||||
for(Subject3D item: items) {
|
for(Subject3D item: items) {
|
||||||
item.setScale(0.1);
|
item.setScale(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,15 +272,47 @@ 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 <= FIRST_PERSON_LIMIT) {
|
if(distance <= ZOOM_IN_LIMIT) {
|
||||||
this.setDistance(FIRST_PERSON_LIMIT);
|
setDistance(ZOOM_IN_LIMIT);
|
||||||
} else if(distance > THIRD_PERSON_LIMIT) {
|
} else if (distance > ZOOM_OUT_LIMIT){
|
||||||
this.setDistance(distance);
|
|
||||||
untrackSubject();
|
untrackSubject();
|
||||||
setBirdsEye();
|
setDistance(1050);
|
||||||
|
updatePivot(new Translate(250, 0, 210));
|
||||||
} else {
|
} else {
|
||||||
this.setDistance(distance);
|
setDistance(distance);
|
||||||
}
|
}
|
||||||
|
adjustPitchForZoom();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) /
|
||||||
|
((THIRD_PERSON_LIMIT - ZOOM_IN_LIMIT) / (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