GOat boats spread out at startline working
#story[20]
This commit is contained in:
@@ -135,18 +135,6 @@ public class RaceController extends Controller{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/*timer.setOnMouseEntered(new EventHandler<MouseEvent>() {
|
|
||||||
@Override
|
|
||||||
public void handle(MouseEvent e) {
|
|
||||||
tp.show(timer, timer.getLayoutX()+timer.getWidth()+10, timer.getLayoutY()+timer.getHeight()-10);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
timer.setOnMouseExited(new EventHandler<MouseEvent>() {
|
|
||||||
@Override
|
|
||||||
public void handle(MouseEvent e) {
|
|
||||||
tp.hide();
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,13 +161,27 @@ public class RaceController extends Controller{
|
|||||||
double long1 = raceXMLReader.getMapTopLeft().getLongitude();
|
double long1 = raceXMLReader.getMapTopLeft().getLongitude();
|
||||||
double lat2 = raceXMLReader.getMapBottomRight().getLatitude();
|
double lat2 = raceXMLReader.getMapBottomRight().getLatitude();
|
||||||
double long2 = raceXMLReader.getMapBottomRight().getLongitude();
|
double long2 = raceXMLReader.getMapBottomRight().getLongitude();
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList<Leg> legs = raceXMLReader.getLegs();
|
||||||
|
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this, scaleFactor);
|
||||||
|
race.initialiseBoats();
|
||||||
|
|
||||||
|
BoatInRace[] startingBoats = new BoatInRace[race.getStartingBoats().size()];
|
||||||
|
int i = 0;
|
||||||
|
for (BoatInRace boat : race.getStartingBoats()) {
|
||||||
|
startingBoats[i] = boat;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
raceMap = new ResizableRaceCanvas(lat1, long1, lat2, long2);
|
raceMap = new ResizableRaceCanvas(lat1, long1, lat2, long2);
|
||||||
raceMap.setMouseTransparent(true);
|
raceMap.setMouseTransparent(true);
|
||||||
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
||||||
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
||||||
raceMap.setBoats(boats);
|
raceMap.setBoats(startingBoats);
|
||||||
raceMap.setRaceBoundaries(raceXMLReader.getBoundary());
|
raceMap.setRaceBoundaries(raceXMLReader.getBoundary());
|
||||||
raceMap.drawBoats();
|
//raceMap.drawBoats();
|
||||||
raceMap.drawRaceMap();
|
raceMap.drawRaceMap();
|
||||||
raceMap.setVisible(true);
|
raceMap.setVisible(true);
|
||||||
|
|
||||||
@@ -187,8 +189,7 @@ public class RaceController extends Controller{
|
|||||||
startScreen.setVisible(false);
|
startScreen.setVisible(false);
|
||||||
ongoingRacePane.setVisible(true);
|
ongoingRacePane.setVisible(true);
|
||||||
|
|
||||||
ArrayList<Leg> legs = raceXMLReader.getLegs();
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this, scaleFactor);
|
|
||||||
|
|
||||||
showFPS.setVisible(true);
|
showFPS.setVisible(true);
|
||||||
showFPS.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
showFPS.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class Leg {
|
|||||||
this.startMarker = start;
|
this.startMarker = start;
|
||||||
this.endMarker = end;
|
this.endMarker = end;
|
||||||
this.legNumber = number;
|
this.legNumber = number;
|
||||||
this.distance = calculateDistance();
|
calculateDistance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,13 +56,6 @@ public class Leg {
|
|||||||
return distance;
|
return distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// public Leg createCopy() {
|
|
||||||
// Leg copy = new Leg(this.name, this.startMarker1, this.startMarker2,
|
|
||||||
// this.endMarker1, this.endMarker2, this.legNumber);
|
|
||||||
// return copy;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the leg number that the leg exists in the Race
|
* Returns the leg number that the leg exists in the Race
|
||||||
*
|
*
|
||||||
@@ -83,12 +76,21 @@ public class Leg {
|
|||||||
return endMarker;
|
return endMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setStartMarker(Marker startMarker) {
|
||||||
|
this.startMarker = startMarker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndMarker(Marker endMarker) {
|
||||||
|
this.endMarker = endMarker;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the distance that the legs are in nautical miles (1.852 km).
|
* Calculates the distance that the legs are in nautical miles (1.852 km).
|
||||||
*
|
*
|
||||||
* @return Returns the leg distance.
|
* @return Returns the leg distance.
|
||||||
*/
|
*/
|
||||||
private double calculateDistance() {
|
public void calculateDistance() {
|
||||||
|
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
//Load start and end of leg
|
//Load start and end of leg
|
||||||
@@ -96,7 +98,9 @@ public class Leg {
|
|||||||
GPSCoordinate endMarker = this.endMarker.getAverageGPSCoordinate();
|
GPSCoordinate endMarker = this.endMarker.getAverageGPSCoordinate();
|
||||||
calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude());
|
calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude());
|
||||||
calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude());
|
calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude());
|
||||||
return calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
|
this.distance = calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,14 @@ public class Marker {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GPSCoordinate getMark1() {
|
||||||
|
return mark1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GPSCoordinate getMark2() {
|
||||||
|
return mark2;
|
||||||
|
}
|
||||||
|
|
||||||
public GPSCoordinate getAverageGPSCoordinate() {
|
public GPSCoordinate getAverageGPSCoordinate() {
|
||||||
return averageGPSCoordinate;
|
return averageGPSCoordinate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,39 +53,26 @@ public abstract class Race implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Constructor for Race class
|
public void initialiseBoats() {
|
||||||
// * @param boats boats participating in the race.
|
|
||||||
// * @param legs legs that there are in the race.
|
Leg officialStart = legs.get(0);
|
||||||
// */
|
String name = officialStart.getName();
|
||||||
// public Race(BoatInRace[] boats, ArrayList<Leg> legs, int scaleFactor) {
|
Marker endMarker = officialStart.getEndMarker();
|
||||||
// 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() {
|
ArrayList<Marker> startMarkers = getSpreadStartingPositions();
|
||||||
|
|
||||||
// Leg startLeg = legs.get(0);
|
|
||||||
// Leg copyLeg = startLeg.createCopy();
|
|
||||||
|
|
||||||
//ArrayList<GPSCoordinate> startPositions = getSpreadStartingPositions();
|
|
||||||
for (int i = 0; i < startingBoats.size(); i++) {
|
for (int i = 0; i < startingBoats.size(); i++) {
|
||||||
BoatInRace boat = startingBoats.get(i);
|
BoatInRace boat = startingBoats.get(i);
|
||||||
if (boat != null) {
|
if (boat != null) {
|
||||||
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
||||||
boat.setCurrentLeg(legs.get(0));
|
Leg startLeg = new Leg(name, 0);
|
||||||
// copyLeg.setStartGPSCoordinate(startPositions.get(i));
|
boat.setCurrentPosition(startMarkers.get(i).getAverageGPSCoordinate());
|
||||||
// boat.setCurrentLeg(startLeg);
|
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) {
|
for (BoatInRace boat : startingBoats) {
|
||||||
if (boat != null && !boat.isFinished()) {
|
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);
|
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
|
* Creates a list of starting positions for the different boats, so they do not appear cramped at the start line
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
// public ArrayList<GPSCoordinate> getSpreadStartingPositions() {
|
public ArrayList<Marker> getSpreadStartingPositions() {
|
||||||
//
|
|
||||||
// int nBoats = startingBoats.size();
|
int nBoats = startingBoats.size();
|
||||||
// GPSCoordinate marker1 = legs.get(0).getStartMarker1();
|
Marker marker = legs.get(0).getStartMarker();
|
||||||
// GPSCoordinate marker2 = legs.get(0).getStartMarker2();
|
|
||||||
// GeodeticCalculator initialCalc = new GeodeticCalculator();
|
GeodeticCalculator initialCalc = new GeodeticCalculator();
|
||||||
// initialCalc.setStartingGeographicPoint(marker1.getLongitude(), marker1.getLatitude());
|
initialCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
||||||
// initialCalc.setDestinationGeographicPoint(marker2.getLongitude(), marker2.getLatitude());
|
initialCalc.setDestinationGeographicPoint(marker.getMark2().getLongitude(), marker.getMark2().getLatitude());
|
||||||
//
|
|
||||||
// double azimuth = initialCalc.getAzimuth();
|
double azimuth = initialCalc.getAzimuth();
|
||||||
// double distanceBetweenMarkers = initialCalc.getOrthodromicDistance();
|
double distanceBetweenMarkers = initialCalc.getOrthodromicDistance();
|
||||||
// double distanceBetweenBoats = distanceBetweenMarkers / (nBoats + 1);
|
double distanceBetweenBoats = distanceBetweenMarkers / (nBoats + 1);
|
||||||
//
|
|
||||||
// GeodeticCalculator positionCalc = new GeodeticCalculator();
|
GeodeticCalculator positionCalc = new GeodeticCalculator();
|
||||||
// positionCalc.setStartingGeographicPoint(marker1.getLongitude(), marker1.getLatitude());
|
positionCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
||||||
// ArrayList<GPSCoordinate> positions = new ArrayList<>();
|
ArrayList<Marker> positions = new ArrayList<>();
|
||||||
//
|
|
||||||
// for (int i = 0; i < nBoats; i++) {
|
for (int i = 0; i < nBoats; i++) {
|
||||||
// positionCalc.setDirection(azimuth, distanceBetweenBoats);
|
positionCalc.setDirection(azimuth, distanceBetweenBoats);
|
||||||
// Point2D position = positionCalc.getDestinationGeographicPoint();
|
Point2D position = positionCalc.getDestinationGeographicPoint();
|
||||||
// positions.add(new GPSCoordinate(position.getY(), position.getX()));
|
positions.add(new Marker(new GPSCoordinate(position.getY(), position.getX())));
|
||||||
//
|
|
||||||
// positionCalc = new GeodeticCalculator();
|
positionCalc = new GeodeticCalculator();
|
||||||
// positionCalc.setStartingGeographicPoint(position);
|
positionCalc.setStartingGeographicPoint(position);
|
||||||
// }
|
}
|
||||||
// return positions;
|
return positions;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user