- Added ability to color the indicators.

#tags [1276]
This commit is contained in:
alistairjmcintyre
2017-09-27 22:07:24 +13:00
parent c5e6302f86
commit 7a76efa2ce
@@ -8,6 +8,8 @@ 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;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.MeshView;
import javafx.scene.transform.Rotate; import javafx.scene.transform.Rotate;
import javafx.scene.transform.Scale; import javafx.scene.transform.Scale;
import javafx.scene.transform.Translate; import javafx.scene.transform.Translate;
@@ -30,12 +32,14 @@ public class BoatObject extends Group {
private BoatModel boatAssets; private BoatModel boatAssets;
private Group wake; private Group wake;
private Group markIndicator;
private Group playerIndicator;
private Color colour = Color.BLACK; private Color colour = Color.BLACK;
private Boolean isSelected = false; private Boolean isSelected = false;
private Rotate rotation = new Rotate(0, new Point3D(0,0,1)); private Rotate rotation = new Rotate(0, new Point3D(0,0,1));
// This stuff only matters to the players boat object.
private Group markIndicator;
private MeshView playerIndicator;
private Color indicatorColor = Color.LIGHTBLUE;
private ReadOnlyDoubleWrapper rotationProperty; private ReadOnlyDoubleWrapper rotationProperty;
private List<SelectedBoatListener> selectedBoatListenerListeners = new ArrayList<>(); private List<SelectedBoatListener> selectedBoatListenerListeners = new ArrayList<>();
@@ -85,25 +89,18 @@ public class BoatObject extends Group {
} }
public void updateMarkIndicator(Point2D markPoint) { public void updateMarkIndicator(Point2D markPoint) {
// calculate heading between boat and next mark
System.out.println(markPoint);
Point2D boatLoc = new Point2D(this.getLayoutX(), this.getLayoutY()); Point2D boatLoc = new Point2D(this.getLayoutX(), this.getLayoutY());
System.out.println(boatLoc);
Double angle = Math.toDegrees( Double angle = Math.toDegrees(
Math.atan2(boatLoc.getY() - markPoint.getY(), boatLoc.getX() - markPoint.getX())) - 90; Math.atan2(boatLoc.getY() - markPoint.getY(), boatLoc.getX() - markPoint.getX())) - 90;
Double radius = 2.7; Double radius = 2.7;
Double scale = 0.5; Double scale = 0.8;
Double originX = this.getLayoutX(); Double originX = this.getLayoutX();
Double originY = this.getLayoutY(); Double originY = this.getLayoutY();
Double transX = (radius * Math.cos(Math.toRadians(angle))); Double transX = (radius * Math.cos(Math.toRadians(angle)));
Double transY = (radius * Math.sin(Math.toRadians(angle))); Double transY = (radius * Math.sin(Math.toRadians(angle)));
System.out.println(transX);
System.out.println(transY);
markIndicator.getTransforms().clear(); markIndicator.getTransforms().clear();
markIndicator.getTransforms().addAll( markIndicator.getTransforms().addAll(
new Rotate(angle, new Point3D(0, 0, 1)), new Rotate(angle, new Point3D(0, 0, 1)),
@@ -154,13 +151,30 @@ public class BoatObject extends Group {
public void setMarkIndicator(Group indicator) { public void setMarkIndicator(Group indicator) {
this.markIndicator = indicator; this.markIndicator = indicator;
this.getChildren().add(markIndicator); this.getChildren().add(markIndicator);
createPlayerIndicator();
setIndicatorColor(indicatorColor);
}
private void createPlayerIndicator() {
Model torus = ModelFactory.importModel(ModelType.PLAYER_IDENTIFIER_TORUS); Model torus = ModelFactory.importModel(ModelType.PLAYER_IDENTIFIER_TORUS);
torus.getAssets().getTransforms().addAll( torus.getAssets().getTransforms().addAll(
new Rotate(90, new Point3D(1, 0, 0)), new Rotate(90, new Point3D(1, 0, 0)),
new Scale(0.7, 0.7, 0.7), new Scale(0.7, 0.7, 0.7),
new Translate(0, 0, 0) new Translate(0, 0, 0)
); );
this.getChildren().add(torus.getAssets()); this.getChildren().add(torus.getAssets());
playerIndicator = (MeshView) ((Group) ((Group) torus.getAssets().getChildren().get(0))
.getChildren().get(0)).getChildren().get(0);
}
public void setIndicatorColor(Color color) {
this.indicatorColor = color;
MeshView markIndicatorMesh = (MeshView) ((Group) ((Group) this.markIndicator.getChildren()
.get(0))
.getChildren().get(0)).getChildren().get(0);
markIndicatorMesh.setMaterial(new PhongMaterial(color));
playerIndicator.setMaterial(new PhongMaterial(color));
} }
public Group getWake () { public Group getWake () {