Linked the streamedRace course to the visualiser, linked the boats to the visualiser (this needs to be tests) #story[768]
This commit is contained in:
@@ -1,44 +1,60 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.BoatInRace;
|
||||
import seng302.Model.Leg;
|
||||
import seng302.Model.Marker;
|
||||
|
||||
/**
|
||||
* Created by Joseph on 24/04/2017.
|
||||
*/
|
||||
public class StreamedBoat extends BoatInRace {
|
||||
private int sourceID;
|
||||
private boolean complete;
|
||||
private boolean dnf = false;
|
||||
|
||||
private void init() {
|
||||
this.velocity = 0;
|
||||
this.scaledVelocity = 0;
|
||||
this.heading = 0;
|
||||
this.setCurrentLeg(new Leg("None", -1));
|
||||
this.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||
}
|
||||
|
||||
public StreamedBoat(int sourceID, String name, Color colour, String abbrev) {
|
||||
super(name, colour, abbrev);
|
||||
this.sourceID = sourceID;
|
||||
this.complete = true;
|
||||
this.init();
|
||||
}
|
||||
|
||||
public StreamedBoat(int sourceID) {
|
||||
super("None", Color.BLACK, "None");
|
||||
this.sourceID = sourceID;
|
||||
this.complete = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Overridden to ignore this function
|
||||
* @deprecated
|
||||
* @return 0
|
||||
*/
|
||||
public double getScaledVelocity() {
|
||||
return 0;
|
||||
this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden to ignore this function
|
||||
* @deprecated
|
||||
* @param velocity of boat
|
||||
* Calculates the azimuth of the travel via heading of the boat
|
||||
*
|
||||
* @return the direction that the boat is heading towards in degrees (-180 to 180).
|
||||
*/
|
||||
public void setScaledVelocity(double velocity) {
|
||||
public double calculateAzimuth() {
|
||||
double azimuth;
|
||||
if (heading <= 180) {
|
||||
azimuth = heading;
|
||||
} else {
|
||||
azimuth = -heading + 180;
|
||||
}
|
||||
return azimuth;
|
||||
}
|
||||
|
||||
public boolean isDnf() {
|
||||
return dnf;
|
||||
}
|
||||
|
||||
public void setDnf(boolean dnf) {
|
||||
this.dnf = dnf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import seng302.Constants;
|
||||
import seng302.Controllers.RaceController;
|
||||
import seng302.Model.BoatInRace;
|
||||
import seng302.Model.Leg;
|
||||
import seng302.Model.Race;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.Model.*;
|
||||
import seng302.RaceDataSource;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -18,10 +20,23 @@ public class StreamedRace extends Race {
|
||||
public StreamedRace(RaceDataSource raceData, RaceController controller, int scaleFactor) {
|
||||
super(raceData.getBoats(), raceData.getLegs(), controller, scaleFactor);
|
||||
this.raceData = raceData;
|
||||
this.scaleFactor = 1; // There will be no scaling in a live streamed race
|
||||
}
|
||||
|
||||
public void initialiseBoats() {
|
||||
Leg officialStart = legs.get(0);
|
||||
String name = officialStart.getName();
|
||||
Marker endMarker = officialStart.getEndMarker();
|
||||
|
||||
for (int i = 0; i < startingBoats.size(); i++) {
|
||||
BoatInRace boat = startingBoats.get(i);
|
||||
if (boat != null) {
|
||||
Leg startLeg = new Leg(name, 0);
|
||||
startLeg.setEndMarker(endMarker);
|
||||
boat.setCurrentLeg(startLeg);
|
||||
boat.setHeading(boat.calculateHeading());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,6 +44,7 @@ public class StreamedRace extends Race {
|
||||
* @return True if boat cannot finish the race
|
||||
*/
|
||||
protected boolean doNotFinish() {
|
||||
// DNF is no longer random and is now determined by a dnf packet
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -39,8 +55,21 @@ public class StreamedRace extends Race {
|
||||
* @param timeElapsed Time that has elapse since the start of the the race.
|
||||
* @see BoatInRace
|
||||
*/
|
||||
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
||||
|
||||
protected void checkPosition(StreamedBoat boat, long timeElapsed) {
|
||||
if (boat.getCurrentLeg().getName().toLowerCase().contains("finish")) {
|
||||
//boat has finished
|
||||
boatsFinished++;
|
||||
boat.setFinished(true);
|
||||
boat.setTimeFinished(timeElapsed);
|
||||
} else if (boat.isDnf()) {
|
||||
boatsFinished++;
|
||||
boat.setFinished(true);
|
||||
boat.setCurrentLeg(new Leg("DNF", -1));
|
||||
boat.setVelocity(0);
|
||||
boat.setScaledVelocity(0);
|
||||
}
|
||||
//Update the boat display table in the GUI to reflect the leg change
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +78,63 @@ public class StreamedRace extends Race {
|
||||
* @param boat to be updated
|
||||
* @param millisecondsElapsed time since last update
|
||||
*/
|
||||
protected void updatePosition(BoatInRace boat, int millisecondsElapsed) {
|
||||
protected void updatePosition(StreamedBoat boat, int millisecondsElapsed) {
|
||||
//distanceTravelled = velocity (nm p hr) * time taken to update loop
|
||||
double distanceTravelled = (boat.getVelocity() * millisecondsElapsed) / 3600000;
|
||||
|
||||
boolean finish = boat.getCurrentLeg().getName().toLowerCase().contains("finish");
|
||||
if (!finish) {
|
||||
//Calculate boat's new position by adding the distance travelled onto the start point of the leg
|
||||
boat.setCurrentPosition(calculatePosition(boat.getCurrentPosition(), distanceTravelled, boat.calculateAzimuth()));
|
||||
}
|
||||
}
|
||||
|
||||
protected void setPostion(StreamedBoat boat, GPSCoordinate coordinate) {
|
||||
boat.setCurrentPosition(coordinate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the boats next GPS position based on its distance travelled and heading
|
||||
*
|
||||
* @param oldCoordinates GPS coordinates of the boat's starting position
|
||||
* @param distanceTravelled distance in nautical miles
|
||||
* @param azimuth boat's current direction. Value between -180 and 180
|
||||
* @return The boat's new coordinate
|
||||
*/
|
||||
public static GPSCoordinate calculatePosition(GPSCoordinate oldCoordinates, double distanceTravelled, double azimuth) {
|
||||
|
||||
//Find new coordinate using current heading and distance
|
||||
|
||||
GeodeticCalculator geodeticCalculator = new GeodeticCalculator();
|
||||
//Load start point into calculator
|
||||
Point2D startPoint = new Point2D.Double(oldCoordinates.getLongitude(), oldCoordinates.getLatitude());
|
||||
geodeticCalculator.setStartingGeographicPoint(startPoint);
|
||||
//load direction and distance travelled into calculator
|
||||
geodeticCalculator.setDirection(azimuth, distanceTravelled * Constants.NMToMetersConversion);
|
||||
//get new point
|
||||
Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint();
|
||||
|
||||
return new GPSCoordinate(endPoint.getY(), endPoint.getX());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the position of the boat, this updates the boats current position.
|
||||
* @deprecated
|
||||
* @param boat Boat that the postion is to be updated for.
|
||||
* @param timeElapsed Time that has elapse since the start of the the race.
|
||||
* @see BoatInRace
|
||||
*/
|
||||
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the boat's gps coordinates
|
||||
* @deprecated
|
||||
* @param boat to be updated
|
||||
* @param millisecondsElapsed time since last update
|
||||
*/
|
||||
protected void updatePosition(BoatInRace boat, int millisecondsElapsed){
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user