Merge remote-tracking branch 'origin/master' into story_61

# Conflicts:
#	racevisionGame/src/main/java/mock/model/MockRace.java
#	racevisionGame/src/main/java/mock/model/commandFactory/CommandFactory.java
#	racevisionGame/src/main/java/visualiser/gameController/ControllerClient.java
#	racevisionGame/src/main/java/visualiser/gameController/ControllerServer.java
#	racevisionGame/src/main/resources/visualiser/scenes/race.fxml
This commit is contained in:
fjc40
2017-08-15 14:49:58 +12:00
18 changed files with 1554 additions and 59 deletions
@@ -7,8 +7,6 @@ import visualiser.gameController.Keys.KeyFactory;
import java.util.HashMap;
import static javafx.application.Application.launch;
/**
* Class for checking what keys are currently being used
*/
@@ -28,7 +26,7 @@ public class InputChecker {
ControlKey controlKey = keyFactory.getKey(codeString);
if (controlKey != null) {
controlKey.onAction();
System.out.println(controlKey.toString() + " is Pressed.");
// System.out.println(controlKey.toString() + " is Pressed.");
}
currentlyActiveKeys.put(codeString, true);
}
@@ -39,7 +37,7 @@ public class InputChecker {
ControlKey controlKey = keyFactory.getKey(codeString);
if (controlKey != null) {
controlKey.onRelease();
System.out.println(controlKey.toString() + " is Released.");
// System.out.println(controlKey.toString() + " is Released.");
}
currentlyActiveKeys.remove(event.getCode().toString());
});
@@ -51,7 +49,7 @@ public class InputChecker {
ControlKey controlKey = keyFactory.getKey(key);
if (controlKey != null){
controlKey.onHold();
System.out.println(controlKey.toString() + " is Held.");
// System.out.println(controlKey.toString() + " is Held.");
}
}
// for (String key : InputKeys.stringKeysMap.keySet()){
@@ -40,6 +40,7 @@ public class Annotations {
private static String pathCheckAnno = "showBoatPath";
private static String timeCheckAnno = "showTime";
private static String estTimeCheckAnno = "showEstTime";
private static String guideLineAnno = "showGuideline";
// string values match the fx:id value of radio buttons
private static String noBtn = "noBtn";
@@ -160,6 +161,16 @@ public class Annotations {
raceMap.draw();
}
});
//listener to show estimated time for annotation
checkBoxes.get(guideLineAnno).selectedProperty()
.addListener((ov, old_val, new_val) -> {
if (old_val != new_val) {
raceMap.toggleGuideLine();
storeCurrentAnnotationState(guideLineAnno, new_val);
raceMap.draw();
}
});
}
/**
@@ -6,9 +6,8 @@ import javafx.scene.paint.Paint;
import javafx.scene.transform.Rotate;
import network.Messages.Enums.BoatStatusEnum;
import shared.dataInput.RaceDataSource;
import shared.model.GPSCoordinate;
import shared.model.Mark;
import shared.model.RaceClock;
import shared.enums.RoundingType;
import shared.model.*;
import java.util.ArrayList;
import java.util.List;
@@ -44,6 +43,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
private boolean annoPath = true;
private boolean annoEstTime = true;
private boolean annoTimeSinceLastMark = true;
private boolean annoGuideLine = false;
@@ -111,6 +111,13 @@ public class ResizableRaceCanvas extends ResizableCanvas {
annoSpeed = !annoSpeed;
}
/**
* Toggle the guideline annotation
*/
public void toggleGuideLine() {
annoGuideLine = !annoGuideLine;
}
@@ -497,6 +504,11 @@ public class ResizableRaceCanvas extends ResizableCanvas {
//Race boundary.
drawBoundary();
//Guiding Line
if (annoGuideLine){
drawRaceLine();
}
//Boats.
drawBoats();
@@ -505,6 +517,139 @@ public class ResizableRaceCanvas extends ResizableCanvas {
}
/**
* draws a transparent line around the course that shows the paths boats must travel
*/
public void drawRaceLine(){
List<Leg> legs = this.visualiserRace.getLegs();
GPSCoordinate legStartPoint = legs.get(0).getStartCompoundMark().getAverageGPSCoordinate();
GPSCoordinate nextStartPoint;
for (int i = 0; i < legs.size() -1; i++) {
nextStartPoint = drawLineRounding(legs, i, legStartPoint);
legStartPoint = nextStartPoint;
}
}
/**
* Draws a line around a course that shows where boats need to go. This method
* draws the line leg by leg
* @param legs the legs of a race
* @param index the index of the current leg to use
* @return the end point of the current leg that has been drawn
*/
private GPSCoordinate drawLineRounding(List<Leg> legs, int index, GPSCoordinate legStartPoint){
GPSCoordinate startDirectionLinePoint;
GPSCoordinate endDirectionLinePoint;
Bearing bearingOfDirectionLine;
GPSCoordinate startNextDirectionLinePoint;
GPSCoordinate endNextDirectionLinePoint;
Bearing bearingOfNextDirectionLine;
//finds the direction of the current leg as a bearing
startDirectionLinePoint = legStartPoint;
GPSCoordinate tempEndDirectionLinePoint = legs.get(index).getEndCompoundMark().getAverageGPSCoordinate();
bearingOfDirectionLine = GPSCoordinate.calculateBearing(startDirectionLinePoint, tempEndDirectionLinePoint);
//after finding the initial bearing pick the mark used for rounding
endDirectionLinePoint = legs.get(index).getEndCompoundMark().getMarkForRounding(bearingOfDirectionLine).getPosition();
bearingOfDirectionLine = GPSCoordinate.calculateBearing(startDirectionLinePoint, endDirectionLinePoint);
//finds the direction of the next leg as a bearing
if (index < legs.size() -2){ // not last leg
startNextDirectionLinePoint = legs.get(index + 1).getStartCompoundMark().getMark1Position();
endNextDirectionLinePoint = legs.get(index + 1).getEndCompoundMark().getMark1Position();
bearingOfNextDirectionLine = GPSCoordinate.calculateBearing(startNextDirectionLinePoint, endNextDirectionLinePoint);
double degreesToAdd;
//find which side is need to be used
if (legs.get(index).getEndCompoundMark().getRoundingType() == RoundingType.Port ||
legs.get(index).getEndCompoundMark().getRoundingType() == RoundingType.SP){
degreesToAdd = 90;
}else{
degreesToAdd = -90;
}
//use the direction line to find a point parallel to it by the mark
GPSCoordinate pointToStartCurve = GPSCoordinate.calculateNewPosition(endDirectionLinePoint,
100, Azimuth.fromDegrees(bearingOfDirectionLine.degrees()+degreesToAdd));
//use the direction line to find a point to curve too
GPSCoordinate pointToEndCurve = GPSCoordinate.calculateNewPosition(endDirectionLinePoint,
100, Azimuth.fromDegrees(bearingOfNextDirectionLine.degrees()+degreesToAdd));
//use the curve points to find the two control points for the bezier curve
GPSCoordinate controlPoint;
GPSCoordinate controlPoint2;
Bearing bearingOfCurveLine = GPSCoordinate.calculateBearing(pointToStartCurve, pointToEndCurve);
if ((bearingOfDirectionLine.degrees() - bearingOfNextDirectionLine.degrees() +360)%360< 145){
//small turn
controlPoint = GPSCoordinate.calculateNewPosition(pointToStartCurve,
50, Azimuth.fromDegrees(bearingOfCurveLine.degrees()+(degreesToAdd/2)));
controlPoint2 = controlPoint;
}else{
//large turn
controlPoint = GPSCoordinate.calculateNewPosition(pointToStartCurve,
150, Azimuth.fromDegrees(bearingOfCurveLine.degrees()+degreesToAdd));
controlPoint2 = GPSCoordinate.calculateNewPosition(pointToEndCurve,
150, Azimuth.fromDegrees(bearingOfCurveLine.degrees()+degreesToAdd));
}
//change all gps into graph coordinate
GraphCoordinate startPath = this.map.convertGPS(startDirectionLinePoint);
GraphCoordinate curvePoint = this.map.convertGPS(pointToStartCurve);
GraphCoordinate curvePointEnd = this.map.convertGPS(pointToEndCurve);
GraphCoordinate c1 = this.map.convertGPS(controlPoint);
GraphCoordinate c2 = this.map.convertGPS(controlPoint2);
gc.setLineWidth(2);
gc.setStroke(Color.MEDIUMAQUAMARINE);
gc.beginPath();
gc.moveTo(startPath.getX(), startPath.getY());
gc.lineTo(curvePoint.getX(), curvePoint.getY());
drawArrowHead(startDirectionLinePoint, pointToStartCurve);
gc.bezierCurveTo(c1.getX(), c1.getY(), c2.getX(), c2.getY(), curvePointEnd.getX(), curvePointEnd.getY());
gc.stroke();
gc.closePath();
gc.save();
return pointToEndCurve;
}else{//last leg so no curve
GraphCoordinate startPath = this.map.convertGPS(legStartPoint);
GraphCoordinate endPath = this.map.convertGPS(legs.get(index).getEndCompoundMark().getAverageGPSCoordinate());
gc.beginPath();
gc.moveTo(startPath.getX(), startPath.getY());
gc.lineTo(endPath.getX(), endPath.getY());
gc.stroke();
gc.closePath();
gc.save();
drawArrowHead(legStartPoint, legs.get(index).getEndCompoundMark().getAverageGPSCoordinate());
return null;
}
}
private void drawArrowHead(GPSCoordinate start, GPSCoordinate end){
GraphCoordinate lineStart = this.map.convertGPS(start);
GraphCoordinate lineEnd = this.map.convertGPS(end);
double arrowAngle = Math.toRadians(45.0);
double arrowLength = 10.0;
double dx = lineStart.getX() - lineEnd.getX();
double dy = lineStart.getY() - lineEnd.getY();
double angle = Math.atan2(dy, dx);
double x1 = Math.cos(angle + arrowAngle) * arrowLength + lineEnd.getX();
double y1 = Math.sin(angle + arrowAngle) * arrowLength + lineEnd.getY();
double x2 = Math.cos(angle - arrowAngle) * arrowLength + lineEnd.getX();
double y2 = Math.sin(angle - arrowAngle) * arrowLength + lineEnd.getY();
gc.strokeLine(lineEnd.getX(), lineEnd.getY(), x1, y1);
gc.strokeLine(lineEnd.getX(), lineEnd.getY(), x2, y2);
}
@@ -516,7 +661,6 @@ public class ResizableRaceCanvas extends ResizableCanvas {
* @see TrackPoint
*/
private void drawTrack(VisualiserBoat boat) {
//Check that track points are enabled.
if (this.annoPath) {