Created ray casting methods for MockBoat and CompoundMark
- Added ColliderRegistry to Race - Added collision triggering to RaceLogic - Created basic collision handlers for MockBoat and CompoundMark
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
package shared.model;
|
||||
|
||||
|
||||
import mock.model.MockBoat;
|
||||
import mock.model.collider.Collider;
|
||||
import mock.model.collider.Collision;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a compound mark - that is, either one or two individual marks which form a single compound mark.
|
||||
*/
|
||||
public class CompoundMark {
|
||||
public class CompoundMark implements Collider {
|
||||
|
||||
/**
|
||||
* The ID of the compound mark.
|
||||
@@ -110,7 +119,7 @@ public class CompoundMark {
|
||||
* @return The position of the second mark in the compound mark.
|
||||
*/
|
||||
public GPSCoordinate getMark2Position() {
|
||||
return mark2.getPosition();
|
||||
return mark2 == null? mark1.getPosition() : mark2.getPosition();
|
||||
}
|
||||
|
||||
|
||||
@@ -128,17 +137,32 @@ public class CompoundMark {
|
||||
* @return The average coordinate of the compound mark.
|
||||
*/
|
||||
private GPSCoordinate calculateAverage() {
|
||||
|
||||
//If the compound mark only contains one mark, the average is simply the first mark's position.
|
||||
if (this.mark2 == null) {
|
||||
return this.getMark1Position();
|
||||
}
|
||||
|
||||
|
||||
//Otherwise, calculate the average of both marks.
|
||||
GPSCoordinate averageCoordinate = GPSCoordinate.calculateAverageCoordinate(this.getMark1Position(), this.getMark2Position());
|
||||
|
||||
return averageCoordinate;
|
||||
|
||||
}
|
||||
|
||||
private Mark closestMark(GPSCoordinate coordinate) {
|
||||
double mark1distance = GPSCoordinate.calculateDistanceMeters(getMark1Position(), coordinate);
|
||||
double mark2distance = GPSCoordinate.calculateDistanceMeters(getMark2Position(), coordinate);
|
||||
return mark1distance <= mark2distance? mark1 : mark2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rayCast(MockBoat boat) {
|
||||
GPSCoordinate position = boat.getCurrentPosition();
|
||||
double distance = GPSCoordinate.calculateDistanceMeters(position, closestMark(position).getPosition());
|
||||
Bearing bearing = Bearing.fromAzimuth(GPSCoordinate.calculateAzimuth(position, closestMark(position).getPosition()));
|
||||
if(distance < 100) {
|
||||
onCollisionEnter(new Collision(bearing, distance));
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCollisionEnter(Collision e) {
|
||||
System.out.println(e.getBearing().degrees());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import mock.model.collider.ColliderRegistry;
|
||||
import network.Messages.Enums.RaceStatusEnum;
|
||||
import network.Messages.Enums.RaceTypeEnum;
|
||||
import network.Messages.LatestMessages;
|
||||
@@ -20,90 +21,72 @@ import java.util.List;
|
||||
* Has a course, state, wind, boundaries, etc.... Boats are added by inheriting classes (see {@link Boat}, {@link mock.model.MockBoat}, {@link visualiser.model.VisualiserBoat}.
|
||||
*/
|
||||
public abstract class Race {
|
||||
|
||||
|
||||
/**
|
||||
* The source of race related data.
|
||||
*/
|
||||
protected RaceDataSource raceDataSource;
|
||||
|
||||
/**
|
||||
* The source of boat related data.
|
||||
*/
|
||||
protected BoatDataSource boatDataSource;
|
||||
|
||||
/**
|
||||
* The source of regatta related data.
|
||||
*/
|
||||
protected RegattaDataSource regattaDataSource;
|
||||
|
||||
/**
|
||||
* The collection of latest race messages.
|
||||
* Can be either read from or written to.
|
||||
*/
|
||||
protected LatestMessages latestMessages;
|
||||
|
||||
/**
|
||||
* A list of compound marks in the race.
|
||||
*/
|
||||
protected List<CompoundMark> compoundMarks;
|
||||
|
||||
/**
|
||||
* A list of legs in the race.
|
||||
*/
|
||||
protected List<Leg> legs;
|
||||
|
||||
/**
|
||||
* A list of coordinates describing the boundary of the course.
|
||||
*/
|
||||
protected List<GPSCoordinate> boundary;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The clock which tracks the race's start time, current time, and elapsed duration.
|
||||
*/
|
||||
protected RaceClock raceClock;
|
||||
|
||||
|
||||
/**
|
||||
* The race ID of the course.
|
||||
*/
|
||||
protected int raceId;
|
||||
|
||||
/**
|
||||
* The name of the regatta.
|
||||
*/
|
||||
protected String regattaName;
|
||||
|
||||
/**
|
||||
* The current status of the race.
|
||||
*/
|
||||
protected RaceStatusEnum raceStatusEnum;
|
||||
|
||||
/**
|
||||
* The type of race this is.
|
||||
*/
|
||||
protected RaceTypeEnum raceType;
|
||||
|
||||
|
||||
/**
|
||||
* The race's wind.
|
||||
*/
|
||||
protected Property<Wind> raceWind = new SimpleObjectProperty<>();
|
||||
|
||||
|
||||
/**
|
||||
* Registry for all collider object in this race
|
||||
*/
|
||||
protected ColliderRegistry colliderRegistry;
|
||||
/**
|
||||
* The number of frames per second.
|
||||
* We essentially track the number of frames generated per second, over a one second period. When {@link #lastFpsResetTime} reaches 1 second, {@link #currentFps} is reset.
|
||||
*/
|
||||
private int currentFps = 0;
|
||||
|
||||
/**
|
||||
* The number of frames per second we generated over the last 1 second period.
|
||||
*/
|
||||
private IntegerProperty lastFps = new SimpleIntegerProperty(0);
|
||||
|
||||
/**
|
||||
* The time, in milliseconds, since we last reset our {@link #currentFps} counter.
|
||||
*/
|
||||
@@ -156,9 +139,13 @@ public abstract class Race {
|
||||
//Wind.
|
||||
this.setWind(Bearing.fromDegrees(0), 0);
|
||||
|
||||
this.colliderRegistry = new ColliderRegistry();
|
||||
this.colliderRegistry.addAllColliders(compoundMarks);
|
||||
}
|
||||
|
||||
|
||||
public ColliderRegistry getColliderRegistry() {
|
||||
return colliderRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the boats in the race.
|
||||
@@ -272,14 +259,6 @@ public abstract class Race {
|
||||
return raceWind.getValue().getWindSpeed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the race's wind.
|
||||
* @return The race's wind.
|
||||
*/
|
||||
public Property<Wind> windProperty() {
|
||||
return raceWind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the RaceClock for this race.
|
||||
* This is used to track the start time, current time, and elapsed duration of the race.
|
||||
|
||||
Reference in New Issue
Block a user