|
|
|
@ -4,8 +4,11 @@ package seng302.Model;
|
|
|
|
import javafx.application.Platform;
|
|
|
|
import javafx.application.Platform;
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
|
|
|
|
import org.geotools.referencing.GeodeticCalculator;
|
|
|
|
import seng302.Controllers.RaceController;
|
|
|
|
import seng302.Controllers.RaceController;
|
|
|
|
|
|
|
|
import seng302.GPSCoordinate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.awt.geom.Point2D;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -33,21 +36,32 @@ public abstract class Race implements Runnable {
|
|
|
|
* @param legs Number of marks in order that the boats pass in order to complete the race.
|
|
|
|
* @param legs Number of marks in order that the boats pass in order to complete the race.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller, int scaleFactor) {
|
|
|
|
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller, int scaleFactor) {
|
|
|
|
if (boats.length > 0) {
|
|
|
|
|
|
|
|
for (BoatInRace boat : boats) {
|
|
|
|
|
|
|
|
if (boat != null) {
|
|
|
|
|
|
|
|
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.startingBoats = FXCollections.observableArrayList(boats);
|
|
|
|
this.startingBoats = FXCollections.observableArrayList(boats);
|
|
|
|
this.legs = legs;
|
|
|
|
this.legs = legs;
|
|
|
|
this.legs.add(new Leg("Finish", this.legs.size()));
|
|
|
|
this.legs.add(new Leg("Finish", this.legs.size()));
|
|
|
|
this.controller = controller;
|
|
|
|
this.controller = controller;
|
|
|
|
this.scaleFactor = scaleFactor;
|
|
|
|
this.scaleFactor = scaleFactor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initialiseBoats();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initialiseBoats() {
|
|
|
|
|
|
|
|
Leg startLeg = legs.get(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (startingBoats.size() > 0) {
|
|
|
|
|
|
|
|
for (BoatInRace boat : startingBoats) {
|
|
|
|
|
|
|
|
if (boat != null) {
|
|
|
|
|
|
|
|
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boat.setCurrentLeg(startLeg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Constructor for Race class
|
|
|
|
* Constructor for Race class
|
|
|
|
*
|
|
|
|
*
|
|
|
|
@ -89,6 +103,8 @@ public abstract class Race implements Runnable {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void preRace() {
|
|
|
|
private void preRace() {
|
|
|
|
//show the boats participating.
|
|
|
|
//show the boats participating.
|
|
|
|
|
|
|
|
ArrayList<GPSCoordinate> startPositons = getSpreadStartingPositions();
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < startingBoats.size(); i++) {
|
|
|
|
for (int i = 0; i < startingBoats.size(); i++) {
|
|
|
|
if (startingBoats.get(i) != null) {
|
|
|
|
if (startingBoats.get(i) != null) {
|
|
|
|
startingBoats.get(i).setCurrentLeg(legs.get(0));
|
|
|
|
startingBoats.get(i).setCurrentLeg(legs.get(0));
|
|
|
|
@ -252,4 +268,35 @@ public abstract class Race implements Runnable {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected abstract void updatePosition(BoatInRace boat, int millisecondsElapsed);
|
|
|
|
protected abstract void updatePosition(BoatInRace boat, int millisecondsElapsed);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Creates a list of starting positions for the different boats, so they do not appear cramped at the start line
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public ArrayList<GPSCoordinate> getSpreadStartingPositions() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int nBoats = startingBoats.size();
|
|
|
|
|
|
|
|
GPSCoordinate marker1 = legs.get(0).getStartMarker1();
|
|
|
|
|
|
|
|
GPSCoordinate marker2 = legs.get(0).getStartMarker2();
|
|
|
|
|
|
|
|
GeodeticCalculator initialCalc = new GeodeticCalculator();
|
|
|
|
|
|
|
|
initialCalc.setStartingGeographicPoint(marker1.getLongitude(), marker1.getLatitude());
|
|
|
|
|
|
|
|
initialCalc.setDestinationGeographicPoint(marker2.getLongitude(), marker2.getLatitude());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double azimuth = initialCalc.getAzimuth();
|
|
|
|
|
|
|
|
double distanceBetweenMarkers = initialCalc.getOrthodromicDistance();
|
|
|
|
|
|
|
|
double distanceBetweenBoats = distanceBetweenMarkers / (nBoats + 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GeodeticCalculator positionCalc = new GeodeticCalculator();
|
|
|
|
|
|
|
|
positionCalc.setStartingGeographicPoint(marker1.getLongitude(), marker1.getLatitude());
|
|
|
|
|
|
|
|
ArrayList<GPSCoordinate> positions = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nBoats; i++) {
|
|
|
|
|
|
|
|
positionCalc.setDirection(azimuth, distanceBetweenBoats);
|
|
|
|
|
|
|
|
Point2D position = positionCalc.getDestinationGeographicPoint();
|
|
|
|
|
|
|
|
positions.add(new GPSCoordinate(position.getY(), position.getX()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
positionCalc = new GeodeticCalculator();
|
|
|
|
|
|
|
|
positionCalc.setStartingGeographicPoint(position);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return positions;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|