- Marker seems to be detecting the correct mark but somethings wrong with the maths.

tags : #story[1276]
This commit is contained in:
Alistair McIntyre
2017-09-27 17:52:54 +13:00
parent aded794a67
commit 452e83c1c3
2 changed files with 25 additions and 19 deletions
@@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import javafx.animation.AnimationTimer; import javafx.animation.AnimationTimer;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.geometry.Point3D; import javafx.geometry.Point3D;
import javafx.scene.Camera; import javafx.scene.Camera;
@@ -79,6 +80,7 @@ public class GameView3D {
private List<Limit> borderPoints; private List<Limit> borderPoints;
private Map<Mark, Marker3D> markerObjects; private Map<Mark, Marker3D> markerObjects;
private BoatObject playerBoat;
private Map<ClientYacht, BoatObject> boatObjects = new HashMap<>(); private Map<ClientYacht, BoatObject> boatObjects = new HashMap<>();
private BoatObject selectedBoat = null; private BoatObject selectedBoat = null;
private Group wakesGroup = new Group(); private Group wakesGroup = new Group();
@@ -494,11 +496,23 @@ public class GameView3D {
ViewManager.getInstance().getGameClient().getServerThread().getClientId())) { ViewManager.getInstance().getGameClient().getServerThread().getClientId())) {
((ChaseCamera) chaseCam).setPlayerBoat(newBoat); ((ChaseCamera) chaseCam).setPlayerBoat(newBoat);
((TopDownCamera) topDownCam).setPlayerBoat(newBoat); ((TopDownCamera) topDownCam).setPlayerBoat(newBoat);
newBoat.setMarkIndicator( newBoat.setMarkIndicator(
ModelFactory.importModel(ModelType.NEXT_MARK_INDICATOR).getAssets()); ModelFactory.importModel(ModelType.NEXT_MARK_INDICATOR).getAssets());
playerBoat = newBoat;
} }
} }
Platform.runLater(() -> { Platform.runLater(() -> {
ClientYacht playerYacht = ViewManager.getInstance().getGameClient().getAllBoatsMap()
.get(ViewManager.getInstance().getGameClient().getServerThread().getClientId());
for (ObservableValue o : Arrays
.asList(playerBoat.layoutXProperty(), playerBoat.layoutXProperty())) {
o.addListener((obs, oldVal, newVal) -> playerBoat.updateMarkIndicator(
findScaledXY(course.get(playerYacht.getLegNumber()).getMidPoint())
));
}
gameObjects.getChildren().addAll(wakes); gameObjects.getChildren().addAll(wakes);
gameObjects.getChildren().addAll(boatObjectGroup); gameObjects.getChildren().addAll(boatObjectGroup);
}); });
@@ -5,6 +5,7 @@ import java.util.List;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.property.ReadOnlyDoubleWrapper; import javafx.beans.property.ReadOnlyDoubleWrapper;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.geometry.Point2D;
import javafx.geometry.Point3D; import javafx.geometry.Point3D;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
@@ -12,8 +13,6 @@ import javafx.scene.transform.Rotate;
import javafx.scene.transform.Scale; import javafx.scene.transform.Scale;
import javafx.scene.transform.Transform; import javafx.scene.transform.Transform;
import javafx.scene.transform.Translate; 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 * BoatGroup is a javafx group that by default contains a graphical objects for representing a 2
@@ -83,34 +82,26 @@ public class BoatObject extends Group {
this.layoutYProperty().setValue(y); this.layoutYProperty().setValue(y);
wake.setLayoutX(x); wake.setLayoutX(x);
wake.setLayoutY(y); wake.setLayoutY(y);
if (markIndicator != null) { // The player boat.
updateMarkIndicator();
}
}); });
} }
private void updateMarkIndicator() { public void updateMarkIndicator(Point2D markPoint) {
// calculate heading between boat and next mark // calculate heading between boat and next mark
Integer sourceId = ViewManager.getInstance().getGameClient().getServerThread() Double x = markPoint.getX();
.getClientId(); Double y = markPoint.getY();
ClientYacht playerYacht = ViewManager.getInstance().getGameClient().getAllBoatsMap()
.get(sourceId);
Double x; Double deltaX = (boatAssets.getAssets().getLayoutX() - x);
Double y; Double deltaY = (boatAssets.getAssets().getLayoutY() - y);
Double deltaX = (this.getLayoutX() - x);
Double deltaY = (this.getLayoutY() - y);
Double angle = Math.toDegrees(Math.atan2(deltaY, deltaX)); Double angle = Math.toDegrees(Math.atan2(deltaY, deltaX));
//Double angle = rotation.getAngle();
ObservableList<Transform> transforms = markIndicator.getTransforms(); ObservableList<Transform> transforms = markIndicator.getTransforms();
Double radius = 3.0; Double radius = 3.0;
Double scale = 0.4; Double scale = 0.4;
//Double angle = this.rotation.getAngle(); // THIS WILL BE THE NEXT MARK
Double originX = this.getLayoutX(); Double originX = this.getLayoutX();
Double originY = this.getLayoutY(); Double originY = this.getLayoutY();
@@ -119,7 +110,8 @@ public class BoatObject extends Group {
transforms.clear(); transforms.clear();
transforms.addAll( transforms.addAll(
new Rotate(angle, markIndicator.getLayoutX(), markIndicator.getLayoutY(), 0), new Rotate(angle, boatAssets.getAssets().getLayoutX(),
boatAssets.getAssets().getLayoutY(), 0),
new Translate(transX, transY, -1), new Translate(transX, transY, -1),
new Scale(scale, scale, scale) new Scale(scale, scale, scale)
); );