- 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 Group trail = new Group();
private Double windDir; private Double windDir;
private enum ScaleDirection { private enum ScaleDirection {
HORIZONTAL, HORIZONTAL,
VERTICAL VERTICAL
@@ -457,7 +458,7 @@ public class GameView3D {
/** /**
* Rescales the race to the size of the window. * Rescales the race to the size of the window.
* *g
* @param limitingCoordinates the set of geo points that contains the extremities of the race. * @param limitingCoordinates the set of geo points that contains the extremities of the race.
*/ */
private void rescaleRace(List<GeoPoint> limitingCoordinates) { private void rescaleRace(List<GeoPoint> limitingCoordinates) {
@@ -493,6 +494,8 @@ 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(
ModelFactory.importModel(ModelType.NEXT_MARK_INDICATOR).getAssets());
} }
} }
Platform.runLater(() -> { Platform.runLater(() -> {
@@ -602,6 +605,10 @@ public class GameView3D {
public void handle(long now) { public void handle(long now) {
if (--count == 0) { if (--count == 0) {
count = 60; count = 60;
boatObjects.get(playerYacht);
course.get(playerYacht.getLegNumber()).getMidPoint().getLat();
Node segment = ModelFactory.importModel(ModelType.TRAIL_SEGMENT).getAssets(); Node segment = ModelFactory.importModel(ModelType.TRAIL_SEGMENT).getAssets();
Point2D location = findScaledXY(playerYacht.getLocation()); Point2D location = findScaledXY(playerYacht.getLocation());
segment.getTransforms().addAll( segment.getTransforms().addAll(
@@ -4,10 +4,16 @@ import java.util.ArrayList;
import java.util.List; 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.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.transform.Rotate; 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 * 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 BoatModel boatAssets;
private Group wake; private Group wake;
private Group markIndicator;
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));
@@ -76,9 +83,48 @@ 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() {
// 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) { private Double normalizeHeading(double heading, double windDirection) {
Double normalizedHeading = heading - windDirection; Double normalizedHeading = heading - windDirection;
normalizedHeading = (double) Math.floorMod(normalizedHeading.longValue(), 360L); 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 () { public Group getWake () {
return wake; return wake;
} }
@@ -7,7 +7,6 @@ import javafx.geometry.Point3D;
import javafx.scene.AmbientLight; import javafx.scene.AmbientLight;
import javafx.scene.CacheHint; import javafx.scene.CacheHint;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.PointLight;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial; import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
@@ -155,6 +154,8 @@ public class ModelFactory {
assets.setCacheHint(CacheHint.SCALE_AND_ROTATE); assets.setCacheHint(CacheHint.SCALE_AND_ROTATE);
} }
switch (tokenType) { switch (tokenType) {
case NEXT_MARK_INDICATOR:
return makeNextMarkIndicator(assets);
case VELOCITY_PICKUP: case VELOCITY_PICKUP:
return makeCoinPickup(assets); return makeCoinPickup(assets);
case FINISH_MARKER: 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.setRotationAxis(new Point3D(1,0,0));
assets.setRotate(90); assets.setRotate(90);
assets.setTranslateX(0.2); assets.setTranslateX(0.2);
@@ -22,7 +22,8 @@ public enum ModelType {
PLAYER_IDENTIFIER ("player_identifier.dae"), PLAYER_IDENTIFIER ("player_identifier.dae"),
PLAIN_ARROW ("arrow.dae"), PLAIN_ARROW ("arrow.dae"),
START_ARROW ("start_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; final String filename;
@@ -0,0 +1,191 @@
<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
<asset>
<contributor>
<author>Blender User</author>
<authoring_tool>Blender 2.78.0 commit date:2016-09-26, commit time:12:42, hash:4bb1e22</authoring_tool>
</contributor>
<created>2017-09-27T15:59:29</created>
<modified>2017-09-27T15:59:29</modified>
<unit name="meter" meter="1"/>
<up_axis>Z_UP</up_axis>
</asset>
<library_cameras>
<camera id="Camera-camera" name="Camera">
<optics>
<technique_common>
<perspective>
<xfov sid="xfov">49.13434</xfov>
<aspect_ratio>1.777778</aspect_ratio>
<znear sid="znear">0.1</znear>
<zfar sid="zfar">100</zfar>
</perspective>
</technique_common>
</optics>
<extra>
<technique profile="blender">
<YF_dofdist>0</YF_dofdist>
<shiftx>0</shiftx>
<shifty>0</shifty>
</technique>
</extra>
</camera>
</library_cameras>
<library_lights>
<light id="Lamp-light" name="Lamp">
<technique_common>
<point>
<color sid="color">1 1 1</color>
<constant_attenuation>1</constant_attenuation>
<linear_attenuation>0</linear_attenuation>
<quadratic_attenuation>0.00111109</quadratic_attenuation>
</point>
</technique_common>
<extra>
<technique profile="blender">
<adapt_thresh>0.000999987</adapt_thresh>
<area_shape>1</area_shape>
<area_size>0.1</area_size>
<area_sizey>0.1</area_sizey>
<area_sizez>1</area_sizez>
<atm_distance_factor>1</atm_distance_factor>
<atm_extinction_factor>1</atm_extinction_factor>
<atm_turbidity>2</atm_turbidity>
<att1>0</att1>
<att2>1</att2>
<backscattered_light>1</backscattered_light>
<bias>1</bias>
<blue>1</blue>
<buffers>1</buffers>
<bufflag>0</bufflag>
<bufsize>2880</bufsize>
<buftype>2</buftype>
<clipend>30.002</clipend>
<clipsta>1.000799</clipsta>
<compressthresh>0.04999995</compressthresh>
<dist sid="blender_dist">29.99998</dist>
<energy sid="blender_energy">1</energy>
<falloff_type>2</falloff_type>
<filtertype>0</filtertype>
<flag>0</flag>
<gamma sid="blender_gamma">1</gamma>
<green>1</green>
<halo_intensity sid="blnder_halo_intensity">1</halo_intensity>
<horizon_brightness>1</horizon_brightness>
<mode>8192</mode>
<ray_samp>1</ray_samp>
<ray_samp_method>1</ray_samp_method>
<ray_samp_type>0</ray_samp_type>
<ray_sampy>1</ray_sampy>
<ray_sampz>1</ray_sampz>
<red>1</red>
<samp>3</samp>
<shadhalostep>0</shadhalostep>
<shadow_b sid="blender_shadow_b">0</shadow_b>
<shadow_g sid="blender_shadow_g">0</shadow_g>
<shadow_r sid="blender_shadow_r">0</shadow_r>
<sky_colorspace>0</sky_colorspace>
<sky_exposure>1</sky_exposure>
<skyblendfac>1</skyblendfac>
<skyblendtype>1</skyblendtype>
<soft>3</soft>
<spotblend>0.15</spotblend>
<spotsize>75</spotsize>
<spread>1</spread>
<sun_brightness>1</sun_brightness>
<sun_effect_type>0</sun_effect_type>
<sun_intensity>1</sun_intensity>
<sun_size>1</sun_size>
<type>0</type>
</technique>
</extra>
</light>
</library_lights>
<library_images/>
<library_geometries>
<geometry id="Cube_001-mesh" name="Cube.001">
<mesh>
<source id="Cube_001-mesh-positions">
<float_array id="Cube_001-mesh-positions-array" count="0"/>
<technique_common>
<accessor source="#Cube_001-mesh-positions-array" count="0" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Cube_001-mesh-normals">
<float_array id="Cube_001-mesh-normals-array" count="0"/>
<technique_common>
<accessor source="#Cube_001-mesh-normals-array" count="0" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="Cube_001-mesh-vertices">
<input semantic="POSITION" source="#Cube_001-mesh-positions"/>
</vertices>
</mesh>
</geometry>
<geometry id="Cone-mesh" name="Cone">
<mesh>
<source id="Cone-mesh-positions">
<float_array id="Cone-mesh-positions-array" count="99">0 1 -1 0 0 1 0.1950903 0.9807853 -1 0.3826835 0.9238795 -1 0.5555703 0.8314696 -1 0.7071068 0.7071068 -1 0.8314697 0.5555702 -1 0.9238795 0.3826834 -1 0.9807853 0.1950903 -1 1 0 -1 0.9807853 -0.1950902 -1 0.9238796 -0.3826833 -1 0.8314697 -0.5555702 -1 0.7071068 -0.7071068 -1 0.5555702 -0.8314697 -1 0.3826833 -0.9238796 -1 0.1950901 -0.9807853 -1 -3.25841e-7 -1 -1 -0.1950907 -0.9807852 -1 -0.3826839 -0.9238793 -1 -0.5555707 -0.8314693 -1 -0.7071073 -0.7071064 -1 -0.83147 -0.5555697 -1 -0.9238799 -0.3826827 -1 -0.9807854 -0.1950894 -1 -1 9.65599e-7 -1 -0.9807851 0.1950913 -1 -0.9238791 0.3826845 -1 -0.8314689 0.5555713 -1 -0.7071059 0.7071077 -1 -0.5555691 0.8314704 -1 -0.3826821 0.9238801 -1 -0.1950888 0.9807856 -1</float_array>
<technique_common>
<accessor source="#Cone-mesh-positions-array" count="33" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Cone-mesh-normals">
<float_array id="Cone-mesh-normals-array" count="111">0.08775365 0.8909768 0.4454883 0.2598883 0.856737 0.4454884 0.4220357 0.7895733 0.4454885 0.5679646 0.6920667 0.4454883 0.6920668 0.5679646 0.4454883 0.7895735 0.4220356 0.4454884 0.856737 0.2598884 0.4454883 0.8909767 0.08775365 0.4454883 0.8909767 -0.08775341 0.4454883 0.856737 -0.2598884 0.4454884 0.7895734 -0.4220355 0.4454883 0.6920668 -0.5679646 0.4454883 0.5679646 -0.6920668 0.4454883 0.4220357 -0.7895733 0.4454883 0.2598879 -0.8567371 0.4454883 0.08775335 -0.8909768 0.4454884 -0.08775389 -0.8909767 0.4454883 -0.2598888 -0.8567368 0.4454884 -0.422036 -0.7895731 0.4454883 -0.5679649 -0.6920665 0.4454885 -0.6920673 -0.567964 0.4454882 -0.7895737 -0.4220352 0.4454885 -0.8567373 -0.2598874 0.4454883 -0.8909768 -0.08775281 0.4454883 -0.8909767 0.08775442 0.4454883 -0.8567367 0.2598893 0.4454884 -0.7895729 0.4220365 0.4454883 -0.6920661 0.5679656 0.4454883 -0.5679637 0.6920675 0.4454883 -0.4220346 0.7895739 0.4454883 -0.2598869 0.8567374 0.4454883 -0.08775299 0.8909768 0.4454884 0 0 -1 -3.97511e-6 0 -1 3.97512e-6 0 -1 3.88857e-7 0 -1 0 0 -1</float_array>
<technique_common>
<accessor source="#Cone-mesh-normals-array" count="37" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="Cone-mesh-vertices">
<input semantic="POSITION" source="#Cone-mesh-positions"/>
</vertices>
<polylist count="62">
<input semantic="VERTEX" source="#Cone-mesh-vertices" offset="0"/>
<input semantic="NORMAL" source="#Cone-mesh-normals" offset="1"/>
<vcount>3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 </vcount>
<p>0 0 1 0 2 0 2 1 1 1 3 1 3 2 1 2 4 2 4 3 1 3 5 3 5 4 1 4 6 4 6 5 1 5 7 5 7 6 1 6 8 6 8 7 1 7 9 7 9 8 1 8 10 8 10 9 1 9 11 9 11 10 1 10 12 10 12 11 1 11 13 11 13 12 1 12 14 12 14 13 1 13 15 13 15 14 1 14 16 14 16 15 1 15 17 15 17 16 1 16 18 16 18 17 1 17 19 17 19 18 1 18 20 18 20 19 1 19 21 19 21 20 1 20 22 20 22 21 1 21 23 21 23 22 1 22 24 22 24 23 1 23 25 23 25 24 1 24 26 24 26 25 1 25 27 25 27 26 1 26 28 26 28 27 1 27 29 27 29 28 1 28 30 28 30 29 1 29 31 29 31 30 1 30 32 30 32 31 1 31 0 31 16 32 24 32 8 32 32 32 0 32 2 32 2 32 3 32 4 32 4 32 5 32 6 32 6 32 7 32 4 32 8 32 9 32 10 32 10 32 11 32 8 32 12 32 13 32 16 32 14 32 15 32 16 32 16 32 17 32 18 32 18 32 19 32 20 32 20 32 21 32 22 32 22 32 23 32 24 32 24 33 25 33 26 33 26 34 27 34 28 34 28 32 29 32 32 32 30 32 31 32 32 32 32 32 2 32 8 32 4 32 7 32 8 32 8 32 11 32 12 32 13 32 14 32 16 32 16 32 18 32 24 32 20 32 22 32 24 32 24 35 26 35 32 35 29 32 30 32 32 32 2 32 4 32 8 32 8 32 12 32 16 32 18 32 20 32 24 32 26 32 28 32 32 32 32 36 8 36 24 36</p>
</polylist>
</mesh>
</geometry>
</library_geometries>
<library_controllers/>
<library_visual_scenes>
<visual_scene id="Scene" name="Scene">
<node id="Camera" name="Camera" type="NODE">
<matrix sid="transform">0.6859207 -0.3240135 0.6515582 7.481132 0.7276763 0.3054208 -0.6141704 -6.50764 0 0.8953956 0.4452714 5.343665 0 0 0 1</matrix>
<instance_camera url="#Camera-camera"/>
</node>
<node id="Lamp" name="Lamp" type="NODE">
<matrix sid="transform">-0.2908646 -0.7711008 0.5663932 4.076245 0.9551712 -0.1998834 0.2183912 1.005454 -0.05518906 0.6045247 0.7946723 5.903862 0 0 0 1</matrix>
<instance_light url="#Lamp-light"/>
</node>
<node id="Cube" name="Cube" type="NODE">
<matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</matrix>
<instance_geometry url="#Cube_001-mesh" name="Cube"/>
</node>
<node id="Cone" name="Cone" type="NODE">
<matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 1.015816 0 0 0 1</matrix>
<instance_geometry url="#Cone-mesh" name="Cone"/>
</node>
</visual_scene>
</library_visual_scenes>
<scene>
<instance_visual_scene url="#Scene"/>
</scene>
</COLLADA>