mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Documented some RaceObject classes.
#documentation
This commit is contained in:
@@ -99,9 +99,6 @@ public class CanvasController {
|
||||
fitMarksToCanvas();
|
||||
drawBoats();
|
||||
timer = new AnimationTimer() {
|
||||
private int countdown = 60;
|
||||
private int[] currentRaceMarker = {1, 1, 1, 1, 1, 1};
|
||||
List<Mark> marks = raceViewController.getRace().getCourse();
|
||||
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
@@ -118,14 +115,18 @@ public class CanvasController {
|
||||
if (frameTimeIndex == 0) {
|
||||
arrayFilled = true ;
|
||||
}
|
||||
long elapsedNanos;
|
||||
if (arrayFilled) {
|
||||
long elapsedNanos = now - oldFrameTime ;
|
||||
elapsedNanos = now - oldFrameTime ;
|
||||
long elapsedNanosPerFrame = elapsedNanos / frameTimes.length ;
|
||||
Double frameRate = 1_000_000_000.0 / elapsedNanosPerFrame ;
|
||||
drawFps(frameRate.intValue());
|
||||
}
|
||||
// TODO: 1/05/17 cir27 - Make the RaceObjects update on the actual delay.
|
||||
elapsedNanos = 1000 / 60;
|
||||
System.out.println("elapsedNanos = " + elapsedNanos);
|
||||
for (RaceObject raceObject : raceObjects) {
|
||||
raceObject.updatePosition(1000 / 60);
|
||||
raceObject.updatePosition(elapsedNanos);
|
||||
for (int id : raceObject.getRaceIds()) {
|
||||
if (StreamParser.boatPositions.containsKey((long) id)) {
|
||||
Point3D p = StreamParser.boatPositions.get((long) id);
|
||||
@@ -146,7 +147,7 @@ public class CanvasController {
|
||||
|
||||
class ResizableCanvas extends Canvas {
|
||||
|
||||
public ResizableCanvas() {
|
||||
ResizableCanvas() {
|
||||
// Redraw canvas when size changes.
|
||||
widthProperty().addListener(evt -> draw());
|
||||
heightProperty().addListener(evt -> draw());
|
||||
@@ -203,39 +204,14 @@ public class CanvasController {
|
||||
for (Boat boat : boats) {
|
||||
BoatGroup boatGroup = new BoatGroup(boat, Colors.getColor());
|
||||
boatGroup.moveTo(startingX, startingY, 0d);
|
||||
// boatGroup.setDestination(firstMarkX, firstMarkY);
|
||||
boatGroup.forceRotation();
|
||||
//group.getChildren().add(boatGroup);
|
||||
raceObjects.add(boatGroup);
|
||||
boatAnnotations.getChildren().add(boatGroup.getLowPriorityAnnotations());
|
||||
// drawBoat(boat.getLongitude(), boat.getLatitude(), boat.getColor(), boat.getShortName(), boat.getSpeedInKnots(), boat.getHeading());
|
||||
}
|
||||
group.getChildren().add(boatAnnotations);
|
||||
group.getChildren().addAll(raceObjects);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class for creating point so that you can rotate it around origin point.
|
||||
*/
|
||||
class Point {
|
||||
|
||||
double x, y;
|
||||
|
||||
Point (double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
void rotate(double angle) {
|
||||
double oldX = x;
|
||||
double oldY = y;
|
||||
this.x = oldX * Math.cos(angle) - oldY * Math.sin(angle);
|
||||
this.y = oldX * Math.sin(angle) + oldY * Math.cos(angle);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates x and y location for every marker that fits it to the canvas the race will be drawn on.
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,6 @@ public class BoatGroup extends RaceObject{
|
||||
private static final double BOAT_HEIGHT = 15d;
|
||||
private static final double BOAT_WIDTH = 10d;
|
||||
private static final int LINE_INTERVAL = 30;
|
||||
private static double expectedUpdateInterval = 200;
|
||||
private double framesForNewLine = 0;
|
||||
private boolean destinationSet;
|
||||
private Point2D lastPoint;
|
||||
@@ -56,6 +55,7 @@ public class BoatGroup extends RaceObject{
|
||||
*/
|
||||
public BoatGroup (Boat boat, Color color, double... points)
|
||||
{
|
||||
this.boat = boat;
|
||||
initChildren(color, points);
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ public class BoatGroup extends RaceObject{
|
||||
|
||||
/**
|
||||
* Updates the position of all graphics in the BoatGroup based off of the given time interval.
|
||||
* @param timeInterval The interval, in microseconds, the boat should update it's position based on.
|
||||
* @param timeInterval The interval, in milliseconds, the boat should update it's position based on.
|
||||
*/
|
||||
public void updatePosition (long timeInterval) {
|
||||
//Calculate the movement of the boat.
|
||||
@@ -249,6 +249,12 @@ public class BoatGroup extends RaceObject{
|
||||
return boat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this BoatGroup contains at least one of the given IDs.
|
||||
*
|
||||
* @param raceIds The ID's to check the BoatGroup for.
|
||||
* @return True if the BoatGroup contains at east one of the given IDs, false otherwise.
|
||||
*/
|
||||
public boolean hasRaceId (int... raceIds) {
|
||||
for (int id : raceIds) {
|
||||
if (id == boat.getId())
|
||||
@@ -257,10 +263,22 @@ public class BoatGroup extends RaceObject{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all raceIds associated with this group. For BoatGroups the ID's are for the boat.
|
||||
*
|
||||
* @return An array containing all ID's associated with this RaceObject.
|
||||
*/
|
||||
public int[] getRaceIds () {
|
||||
return new int[] {boat.getId()};
|
||||
}
|
||||
|
||||
/**
|
||||
* Due to javaFX limitations annotations associated with a boat that you want to appear below all boats in the
|
||||
* Z-axis need to be pulled out of the BoatGroup and added to the parent group of the BoatGroups. This function
|
||||
* returns these annotations as a group.
|
||||
*
|
||||
* @return A group containing low priority annotations.
|
||||
*/
|
||||
public Group getLowPriorityAnnotations () {
|
||||
Group group = new Group();
|
||||
group.getChildren().addAll(wake, lineGroup);
|
||||
|
||||
@@ -18,8 +18,6 @@ public abstract class RaceObject extends Group {
|
||||
protected double pixelVelocityX;
|
||||
protected double pixelVelocityY;
|
||||
|
||||
static double max = 0;
|
||||
|
||||
public Point2D getPosition () {
|
||||
return new Point2D(super.getLayoutX(), getLayoutY());
|
||||
}
|
||||
@@ -28,10 +26,16 @@ public abstract class RaceObject extends Group {
|
||||
return expectedUpdateInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void setExpectedUpdateInterval(double expectedUpdateInterval) {
|
||||
RaceObject.expectedUpdateInterval = expectedUpdateInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the rotational velocity required to reach the rotationalGoal from the currentRotation.
|
||||
*/
|
||||
protected void calculateRotationalVelocity () {
|
||||
if (Math.abs(rotationalGoal - currentRotation) > 180) {
|
||||
if (rotationalGoal - currentRotation >= 0) {
|
||||
@@ -47,20 +51,24 @@ public abstract class RaceObject extends Group {
|
||||
rotationalVelocity = 0;
|
||||
rotateTo(rotationalGoal);
|
||||
}
|
||||
// max = Math.max(max, Math.abs(rotationalVelocity));
|
||||
// System.out.println("max = " + max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the destination of everything within the RaceObject that has an ID in the array raceIds. The destination is
|
||||
* set to the co-ordinates (x, y) with the given rotation.
|
||||
* @param x
|
||||
* @param y
|
||||
* @param rotation
|
||||
* @param raceIds
|
||||
* @param x X co-ordinate to move the graphics to.
|
||||
* @param y Y co-ordinate to move the graphics to.
|
||||
* @param rotation Rotation to move graphics to.
|
||||
* @param raceIds RaceID of the object to move.
|
||||
*/
|
||||
public abstract void setDestination (double x, double y, double rotation, int... raceIds);
|
||||
|
||||
/**
|
||||
* Sets the destination of everything within the RaceObject that has an ID in the array raceIds. The destination is
|
||||
* set to the co-ordinates (x, y).
|
||||
* @param x X co-ordinate to move the graphic to.
|
||||
* @param y Y co-ordinate to move the graphic to.
|
||||
* @param raceIds RaceID to the object to move.
|
||||
*/
|
||||
public abstract void setDestination (double x, double y, int... raceIds);
|
||||
|
||||
public abstract void updatePosition (long timeInterval);
|
||||
|
||||
@@ -21,8 +21,6 @@ class Wake extends Group {
|
||||
private double[] rotations = new double[numWakes];
|
||||
private int[] velocityIndices = new int[numWakes];
|
||||
private double sum = 0;
|
||||
static double max = 0;
|
||||
static double min = Double.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* Create a wake at the given location.
|
||||
@@ -54,17 +52,12 @@ class Wake extends Group {
|
||||
rotationalVelocity = 0;
|
||||
}
|
||||
sum -= Math.abs(velocities[(velocityIndices[0] + 10) % 13]);
|
||||
// sum -= Math.abs(velocities[velocityIndices[0]]);
|
||||
sum += Math.abs(rotationalVelocity);
|
||||
System.out.println("sum = " + sum);
|
||||
if (sum < 0.9)
|
||||
rotate (rotationGoal); //In relatively straight segments the wake snaps to match the boats current position.
|
||||
//This stops the wake from eventually becoming out of sync with the boat.
|
||||
//This stops the wake from eventually becoming out of sync with the boat.
|
||||
|
||||
max = Math.max(max, sum);
|
||||
min = Math.min(max, sum);
|
||||
System.out.println("max = " + max);
|
||||
System.out.println("min = " + min);
|
||||
//Update the index of the array of recent velocities that each wake uses. Each wake is 3 velocities behind the
|
||||
//next smallest wake.
|
||||
velocityIndices[0] = (13 + (velocityIndices[0] - 1) % 13) % 13;
|
||||
|
||||
Reference in New Issue
Block a user