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.gameController.ControllerClient;
|
||||
import visualiser.gameController.Keys.ControlKey;
|
||||
import visualiser.gameController.Keys.KeyFactory;
|
||||
import visualiser.layout.Subject3D;
|
||||
import visualiser.layout.View3D;
|
||||
import visualiser.model.*;
|
||||
@@ -185,15 +186,12 @@ public class RaceController extends Controller {
|
||||
view3D.setDistance(1050);
|
||||
view3D.setYaw(0);
|
||||
view3D.setPitch(60);
|
||||
RaceDataSource raceData = visualiserRace.getVisualiserRaceState().getRaceDataSource();
|
||||
|
||||
double lat1 = raceData.getMapTopLeft().getLatitude();
|
||||
double long1 = raceData.getMapTopLeft().getLongitude();
|
||||
double lat2 = raceData.getMapBottomRight().getLatitude();
|
||||
double long2 = raceData.getMapBottomRight().getLongitude();
|
||||
final GPSConverter gpsConverter = new GPSConverter(lat1, long1, lat2, long2, 450, 450);
|
||||
RaceDataSource raceData = visualiserRace.getVisualiserRaceState().getRaceDataSource();
|
||||
final GPSConverter gpsConverter = new GPSConverter(raceData, 450, 450);
|
||||
|
||||
view3D.setItems(viewSubjects);
|
||||
view3D.enableTracking();
|
||||
canvasBase.add(view3D, 0, 0);
|
||||
|
||||
for(Mark mark: race.getVisualiserRaceState().getMarks()) {
|
||||
@@ -213,13 +211,8 @@ public class RaceController extends Controller {
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
subject.setHeading(boat.getBearing().degrees());
|
||||
double x = gpsConverter.convertGPS(boat.getPosition()).getX();
|
||||
subject.setX(x);
|
||||
subject.setX(gpsConverter.convertGPS(boat.getPosition()).getX());
|
||||
subject.setZ(gpsConverter.convertGPS(boat.getPosition()).getY());
|
||||
if(boat.getSourceID() == race.getVisualiserRaceState().getPlayerBoatID()) {
|
||||
//view3D.updatePivot(subject.getPosition());
|
||||
}
|
||||
//view3D.setYaw(boat.getBearing().degrees());
|
||||
}
|
||||
};
|
||||
trackBoat.start();
|
||||
@@ -229,6 +222,13 @@ public class RaceController extends Controller {
|
||||
view3D.setOnScroll(e -> {
|
||||
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;
|
||||
|
||||
import javafx.scene.input.KeyCode;
|
||||
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.
|
||||
*/
|
||||
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
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
package visualiser.layout;
|
||||
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.Point3D;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.PerspectiveCamera;
|
||||
import javafx.scene.SubScene;
|
||||
import javafx.scene.input.PickResult;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Shape;
|
||||
import javafx.scene.shape.Shape3D;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import javafx.scene.transform.Translate;
|
||||
@@ -25,6 +22,10 @@ import java.util.Map;
|
||||
* sky box, whose textures are set with special methods.
|
||||
*/
|
||||
public class View3D extends Pane {
|
||||
/**
|
||||
* Container for group and camera
|
||||
*/
|
||||
private SubScene scene;
|
||||
/**
|
||||
* Observable list of renderable items
|
||||
*/
|
||||
@@ -65,39 +66,42 @@ public class View3D extends Pane {
|
||||
* Angle between ground plane and camera direction
|
||||
*/
|
||||
private Rotate pitch;
|
||||
|
||||
/**
|
||||
* Single listener for subject heading changes
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Single listener for subject position (y) changes
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Distance to switch from third person to bird's eye
|
||||
*/
|
||||
private double THIRD_PERSON_LIMIT = 100;
|
||||
|
||||
/**
|
||||
* Default constructor for View3D. Sets up Scene and PerspectiveCamera.
|
||||
*/
|
||||
public View3D() {
|
||||
world = new Group();
|
||||
selectionMap = new HashMap<>();
|
||||
target = null;
|
||||
this.world = new Group();
|
||||
this.selectionMap = new HashMap<>();
|
||||
this.target = null;
|
||||
this.scene = new SubScene(world, 300, 300);
|
||||
|
||||
SubScene scene = new SubScene(world, 300, 300);
|
||||
scene.widthProperty().bind(this.widthProperty());
|
||||
scene.heightProperty().bind(this.heightProperty());
|
||||
scene.setFill(new Color(0.2, 0.6, 1, 1));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
if(target != null) {
|
||||
target.getPosition().xProperty().removeListener(pivotX);
|
||||
@@ -189,6 +202,12 @@ public class View3D extends Pane {
|
||||
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) {
|
||||
double distance = -this.distance.getZ() + delta;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package visualiser.utils;
|
||||
|
||||
import shared.dataInput.RaceDataSource;
|
||||
import shared.model.GPSCoordinate;
|
||||
import visualiser.model.GraphCoordinate;
|
||||
|
||||
@@ -21,13 +22,13 @@ public class GPSConverter {
|
||||
*/
|
||||
private double latitudeFactor;
|
||||
|
||||
public GPSConverter(double latTop, double longLeft, double latBottom, double longRight, double longitudeFactor, double latitudeFactor){
|
||||
this.longRight = longRight;
|
||||
this.longLeft = longLeft;
|
||||
this.latBottom = latBottom;
|
||||
this.latTop = latTop;
|
||||
this.longitudeFactor = (int)longitudeFactor;
|
||||
this.latitudeFactor = (int)latitudeFactor;
|
||||
public GPSConverter(RaceDataSource source, double longitudeFactor, double latitudeFactor) {
|
||||
this.latTop = source.getMapTopLeft().getLatitude();
|
||||
this.longLeft = source.getMapTopLeft().getLongitude();
|
||||
this.latBottom = source.getMapBottomRight().getLatitude();
|
||||
this.longRight = source.getMapBottomRight().getLongitude();
|
||||
this.longitudeFactor = longitudeFactor;
|
||||
this.latitudeFactor = latitudeFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user