- Added new indicator for direction to next mark.

- Marker rotates towards a given heading.

tags : #story[1276]
This commit is contained in:
Alistair McIntyre
2017-09-27 17:17:50 +13:00
parent 2dcdd1c248
commit aded794a67
5 changed files with 267 additions and 4 deletions
@@ -91,6 +91,7 @@ public class GameView3D {
private Group trail = new Group();
private Double windDir;
private enum ScaleDirection {
HORIZONTAL,
VERTICAL
@@ -457,7 +458,7 @@ public class GameView3D {
/**
* Rescales the race to the size of the window.
*
*g
* @param limitingCoordinates the set of geo points that contains the extremities of the race.
*/
private void rescaleRace(List<GeoPoint> limitingCoordinates) {
@@ -493,6 +494,8 @@ public class GameView3D {
ViewManager.getInstance().getGameClient().getServerThread().getClientId())) {
((ChaseCamera) chaseCam).setPlayerBoat(newBoat);
((TopDownCamera) topDownCam).setPlayerBoat(newBoat);
newBoat.setMarkIndicator(
ModelFactory.importModel(ModelType.NEXT_MARK_INDICATOR).getAssets());
}
}
Platform.runLater(() -> {
@@ -602,6 +605,10 @@ public class GameView3D {
public void handle(long now) {
if (--count == 0) {
count = 60;
boatObjects.get(playerYacht);
course.get(playerYacht.getLegNumber()).getMidPoint().getLat();
Node segment = ModelFactory.importModel(ModelType.TRAIL_SEGMENT).getAssets();
Point2D location = findScaledXY(playerYacht.getLocation());
segment.getTransforms().addAll(
@@ -4,10 +4,16 @@ import java.util.ArrayList;
import java.util.List;
import javafx.application.Platform;
import javafx.beans.property.ReadOnlyDoubleWrapper;
import javafx.collections.ObservableList;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Scale;
import javafx.scene.transform.Transform;
import javafx.scene.transform.Translate;
import seng302.model.ClientYacht;
import seng302.visualiser.controllers.ViewManager;
/**
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2
@@ -27,6 +33,7 @@ public class BoatObject extends Group {
private BoatModel boatAssets;
private Group wake;
private Group markIndicator;
private Color colour = Color.BLACK;
private Boolean isSelected = false;
private Rotate rotation = new Rotate(0, new Point3D(0,0,1));
@@ -76,9 +83,48 @@ public class BoatObject extends Group {
this.layoutYProperty().setValue(y);
wake.setLayoutX(x);
wake.setLayoutY(y);
if (markIndicator != null) { // The player boat.
updateMarkIndicator();
}
});
}
private void updateMarkIndicator() {
// calculate heading between boat and next mark
Integer sourceId = ViewManager.getInstance().getGameClient().getServerThread()
.getClientId();
ClientYacht playerYacht = ViewManager.getInstance().getGameClient().getAllBoatsMap()
.get(sourceId);
Double x;
Double y;
Double deltaX = (this.getLayoutX() - x);
Double deltaY = (this.getLayoutY() - y);
Double angle = Math.toDegrees(Math.atan2(deltaY, deltaX));
ObservableList<Transform> transforms = markIndicator.getTransforms();
Double radius = 3.0;
Double scale = 0.4;
//Double angle = this.rotation.getAngle(); // THIS WILL BE THE NEXT MARK
Double originX = this.getLayoutX();
Double originY = this.getLayoutY();
Double transX = (radius * Math.cos(Math.toRadians(angle)));
Double transY = (radius * Math.sin(Math.toRadians(angle)));
transforms.clear();
transforms.addAll(
new Rotate(angle, markIndicator.getLayoutX(), markIndicator.getLayoutY(), 0),
new Translate(transX, transY, -1),
new Scale(scale, scale, scale)
);
}
private Double normalizeHeading(double heading, double windDirection) {
Double normalizedHeading = heading - windDirection;
normalizedHeading = (double) Math.floorMod(normalizedHeading.longValue(), 360L);
@@ -118,6 +164,11 @@ public class BoatObject extends Group {
}
}
public void setMarkIndicator(Group indicator) {
this.markIndicator = indicator;
this.getChildren().add(markIndicator);
}
public Group getWake () {
return wake;
}
@@ -7,7 +7,6 @@ import javafx.geometry.Point3D;
import javafx.scene.AmbientLight;
import javafx.scene.CacheHint;
import javafx.scene.Group;
import javafx.scene.PointLight;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Circle;
@@ -155,6 +154,8 @@ public class ModelFactory {
assets.setCacheHint(CacheHint.SCALE_AND_ROTATE);
}
switch (tokenType) {
case NEXT_MARK_INDICATOR:
return makeNextMarkIndicator(assets);
case VELOCITY_PICKUP:
return makeCoinPickup(assets);
case FINISH_MARKER:
@@ -185,7 +186,19 @@ public class ModelFactory {
}
}
private static Model makeCoinPickup(Group assets){
private static Model makeNextMarkIndicator(Group assets) {
// assets.getTransforms().addAll(
// new Translate(10, 10, 0),
// new Rotate(90, new Point3D(0,0,1)),
// new Scale(0.5, 0.5, 0.5)
// );
assets.getChildren().add(new AmbientLight());
return new Model(new Group(assets), null);
}
private static Model makeCoinPickup(Group assets) {
assets.setRotationAxis(new Point3D(1,0,0));
assets.setRotate(90);
assets.setTranslateX(0.2);
@@ -22,7 +22,8 @@ public enum ModelType {
PLAYER_IDENTIFIER ("player_identifier.dae"),
PLAIN_ARROW ("arrow.dae"),
START_ARROW ("start_arrow.dae"),
FINISH_ARROW ("finish_arrow.dae");
FINISH_ARROW("finish_arrow.dae"),
NEXT_MARK_INDICATOR("indicator_arrow.dae");
final String filename;