Bound zooming action to zoom keys
- View3D subject selection is no longer enabled by default - Added documentation #story[1190]
This commit is contained in:
@@ -26,6 +26,7 @@ import shared.model.Mark;
|
|||||||
import visualiser.app.App;
|
import visualiser.app.App;
|
||||||
import visualiser.gameController.ControllerClient;
|
import visualiser.gameController.ControllerClient;
|
||||||
import visualiser.gameController.Keys.ControlKey;
|
import visualiser.gameController.Keys.ControlKey;
|
||||||
|
import visualiser.gameController.Keys.KeyFactory;
|
||||||
import visualiser.layout.Subject3D;
|
import visualiser.layout.Subject3D;
|
||||||
import visualiser.layout.View3D;
|
import visualiser.layout.View3D;
|
||||||
import visualiser.model.*;
|
import visualiser.model.*;
|
||||||
@@ -185,15 +186,12 @@ public class RaceController extends Controller {
|
|||||||
view3D.setDistance(1050);
|
view3D.setDistance(1050);
|
||||||
view3D.setYaw(0);
|
view3D.setYaw(0);
|
||||||
view3D.setPitch(60);
|
view3D.setPitch(60);
|
||||||
RaceDataSource raceData = visualiserRace.getVisualiserRaceState().getRaceDataSource();
|
|
||||||
|
|
||||||
double lat1 = raceData.getMapTopLeft().getLatitude();
|
RaceDataSource raceData = visualiserRace.getVisualiserRaceState().getRaceDataSource();
|
||||||
double long1 = raceData.getMapTopLeft().getLongitude();
|
final GPSConverter gpsConverter = new GPSConverter(raceData, 450, 450);
|
||||||
double lat2 = raceData.getMapBottomRight().getLatitude();
|
|
||||||
double long2 = raceData.getMapBottomRight().getLongitude();
|
|
||||||
final GPSConverter gpsConverter = new GPSConverter(lat1, long1, lat2, long2, 450, 450);
|
|
||||||
|
|
||||||
view3D.setItems(viewSubjects);
|
view3D.setItems(viewSubjects);
|
||||||
|
view3D.enableTracking();
|
||||||
canvasBase.add(view3D, 0, 0);
|
canvasBase.add(view3D, 0, 0);
|
||||||
|
|
||||||
for(Mark mark: race.getVisualiserRaceState().getMarks()) {
|
for(Mark mark: race.getVisualiserRaceState().getMarks()) {
|
||||||
@@ -213,13 +211,8 @@ public class RaceController extends Controller {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(long now) {
|
public void handle(long now) {
|
||||||
subject.setHeading(boat.getBearing().degrees());
|
subject.setHeading(boat.getBearing().degrees());
|
||||||
double x = gpsConverter.convertGPS(boat.getPosition()).getX();
|
subject.setX(gpsConverter.convertGPS(boat.getPosition()).getX());
|
||||||
subject.setX(x);
|
|
||||||
subject.setZ(gpsConverter.convertGPS(boat.getPosition()).getY());
|
subject.setZ(gpsConverter.convertGPS(boat.getPosition()).getY());
|
||||||
if(boat.getSourceID() == race.getVisualiserRaceState().getPlayerBoatID()) {
|
|
||||||
//view3D.updatePivot(subject.getPosition());
|
|
||||||
}
|
|
||||||
//view3D.setYaw(boat.getBearing().degrees());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
trackBoat.start();
|
trackBoat.start();
|
||||||
@@ -229,6 +222,13 @@ public class RaceController extends Controller {
|
|||||||
view3D.setOnScroll(e -> {
|
view3D.setOnScroll(e -> {
|
||||||
view3D.updateDistance(e.getDeltaY());
|
view3D.updateDistance(e.getDeltaY());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
racePane.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
|
||||||
|
switch(keyFactory.getKey(e.getCode().toString()).toString()) {
|
||||||
|
case "Zoom In": view3D.updateDistance(-10); break;
|
||||||
|
case "Zoom Out": view3D.updateDistance(10); break;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package visualiser.gameController.Keys;
|
package visualiser.gameController.Keys;
|
||||||
|
|
||||||
import javafx.scene.input.KeyCode;
|
|
||||||
import network.Messages.Enums.BoatActionEnum;
|
import network.Messages.Enums.BoatActionEnum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,7 +44,7 @@ public abstract class ControlKey {
|
|||||||
/**
|
/**
|
||||||
* What this key should do when the command is issued for it to do its job.
|
* What this key should do when the command is issued for it to do its job.
|
||||||
*/
|
*/
|
||||||
public abstract void onAction();//may want to make it take in a visualiser and stuff in the future.
|
public abstract void onAction();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What to do when the key is held
|
* What to do when the key is held
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
package visualiser.layout;
|
package visualiser.layout;
|
||||||
|
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.beans.value.ObservableValue;
|
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.geometry.Point3D;
|
|
||||||
import javafx.scene.Group;
|
import javafx.scene.Group;
|
||||||
import javafx.scene.PerspectiveCamera;
|
import javafx.scene.PerspectiveCamera;
|
||||||
import javafx.scene.SubScene;
|
import javafx.scene.SubScene;
|
||||||
import javafx.scene.input.PickResult;
|
import javafx.scene.input.PickResult;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Shape;
|
|
||||||
import javafx.scene.shape.Shape3D;
|
import javafx.scene.shape.Shape3D;
|
||||||
import javafx.scene.transform.Rotate;
|
import javafx.scene.transform.Rotate;
|
||||||
import javafx.scene.transform.Translate;
|
import javafx.scene.transform.Translate;
|
||||||
@@ -25,6 +22,10 @@ import java.util.Map;
|
|||||||
* sky box, whose textures are set with special methods.
|
* sky box, whose textures are set with special methods.
|
||||||
*/
|
*/
|
||||||
public class View3D extends Pane {
|
public class View3D extends Pane {
|
||||||
|
/**
|
||||||
|
* Container for group and camera
|
||||||
|
*/
|
||||||
|
private SubScene scene;
|
||||||
/**
|
/**
|
||||||
* Observable list of renderable items
|
* Observable list of renderable items
|
||||||
*/
|
*/
|
||||||
@@ -65,39 +66,42 @@ public class View3D extends Pane {
|
|||||||
* Angle between ground plane and camera direction
|
* Angle between ground plane and camera direction
|
||||||
*/
|
*/
|
||||||
private Rotate pitch;
|
private Rotate pitch;
|
||||||
|
/**
|
||||||
|
* Single listener for subject heading changes
|
||||||
|
*/
|
||||||
private ChangeListener<? super Number> pivotHeading = (o, prev, curr) -> yaw.setAngle((double)curr);
|
private ChangeListener<? super Number> pivotHeading = (o, prev, curr) -> yaw.setAngle((double)curr);
|
||||||
|
/**
|
||||||
|
* Single listener for subject position (x) changes
|
||||||
|
*/
|
||||||
private ChangeListener<? super Number> pivotX = (o, prev, curr) -> pivot.setX((double)curr);
|
private ChangeListener<? super Number> pivotX = (o, prev, curr) -> pivot.setX((double)curr);
|
||||||
|
/**
|
||||||
|
* Single listener for subject position (y) changes
|
||||||
|
*/
|
||||||
private ChangeListener<? super Number> pivotY = (o, prev, curr) -> pivot.setY((double)curr);
|
private ChangeListener<? super Number> pivotY = (o, prev, curr) -> pivot.setY((double)curr);
|
||||||
|
/**
|
||||||
|
* Single listener for subject position (z) changes
|
||||||
|
*/
|
||||||
private ChangeListener<? super Number> pivotZ = (o, prev, curr) -> pivot.setZ((double)curr);
|
private ChangeListener<? super Number> pivotZ = (o, prev, curr) -> pivot.setZ((double)curr);
|
||||||
|
/**
|
||||||
|
* Distance to switch from third person to bird's eye
|
||||||
|
*/
|
||||||
private double THIRD_PERSON_LIMIT = 100;
|
private double THIRD_PERSON_LIMIT = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for View3D. Sets up Scene and PerspectiveCamera.
|
* Default constructor for View3D. Sets up Scene and PerspectiveCamera.
|
||||||
*/
|
*/
|
||||||
public View3D() {
|
public View3D() {
|
||||||
world = new Group();
|
this.world = new Group();
|
||||||
selectionMap = new HashMap<>();
|
this.selectionMap = new HashMap<>();
|
||||||
target = null;
|
this.target = null;
|
||||||
|
this.scene = new SubScene(world, 300, 300);
|
||||||
|
|
||||||
SubScene scene = new SubScene(world, 300, 300);
|
|
||||||
scene.widthProperty().bind(this.widthProperty());
|
scene.widthProperty().bind(this.widthProperty());
|
||||||
scene.heightProperty().bind(this.heightProperty());
|
scene.heightProperty().bind(this.heightProperty());
|
||||||
scene.setFill(new Color(0.2, 0.6, 1, 1));
|
scene.setFill(new Color(0.2, 0.6, 1, 1));
|
||||||
|
|
||||||
scene.setCamera(buildCamera());
|
scene.setCamera(buildCamera());
|
||||||
|
|
||||||
scene.setOnMousePressed(e -> {
|
|
||||||
PickResult result = e.getPickResult();
|
|
||||||
if(result != null && result.getIntersectedNode() != null && result.getIntersectedNode() instanceof Shape3D) {
|
|
||||||
trackSubject(selectionMap.get(result.getIntersectedNode()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.getChildren().add(scene);
|
this.getChildren().add(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,6 +146,15 @@ public class View3D extends Pane {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void enableTracking() {
|
||||||
|
scene.setOnMousePressed(e -> {
|
||||||
|
PickResult result = e.getPickResult();
|
||||||
|
if(result != null && result.getIntersectedNode() != null && result.getIntersectedNode() instanceof Shape3D) {
|
||||||
|
trackSubject(selectionMap.get(result.getIntersectedNode()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void untrackSubject() {
|
private void untrackSubject() {
|
||||||
if(target != null) {
|
if(target != null) {
|
||||||
target.getPosition().xProperty().removeListener(pivotX);
|
target.getPosition().xProperty().removeListener(pivotX);
|
||||||
@@ -189,6 +202,12 @@ public class View3D extends Pane {
|
|||||||
this.distance.setZ(-distance);
|
this.distance.setZ(-distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds delta to current distance and changes camera mode if applicable.
|
||||||
|
* Third person limit specifies the distance at which a third person camera
|
||||||
|
* switches to bird's-eye, remaining focused on the same position.
|
||||||
|
* @param delta amount to change distance by
|
||||||
|
*/
|
||||||
public void updateDistance(double delta) {
|
public void updateDistance(double delta) {
|
||||||
double distance = -this.distance.getZ() + delta;
|
double distance = -this.distance.getZ() + delta;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package visualiser.utils;
|
package visualiser.utils;
|
||||||
|
|
||||||
|
import shared.dataInput.RaceDataSource;
|
||||||
import shared.model.GPSCoordinate;
|
import shared.model.GPSCoordinate;
|
||||||
import visualiser.model.GraphCoordinate;
|
import visualiser.model.GraphCoordinate;
|
||||||
|
|
||||||
@@ -21,13 +22,13 @@ public class GPSConverter {
|
|||||||
*/
|
*/
|
||||||
private double latitudeFactor;
|
private double latitudeFactor;
|
||||||
|
|
||||||
public GPSConverter(double latTop, double longLeft, double latBottom, double longRight, double longitudeFactor, double latitudeFactor){
|
public GPSConverter(RaceDataSource source, double longitudeFactor, double latitudeFactor) {
|
||||||
this.longRight = longRight;
|
this.latTop = source.getMapTopLeft().getLatitude();
|
||||||
this.longLeft = longLeft;
|
this.longLeft = source.getMapTopLeft().getLongitude();
|
||||||
this.latBottom = latBottom;
|
this.latBottom = source.getMapBottomRight().getLatitude();
|
||||||
this.latTop = latTop;
|
this.longRight = source.getMapBottomRight().getLongitude();
|
||||||
this.longitudeFactor = (int)longitudeFactor;
|
this.longitudeFactor = longitudeFactor;
|
||||||
this.latitudeFactor = (int)latitudeFactor;
|
this.latitudeFactor = latitudeFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user