Implemented wake visualisation for each boat

- Added and tested wake calculation for BoatInRace
- Draws boat in canvas between start and entering Finish leg
- Allow boat velocity to be set after initialisation for testing
#story [21]
This commit is contained in:
Connor Taylor-Brown
2017-03-25 20:41:16 +13:00
parent f8147be4df
commit e8cd9b2ee8
5 changed files with 72 additions and 14 deletions
@@ -66,6 +66,7 @@ public class RaceController extends Controller{
BoatInRace[] boatInRaces = new BoatInRace[boats.size()];
raceMap.setBoats(boats.toArray(boatInRaces));
raceMap.drawRaceMap();
raceMap.updateBoats();
}
/**
+4
View File
@@ -48,6 +48,10 @@ public class Boat {
return velocity;
}
public void setVelocity(double velocity) {
this.velocity = velocity;
}
/**
*
* @return The Name of the boat.
+15 -1
View File
@@ -6,6 +6,7 @@ import javafx.scene.paint.Color;
import org.geotools.referencing.GeodeticCalculator;
import seng302.GPSCoordinate;
import java.awt.geom.Point2D;
/**
@@ -147,7 +148,7 @@ public class BoatInRace extends Boat {
/**
* Converts an azimuth to a bearing
* @param azimuth azimuth valuye to be converted
* @param azimuth azimuth value to be converted
* @return the bearings in degrees (0 to 360).
*/
public static double calculateHeading(double azimuth) {
@@ -167,4 +168,17 @@ public class BoatInRace extends Boat {
double azimuth = this.calculateAzimuth();
return calculateHeading(azimuth);
}
public GPSCoordinate getWake() {
double reverseHeading = calculateHeading() - 180;
double distance = getVelocity();
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(
new Point2D.Double(getCurrentPosition().getLongitude(), getCurrentPosition().getLatitude())
);
calc.setDirection(reverseHeading, distance);
Point2D endpoint = calc.getDestinationGeographicPoint();
return new GPSCoordinate(endpoint.getY(), endpoint.getX());
}
}
@@ -66,8 +66,9 @@ public class ResizableRaceCanvas extends Canvas {
* @see Paint
*/
public void displayMark(GraphCoordinate graphCoordinate, Paint paint){
double d = 15;
gc.setFill(paint);
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 15, 15);
gc.fillOval(graphCoordinate.getX() - (d/2), graphCoordinate.getY() - (d/2), d, d);
}
/**
@@ -187,7 +188,6 @@ public class ResizableRaceCanvas extends Canvas {
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()));
}
@@ -198,17 +198,16 @@ public class ResizableRaceCanvas extends Canvas {
displayArrow(new GraphCoordinate(500, 20), 100);
}
/**
* Draws a boat at a certain GPSCoordinate
* @param colour Colour to colour boat.
* @param gpsCoordinates GPScoordinate that the boat is to be drawn at.
* @see GPSCoordinate
* @see Color
*/
public void drawBoat(Color colour, GPSCoordinate gpsCoordinates) {
GraphCoordinate graphCoordinate = this.map.convertGPS(gpsCoordinates);
//System.out.println("DrawingBoat" + gpsCoordinates.getLongitude());
displayPoint(graphCoordinate, colour);
public void updateBoats() {
if (boats != null) {
for (BoatInRace boat : boats) {
if (boat != null && !boat.getCurrentLeg().getName().equals("Finish")) {
GraphCoordinate wakeFrom = this.map.convertGPS(boat.getCurrentPosition());
GraphCoordinate wakeTo = this.map.convertGPS(boat.getWake());
displayLine(wakeFrom, wakeTo, boat.getColour());
}
}
}
}
/**