|
|
|
|
@ -53,39 +53,26 @@ public abstract class Race implements Runnable {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
// * Constructor for Race class
|
|
|
|
|
// * @param boats boats participating in the race.
|
|
|
|
|
// * @param legs legs that there are in the race.
|
|
|
|
|
// */
|
|
|
|
|
// public Race(BoatInRace[] boats, ArrayList<Leg> legs, int scaleFactor) {
|
|
|
|
|
// if (boats.length > 0) {
|
|
|
|
|
// for (BoatInRace boat : boats) {
|
|
|
|
|
// if (boat != null) {
|
|
|
|
|
// boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// this.startingBoats = FXCollections.observableArrayList(boats);
|
|
|
|
|
// this.legs = legs;
|
|
|
|
|
// this.legs.add(new Leg("Finish", this.legs.size()));
|
|
|
|
|
// this.scaleFactor = scaleFactor;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void initialiseBoats() {
|
|
|
|
|
|
|
|
|
|
// Leg startLeg = legs.get(0);
|
|
|
|
|
// Leg copyLeg = startLeg.createCopy();
|
|
|
|
|
|
|
|
|
|
//ArrayList<GPSCoordinate> startPositions = getSpreadStartingPositions();
|
|
|
|
|
|
|
|
|
|
public void initialiseBoats() {
|
|
|
|
|
|
|
|
|
|
Leg officialStart = legs.get(0);
|
|
|
|
|
String name = officialStart.getName();
|
|
|
|
|
Marker endMarker = officialStart.getEndMarker();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ArrayList<Marker> startMarkers = getSpreadStartingPositions();
|
|
|
|
|
for (int i = 0; i < startingBoats.size(); i++) {
|
|
|
|
|
BoatInRace boat = startingBoats.get(i);
|
|
|
|
|
if (boat != null) {
|
|
|
|
|
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
|
|
|
|
boat.setCurrentLeg(legs.get(0));
|
|
|
|
|
// copyLeg.setStartGPSCoordinate(startPositions.get(i));
|
|
|
|
|
// boat.setCurrentLeg(startLeg);
|
|
|
|
|
Leg startLeg = new Leg(name, 0);
|
|
|
|
|
boat.setCurrentPosition(startMarkers.get(i).getAverageGPSCoordinate());
|
|
|
|
|
startLeg.setStartMarker(startMarkers.get(i));
|
|
|
|
|
startLeg.setEndMarker(endMarker);
|
|
|
|
|
startLeg.calculateDistance();
|
|
|
|
|
boat.setCurrentLeg(startLeg);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -214,7 +201,7 @@ public abstract class Race implements Runnable {
|
|
|
|
|
|
|
|
|
|
for (BoatInRace boat : startingBoats) {
|
|
|
|
|
if (boat != null && !boat.isFinished()) {
|
|
|
|
|
updatePosition(boat, Math.round(1000/lastFPS));
|
|
|
|
|
updatePosition(boat, Math.round(1000/lastFPS) > 20 ? 15 : Math.round(1000/lastFPS));
|
|
|
|
|
checkPosition(boat, totalTimeElapsed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -304,31 +291,31 @@ public abstract class Race implements Runnable {
|
|
|
|
|
* 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;
|
|
|
|
|
// }
|
|
|
|
|
public ArrayList<Marker> getSpreadStartingPositions() {
|
|
|
|
|
|
|
|
|
|
int nBoats = startingBoats.size();
|
|
|
|
|
Marker marker = legs.get(0).getStartMarker();
|
|
|
|
|
|
|
|
|
|
GeodeticCalculator initialCalc = new GeodeticCalculator();
|
|
|
|
|
initialCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
|
|
|
|
initialCalc.setDestinationGeographicPoint(marker.getMark2().getLongitude(), marker.getMark2().getLatitude());
|
|
|
|
|
|
|
|
|
|
double azimuth = initialCalc.getAzimuth();
|
|
|
|
|
double distanceBetweenMarkers = initialCalc.getOrthodromicDistance();
|
|
|
|
|
double distanceBetweenBoats = distanceBetweenMarkers / (nBoats + 1);
|
|
|
|
|
|
|
|
|
|
GeodeticCalculator positionCalc = new GeodeticCalculator();
|
|
|
|
|
positionCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
|
|
|
|
ArrayList<Marker> positions = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nBoats; i++) {
|
|
|
|
|
positionCalc.setDirection(azimuth, distanceBetweenBoats);
|
|
|
|
|
Point2D position = positionCalc.getDestinationGeographicPoint();
|
|
|
|
|
positions.add(new Marker(new GPSCoordinate(position.getY(), position.getX())));
|
|
|
|
|
|
|
|
|
|
positionCalc = new GeodeticCalculator();
|
|
|
|
|
positionCalc.setStartingGeographicPoint(position);
|
|
|
|
|
}
|
|
|
|
|
return positions;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|