Merge remote-tracking branch 'origin/story9' into story9

# Conflicts:
#	src/main/java/seng302/Constants.java
#	src/main/java/seng302/Model/Race.java
#	src/main/java/seng302/Model/ResizableRaceCanvas.java
This commit is contained in:
David Wu
2017-03-23 18:20:25 +13:00
13 changed files with 642 additions and 103 deletions
+6 -6
View File
@@ -25,12 +25,12 @@ public class Constants {
public static final GPSCoordinate finishLineMarker2 = new GPSCoordinate(32.317257, -64.836260);
public static final BoatInRace[] OFFICIAL_AC35_COMPETITORS = new BoatInRace[]
{new BoatInRace("Oracle Team USA", 700.0, Color.BLUEVIOLET, "USA"),
new BoatInRace("Land Rover BAR", 680.0, Color.BLACK, "BAR"),
new BoatInRace("SoftBank Team Japan", 690.0, Color.RED, "JAP"),
new BoatInRace("Groupama Team France", 710.0, Color.ORANGE, "FRN"),
new BoatInRace("Artemis Racing", 720.0, Color.DARKOLIVEGREEN, "ART"),
new BoatInRace("Emirates Team New Zealand", 810, Color.LIMEGREEN, "ENZ")};
{new BoatInRace("Oracle Team USA", 300.0, Color.BLUEVIOLET, "USA"),
new BoatInRace("Land Rover BAR", 500.0, Color.BLACK, "BAR"),
new BoatInRace("SoftBank Team Japan", 400.0, Color.RED, "JAP"),
new BoatInRace("Groupama Team France", 350.0, Color.ORANGE, "FRN"),
new BoatInRace("Artemis Racing", 440.0, Color.DARKOLIVEGREEN, "ART"),
new BoatInRace("Emirates Team New Zealand", 620, Color.LIMEGREEN, "ENZ")};
//public static final Leg bermudaCourseStartToMark1 = new Leg(0, , new )
}
+1 -1
View File
@@ -53,7 +53,7 @@ public class Boat {
* @return The Name of the boat.
*/
public String toString(){
return getName().getValue();
return getName().toString();
}
public StringProperty getVelocityProp() {
+25 -5
View File
@@ -132,19 +132,39 @@ public class BoatInRace extends Boat {
this.finished = bool;
}
/**
* Calculates the bearing of the travel via map coordinates of the raceMarkers
* @return the heading that the boat is heading towards in degrees.
* Calculates the azimuth of the travel via map coordinates of the raceMarkers
* @return the direction that the boat is heading towards in degrees (-180 to 180).
*/
public double calculateAzimuth(){
//to be changed to coordinates when used to match reality.
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLongitude(), currentLeg.getStartGraphCoordinate().getLatitude());
calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLongitude(), currentLeg.getEndGraphCoordinate().getLatitude());
return calc.getAzimuth();
}
/**
* Converts an azimuth to a bearing
* @param azimuth azimuth valuye to be converted
* @return the bearings in degrees (0 to 360).
*/
public static double calculateHeading(double azimuth) {
if (azimuth >= 0) {
return azimuth;
}
else {
return azimuth + 360;
}
}
/**
* Calculates the bearing of the travel via map coordinates of the raceMarkers
* @return the direction that the boat is heading towards in degrees (0 to 360).
*/
public double calculateHeading(){
double azimuth = this.calculateAzimuth();
return calculateHeading(azimuth);
}
}
@@ -13,6 +13,7 @@ import java.util.ArrayList;
* Created by cbt24 on 6/03/17.
*/
public class ConstantVelocityRace extends Race {
/**
* Initialiser for a Race with constant velocity.
* @param startingBoats array of boats
@@ -35,13 +36,13 @@ public class ConstantVelocityRace extends Race {
double distanceTravelled = boat.getVelocity() * millisecondsElapsed/3600000;
double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
if (!boat.getCurrentLeg().getName().equals("Finish")) {
boolean finish = boat.getCurrentLeg().getName().equals("Finish");
if (!finish) {
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartGraphCoordinate(),
totalDistanceTravelled, boat.calculateAzimuth()));
}
}
/**
+1 -9
View File
@@ -55,15 +55,6 @@ public class Leg {
return distance;
}
/**
*
* @return Returns the name of the Leg
*/
public String toString() {
return name;
}
/**
* Returns the coordinates in GPSCoordinate class of the boats starting coordinate.
* @return Returns the coordinate of the start of the leg.
@@ -101,5 +92,6 @@ public class Leg {
calc.setStartingGeographicPoint(startGPSCoordinate.getLongitude(), startGPSCoordinate.getLatitude());
calc.setDestinationGeographicPoint(endGPSCoordinate.getLongitude(), endGPSCoordinate.getLatitude());
return calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
}
}
+10 -6
View File
@@ -25,8 +25,8 @@ public abstract class Race implements Runnable {
protected long totalTimeElapsed;
private int SLEEP_TIME = 25; //time in milliseconds to pause in a paced loop
private int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
protected int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race
private boolean timerEnabled = true;
/**
@@ -86,7 +86,7 @@ public abstract class Race implements Runnable {
/**
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
*/
private void countdownTimer() {
protected void countdownTimer() {
long currentTime = System.currentTimeMillis();
long startTime = currentTime + PRERACE_TIME;
long minutes;
@@ -103,7 +103,9 @@ public abstract class Race implements Runnable {
remainingSeconds = currentTimeInSeconds % 60;
hours = minutes / 60;
minutes = minutes % 60;
updateTime(String.format("Time until race starts: %02d:%02d:%02d", hours, minutes, remainingSeconds));
if (controller != null) {
updateTime(String.format("Time until race starts: %02d:%02d:%02d", hours, minutes, remainingSeconds));
}
try {
timeLoopEnded = System.currentTimeMillis();
Thread.sleep(SLEEP_TIME - (timeLoopEnded - currentTime));
@@ -118,7 +120,7 @@ public abstract class Race implements Runnable {
* Takes total time elapsed and format to hour:minute:second
* @return Formatted time as string
*/
private String calcTimer() {
protected String calcTimer() {
long minutes;
long currentTimeInSeconds;
long remainingSeconds;
@@ -136,7 +138,7 @@ public abstract class Race implements Runnable {
* Updates the calculated time to the timer label
* @param time The calculated time from calcTimer() method
*/
private void updateTime(String time){
protected void updateTime(String time){
Platform.runLater(() -> {controller.setTimer(time);});
}
@@ -209,11 +211,13 @@ public abstract class Race implements Runnable {
*/
protected void checkPosition(BoatInRace boat, long timeElapsed) {
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
// updateController();
//boat has passed onto new leg
if (boat.getCurrentLeg().getName().equals("Finish")) {
//boat has finished
boatsFinished++;
boat.setFinished(true);
boat.setTimeFinished(timeElapsed);
} else {
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
@@ -1,6 +1,6 @@
package seng302.Model;
import com.sun.xml.internal.bind.v2.runtime.reflect.opt.Const;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
@@ -25,8 +25,6 @@ public class ResizableRaceCanvas extends Canvas {
private GraphicsContext gc;
private RaceMap map;
private BoatInRace[] boats;
private Graphics graphics;
private Font font;
/**
* Sets the boats that are to be displayed in this race.
@@ -154,51 +152,50 @@ public class ResizableRaceCanvas extends Canvas {
*/
public void drawRaceMap() {
double width = getWidth();
double height = getHeight();
gc.clearRect(0, 0, width, height);
//System.out.println("Race Map Canvas Width: "+ width + ", Height:" + height);
this.map = new RaceMap(32.278, -64.863, 32.320989, -64.821, (int)width, (int)height);
if (map == null){
return;
}
//finish line
gc.setLineWidth(2);
GraphCoordinate finishLineCoord1 = this.map.convertGPS(Constants.finishLineMarker1);
GraphCoordinate finishLineCoord2 = this.map.convertGPS(Constants.finishLineMarker2);
displayLine(finishLineCoord1, finishLineCoord2, Color.DARKRED);
//marks
GraphCoordinate markCoord = this.map.convertGPS(Constants.mark1);
GraphCoordinate windwardGate1 = this.map.convertGPS(Constants.windwardGate1);
GraphCoordinate windwardGate2 = this.map.convertGPS(Constants.windwardGate2);
GraphCoordinate leewardGate1 = this.map.convertGPS(Constants.leewardGate1);
GraphCoordinate leewardGate2 = this.map.convertGPS(Constants.leewardGate2);
displayMark(markCoord, Color.GOLD);
displayLine(windwardGate1, windwardGate2, Color.DARKCYAN);
displayLine(leewardGate1, leewardGate2, Color.DARKVIOLET);
//start line
GraphCoordinate startline1 = this.map.convertGPS(Constants.startLineMarker1);
GraphCoordinate startline2 = this.map.convertGPS(Constants.startLineMarker2);
displayLine(startline1, startline2, Color.GREEN);
double width = getWidth();
double height = getHeight();
gc.clearRect(0, 0, width, height);
//System.out.println("Race Map Canvas Width: "+ width + ", Height:" + height);
this.map = new RaceMap(32.278, -64.863, 32.320989, -64.821, (int)width, (int)height);
if (map == null){
return;
}
//finish line
gc.setLineWidth(2);
GraphCoordinate finishLineCoord1 = this.map.convertGPS(Constants.finishLineMarker1);
GraphCoordinate finishLineCoord2 = this.map.convertGPS(Constants.finishLineMarker2);
displayLine(finishLineCoord1, finishLineCoord2, Color.DARKRED);
//marks
GraphCoordinate markCoord = this.map.convertGPS(Constants.mark1);
GraphCoordinate windwardGate1 = this.map.convertGPS(Constants.windwardGate1);
GraphCoordinate windwardGate2 = this.map.convertGPS(Constants.windwardGate2);
GraphCoordinate leewardGate1 = this.map.convertGPS(Constants.leewardGate1);
GraphCoordinate leewardGate2 = this.map.convertGPS(Constants.leewardGate2);
displayMark(markCoord, Color.GOLD);
displayLine(windwardGate1, windwardGate2, Color.DARKCYAN);
displayLine(leewardGate1, leewardGate2, Color.DARKVIOLET);
//start line
GraphCoordinate startline1 = this.map.convertGPS(Constants.startLineMarker1);
GraphCoordinate startline2 = this.map.convertGPS(Constants.startLineMarker2);
displayLine(startline1, startline2, Color.GREEN);
if (boats != null) {
for (BoatInRace boat : boats) {
if (boat != null) {
// System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour());
displayText(boat.getName().getValue(), boat.getVelocity()* 1.94384, this.map.convertGPS(boat.getCurrentPosition()));
}
if (boats != null) {
for (BoatInRace boat : boats) {
if (boat != null) {
// System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour());
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
}
}
}
//display wind direction arrow - specify origin point and angle
displayArrow(new GraphCoordinate(500, 20), 100);
//display wind direction arrow - specify origin point and angle
displayArrow(new GraphCoordinate(500, 20), 100);
}
/**
+182
View File
@@ -0,0 +1,182 @@
<race>
<boats>
<boat>
<name>ORACLE TEAM USA</name>
<speed>300</speed>
<abbr>USA</abbr>
<colour>BLUEVIOLET</colour>
</boat>
<boat>
<name>Land Rover BAR</name>
<speed>500</speed>
<abbr>BAR</abbr>
<colour>BLACK</colour>
</boat>
<boat>
<name>SoftBank Team Japan</name>
<speed>400</speed>
<abbr>JAP</abbr>
<colour>RED</colour>
</boat>
<boat>
<name>Groupama Team France</name>
<speed>350</speed>
<abbr>FRN</abbr>
<colour>ORANGE</colour>
</boat>
<boat>
<name>Artemis Racing</name>
<speed>440</speed>
<abbr>ART</abbr>
<colour>DARKOLIVEGREEN</colour>
</boat>
<boat>
<name>Emirates Team New Zealand</name>
<speed>620</speed>
<abbr>ENZ</abbr>
<colour>LIMEGREEN</colour>
</boat>
</boats>
<legs>
<leg>
<name>Start to Mark 1</name>
<start>
<coordinate>
<latitude>32.296577</latitude>
<longitude>-64.854304</longitude>
</coordinate>
</start>
<finish>
<coordinate>
<latitude>32.293039</latitude>
<longitude>-64.843983</longitude>
</coordinate>
</finish>
</leg>
<leg>
<name>Mark 1 to Leeward Gate</name>
<start>
<coordinate>
<latitude>32.293039</latitude>
<longitude>-64.843983</longitude>
</coordinate>
</start>
<finish>
<coordinate>
<latitude>32.309693</latitude>
<longitude>-64.835249</longitude>
</coordinate>
</finish>
</leg>
<leg>
<name>Leeward Gate to Windward Gate</name>
<start>
<coordinate>
<latitude>32.309693</latitude>
<longitude>-64.835249</longitude>
</coordinate>
</start>
<finish>
<coordinate>
<latitude>32.284680</latitude>
<longitude>-64.850045</longitude>
</coordinate>
</finish>
</leg>
<leg>
<name>Windward Gate to Leeward Gate</name>
<start>
<coordinate>
<coordinate>
<latitude>32.284680</latitude>
<longitude>-64.850045</longitude>
</coordinate>
</coordinate>
</start>
<finish>
<coordinate>
<latitude>32.309693</latitude>
<longitude>-64.835249</longitude>
</coordinate>
</finish>
</leg>
<leg>
<name>Leeward Gate to Finish</name>
<start>
<coordinate>
<latitude>32.309693</latitude>
<longitude>-64.835249</longitude>
</coordinate>
</start>
<finish>
<coordinate>
<latitude>32.317379</latitude>
<longitude>-64.839291</longitude>
</coordinate>
</finish>
</leg>
</legs>
<course>
<boundaries>
<coordinate>
<latitude>32.278</latitude>
<longitude>-64.863</longitude>
</coordinate>
<coordinate>
<latitude>32.30989</latitude>
<longitude>-64.821</longitude>
</coordinate>
</boundaries>
<marker>
<name>Start Line</name>
<coordinate>
<latitude>32.296577</latitude>
<longitude>-64.854304</longitude>
</coordinate>
<coordinate>
<latitude>32.293771</latitude>
<longitude>-64.855242</longitude>
</coordinate>
</marker>
<marker>
<name>Mark</name>
<coordinate>
<latitude>32.293039</latitude>
<longitude>-64.843983</longitude>
</coordinate>
</marker>
<marker>
<name>Windward Gate</name>
<coordinate>
<latitude>32.284680</latitude>
<longitude>-64.850045</longitude>
</coordinate>
<coordinate>
<latitude>32.280164</latitude>
<longitude>-64.847591</longitude>
</coordinate>
</marker>
<marker>
<name>Leeward Gate</name>
<coordinate>
<latitude>32.309693</latitude>
<longitude>-64.835249</longitude>
</coordinate>
<coordinate>
<latitude>32.308046</latitude>
<longitude>-64.831785</longitude>
</coordinate>
</marker>
<marker>
<name>Finish Line</name>
<coordinate>
<latitude>32.317379</latitude>
<longitude>-64.839291</longitude>
</coordinate>
<coordinate>
<latitude>32.317257</latitude>
<longitude>-64.836260</longitude>
</coordinate>
</marker>
</course>
</race>