mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
- Added Camera panning to chase camera mode.
tags : #story[1273]
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.Timer;
|
||||
import javafx.beans.property.ReadOnlyDoubleProperty;
|
||||
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||
import javafx.beans.property.ReadOnlyIntegerProperty;
|
||||
@@ -58,6 +59,8 @@ public class ClientYacht extends Observable {
|
||||
private Integer boatStatus;
|
||||
private Double currentVelocity;
|
||||
|
||||
Timer t;
|
||||
|
||||
private BoatObject boatObject;
|
||||
|
||||
private List<YachtLocationListener> locationListeners = new ArrayList<>();
|
||||
@@ -256,7 +259,6 @@ public class ClientYacht extends Observable {
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
|
||||
public void updateLocation(double lat, double lng, double heading, double velocity) {
|
||||
setLocation(lat, lng);
|
||||
this.heading = heading;
|
||||
@@ -269,17 +271,7 @@ public class ClientYacht extends Observable {
|
||||
}
|
||||
|
||||
private void setHeadingProperty() {
|
||||
Double oldHeading = getHeadingProperty().get();
|
||||
Double currHeading = heading;
|
||||
while (oldHeading.equals(currHeading)) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
oldHeading += 0.5;
|
||||
headingProperty.set(oldHeading);
|
||||
}
|
||||
headingProperty.set(heading);
|
||||
}
|
||||
|
||||
public void addLocationListener(YachtLocationListener listener) {
|
||||
|
||||
@@ -68,7 +68,7 @@ public class ClientToServerThread implements Runnable {
|
||||
private Timer upWindPacketTimer = new Timer();
|
||||
private Timer downWindPacketTimer = new Timer();
|
||||
private boolean upwindTimerFlag = false, downwindTimerFlag = false;
|
||||
static public final int PACKET_SENDING_INTERVAL_MS = 60;
|
||||
static public final int PACKET_SENDING_INTERVAL_MS = 100;
|
||||
|
||||
private int clientId = -1;
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ import seng302.visualiser.cameras.RaceCamera;
|
||||
import seng302.visualiser.cameras.TopDownCamera;
|
||||
import seng302.visualiser.controllers.ViewManager;
|
||||
import seng302.visualiser.fxObjects.MarkArrowFactory;
|
||||
import seng302.visualiser.fxObjects.assets_3D.BoatMeshType;
|
||||
import seng302.visualiser.fxObjects.assets_3D.BoatObject;
|
||||
import seng302.visualiser.fxObjects.assets_3D.Marker3D;
|
||||
import seng302.visualiser.fxObjects.assets_3D.ModelFactory;
|
||||
@@ -47,7 +46,6 @@ import seng302.visualiser.fxObjects.assets_3D.ModelType;
|
||||
|
||||
public class GameView3D {
|
||||
|
||||
|
||||
private final double FOV = 60;
|
||||
private final double DEFAULT_CAMERA_DEPTH = -125;
|
||||
private final double DEFAULT_CAMERA_X = 0;
|
||||
|
||||
@@ -18,18 +18,21 @@ public class ChaseCamera extends PerspectiveCamera implements RaceCamera {
|
||||
private BoatObject playerBoat;
|
||||
private ClientYacht playerYacht;
|
||||
private Double zoomFactor;
|
||||
private Double horizontalPan;
|
||||
private Double verticalPan;
|
||||
|
||||
|
||||
public ChaseCamera() {
|
||||
super(true);
|
||||
transforms = this.getTransforms();
|
||||
this.zoomFactor = -75.0;
|
||||
this.horizontalPan = 0.0;
|
||||
this.verticalPan = 0.0;
|
||||
}
|
||||
|
||||
public void setPlayerBoat(BoatObject playerBoat, ClientYacht playerYacht) {
|
||||
this.playerBoat = playerBoat;
|
||||
this.playerYacht = playerYacht;
|
||||
System.out.println(playerYacht.getHeadingProperty().get());
|
||||
this.playerYacht.getHeadingProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable, Number oldValue,
|
||||
@@ -58,18 +61,9 @@ public class ChaseCamera extends PerspectiveCamera implements RaceCamera {
|
||||
transforms.clear();
|
||||
transforms.addAll(
|
||||
new Translate(playerBoat.getLayoutX(), playerBoat.getLayoutY(), 0),
|
||||
new Rotate(playerYacht.getHeading(), new Point3D(0, 0, 1)),
|
||||
new Rotate(60, new Point3D(1, 0, 0)),
|
||||
new Translate(0, 0, zoomFactor)
|
||||
);
|
||||
}
|
||||
|
||||
private void repositionCamera(Double newHeading) {
|
||||
transforms.clear();
|
||||
transforms.addAll(
|
||||
new Translate(playerBoat.getLayoutX(), playerBoat.getLayoutY(), 0),
|
||||
new Rotate(newHeading, new Point3D(0, 0, 1)),
|
||||
new Rotate(60, new Point3D(1, 0, 0)),
|
||||
new Rotate(playerYacht.getHeadingProperty().getValue() + horizontalPan,
|
||||
new Point3D(0, 0, 1)),
|
||||
new Rotate(60 + verticalPan, new Point3D(1, 0, 0)),
|
||||
new Translate(0, 0, zoomFactor)
|
||||
);
|
||||
}
|
||||
@@ -77,19 +71,25 @@ public class ChaseCamera extends PerspectiveCamera implements RaceCamera {
|
||||
private void adjustZoomFactor(Double adjustment) {
|
||||
if (zoomFactor + adjustment < -15.0 && zoomFactor + adjustment > -125.0) {
|
||||
zoomFactor = zoomFactor + adjustment;
|
||||
repositionCamera();
|
||||
}
|
||||
}
|
||||
|
||||
private void adjustVerticalPan(Double adjustment) {
|
||||
if (verticalPan + adjustment >= -20 && verticalPan + adjustment <= 20) {
|
||||
verticalPan += adjustment;
|
||||
repositionCamera();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zoomIn() {
|
||||
adjustZoomFactor(5.0);
|
||||
repositionCamera();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zoomOut() {
|
||||
adjustZoomFactor(-5.0);
|
||||
repositionCamera();
|
||||
}
|
||||
|
||||
|
||||
@@ -99,17 +99,23 @@ public class ChaseCamera extends PerspectiveCamera implements RaceCamera {
|
||||
|
||||
@Override
|
||||
public void panLeft() {
|
||||
this.horizontalPan -= 5;
|
||||
repositionCamera();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panRight() {
|
||||
this.horizontalPan += 5;
|
||||
repositionCamera();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panUp() {
|
||||
adjustVerticalPan(-5.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panDown() {
|
||||
adjustVerticalPan(5.0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user