GOat boats spread out at startline working

#story[20]
main
Erika Savell 9 years ago
parent 0e7d210cea
commit 9808c57ca7

@ -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 lat2 = raceXMLReader.getMapBottomRight().getLatitude();
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.setMouseTransparent(true);
raceMap.widthProperty().bind(canvasBase.widthProperty());
raceMap.heightProperty().bind(canvasBase.heightProperty());
raceMap.setBoats(boats);
raceMap.setBoats(startingBoats);
raceMap.setRaceBoundaries(raceXMLReader.getBoundary());
raceMap.drawBoats();
//raceMap.drawBoats();
raceMap.drawRaceMap();
raceMap.setVisible(true);
@ -187,8 +189,7 @@ public class RaceController extends Controller{
startScreen.setVisible(false);
ongoingRacePane.setVisible(true);
ArrayList<Leg> legs = raceXMLReader.getLegs();
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this, scaleFactor);
showFPS.setVisible(true);
showFPS.selectedProperty().addListener(new ChangeListener<Boolean>() {

@ -25,7 +25,7 @@ public class Leg {
this.startMarker = start;
this.endMarker = end;
this.legNumber = number;
this.distance = calculateDistance();
calculateDistance();
}
/**
@ -56,13 +56,6 @@ public class Leg {
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
*
@ -83,12 +76,21 @@ public class Leg {
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).
*
* @return Returns the leg distance.
*/
private double calculateDistance() {
public void calculateDistance() {
GeodeticCalculator calc = new GeodeticCalculator();
//Load start and end of leg
@ -96,7 +98,9 @@ public class Leg {
GPSCoordinate endMarker = this.endMarker.getAverageGPSCoordinate();
calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.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() {
return averageGPSCoordinate;
}

@ -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;
}
}

Loading…
Cancel
Save