mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
- Chase Camera:
- Has panning bounds, zoom bounds, and general tidy up. - Now correctly observes the boat object rather than getting information from both the boat object AND the client yacht model. Top Down Camera: - Can only pan within certain bounds now, and will continue to follow the boat regardless. - Can only zoom within certain bounds now. Isometric Camera: - Nothing changed. #tags [1273]
This commit is contained in:
@@ -1,22 +1,25 @@
|
||||
package seng302.visualiser.cameras;
|
||||
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import java.util.Arrays;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.geometry.Point3D;
|
||||
import javafx.scene.PerspectiveCamera;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import javafx.scene.transform.Transform;
|
||||
import javafx.scene.transform.Translate;
|
||||
import seng302.model.ClientYacht;
|
||||
import seng302.visualiser.fxObjects.assets_3D.BoatObject;
|
||||
|
||||
|
||||
public class ChaseCamera extends PerspectiveCamera implements RaceCamera {
|
||||
|
||||
private final Double VERTICAL_PAN_LIMIT = 20.0;
|
||||
private final Double NEAR_ZOOM_LIMIT = -15.0;
|
||||
private final Double FAR_ZOOM_LIMIT = -125.0;
|
||||
|
||||
private ObservableList<Transform> transforms;
|
||||
private BoatObject playerBoat;
|
||||
private ClientYacht playerYacht;
|
||||
|
||||
private Double zoomFactor;
|
||||
private Double horizontalPan;
|
||||
private Double verticalPan;
|
||||
@@ -25,43 +28,27 @@ public class ChaseCamera extends PerspectiveCamera implements RaceCamera {
|
||||
public ChaseCamera() {
|
||||
super(true);
|
||||
transforms = this.getTransforms();
|
||||
this.zoomFactor = -75.0;
|
||||
|
||||
zoomFactor = (FAR_ZOOM_LIMIT + NEAR_ZOOM_LIMIT) / 2.0;
|
||||
this.horizontalPan = 0.0;
|
||||
this.verticalPan = 0.0;
|
||||
}
|
||||
|
||||
public void setPlayerBoat(BoatObject playerBoat, ClientYacht playerYacht) {
|
||||
public void setPlayerBoat(BoatObject playerBoat) {
|
||||
this.playerBoat = playerBoat;
|
||||
this.playerYacht = playerYacht;
|
||||
this.playerYacht.getHeadingProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable, Number oldValue,
|
||||
Number newValue) {
|
||||
repositionCamera();
|
||||
}
|
||||
});
|
||||
|
||||
this.playerBoat.layoutXProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable, Number oldValue,
|
||||
Number newValue) {
|
||||
repositionCamera();
|
||||
}
|
||||
});
|
||||
this.playerBoat.layoutYProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable, Number oldValue,
|
||||
Number newValue) {
|
||||
repositionCamera();
|
||||
}
|
||||
});
|
||||
for (DoubleProperty o : Arrays
|
||||
.asList(playerBoat.getRotationProperty(), playerBoat.layoutYProperty(),
|
||||
playerBoat.layoutXProperty())) {
|
||||
o.addListener((obs, oldVal, newVal) -> repositionCamera());
|
||||
}
|
||||
}
|
||||
|
||||
private void repositionCamera() {
|
||||
transforms.clear();
|
||||
transforms.addAll(
|
||||
new Translate(playerBoat.getLayoutX(), playerBoat.getLayoutY(), 0),
|
||||
new Rotate(playerYacht.getHeadingProperty().getValue() + horizontalPan,
|
||||
new Rotate(playerBoat.getRotationProperty().getValue() + horizontalPan,
|
||||
new Point3D(0, 0, 1)),
|
||||
new Rotate(60 + verticalPan, new Point3D(1, 0, 0)),
|
||||
new Translate(0, 0, zoomFactor)
|
||||
@@ -69,19 +56,25 @@ public class ChaseCamera extends PerspectiveCamera implements RaceCamera {
|
||||
}
|
||||
|
||||
private void adjustZoomFactor(Double adjustment) {
|
||||
if (zoomFactor + adjustment < -15.0 && zoomFactor + adjustment > -125.0) {
|
||||
if (zoomFactor + adjustment < NEAR_ZOOM_LIMIT && zoomFactor + adjustment > FAR_ZOOM_LIMIT) {
|
||||
zoomFactor = zoomFactor + adjustment;
|
||||
repositionCamera();
|
||||
}
|
||||
}
|
||||
|
||||
private void adjustVerticalPan(Double adjustment) {
|
||||
if (verticalPan + adjustment >= -20 && verticalPan + adjustment <= 20) {
|
||||
if (verticalPan + adjustment >= -VERTICAL_PAN_LIMIT
|
||||
&& verticalPan + adjustment <= VERTICAL_PAN_LIMIT) {
|
||||
verticalPan += adjustment;
|
||||
repositionCamera();
|
||||
}
|
||||
}
|
||||
|
||||
private void adjustHorizontalPan(Double adjustment) {
|
||||
this.horizontalPan += adjustment;
|
||||
repositionCamera();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void zoomIn() {
|
||||
adjustZoomFactor(5.0);
|
||||
@@ -92,21 +85,14 @@ public class ChaseCamera extends PerspectiveCamera implements RaceCamera {
|
||||
adjustZoomFactor(-5.0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
These have been left intentionally empty for now. it would be cool to be able to pan around the boat and have the camera move around the boat though.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void panLeft() {
|
||||
this.horizontalPan -= 5;
|
||||
repositionCamera();
|
||||
adjustHorizontalPan(-5.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void panRight() {
|
||||
this.horizontalPan += 5;
|
||||
repositionCamera();
|
||||
adjustHorizontalPan(5.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user