Wakes no longer become out of sync with boats after extended periods of time. Added in

a limit to the length of boat trails.

#implement
This commit is contained in:
cir27
2017-04-29 02:14:55 +12:00
parent 474f0ee427
commit 6149f7be60
7 changed files with 59 additions and 336 deletions
+10 -10
View File
@@ -14,10 +14,10 @@ import seng302.models.parsers.StreamParser;
*/
public class BoatGroup extends RaceObject{
private static final double TEAMNAME_X_OFFSET = 15d;
private static final double TEAMNAME_Y_OFFSET = -20d;
private static final double VELOCITY_X_OFFSET = 15d;
private static final double VELOCITY_Y_OFFSET = -10d;
private static final double TEAMNAME_X_OFFSET = 10d;
private static final double TEAMNAME_Y_OFFSET = -15d;
private static final double VELOCITY_X_OFFSET = 10d;
private static final double VELOCITY_Y_OFFSET = -5d;
private static final double VELOCITY_WAKE_RATIO = 2d;
private static final double BOAT_HEIGHT = 15d;
private static final double BOAT_WIDTH = 10d;
@@ -72,9 +72,9 @@ public class BoatGroup extends RaceObject{
private void initChildren (Color color) {
initChildren(color,
BOAT_WIDTH / 2, 0.0,
BOAT_WIDTH, BOAT_HEIGHT,
0.0, BOAT_HEIGHT);
-BOAT_WIDTH / 2, BOAT_HEIGHT,
0.0, 0.0,
BOAT_WIDTH / 2, BOAT_HEIGHT);
}
/**
@@ -111,7 +111,7 @@ public class BoatGroup extends RaceObject{
teamNameObject.setLayoutY(y);
velocityObject.setLayoutX(x);
velocityObject.setLayoutY(y);
wake.setLayoutX(x + BOAT_WIDTH / 2);
wake.setLayoutX(x);
wake.setLayoutY(y);
wake.rotate(currentRotation);
}
@@ -158,7 +158,7 @@ public class BoatGroup extends RaceObject{
wake.rotate(rotationalGoal);
wakeGenerationDelay--;
} else {
wake.setRotationalVelocity(rotationalVelocity);
wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, pixelVelocityX, pixelVelocityY);
}
}
}
@@ -196,7 +196,7 @@ public class BoatGroup extends RaceObject{
public void rotateTo (double rotation) {
currentRotation = rotation;
boatPoly.getTransforms().clear();
boatPoly.getTransforms().add(new Rotate(rotation, BOAT_WIDTH / 2, 0));
boatPoly.getTransforms().add(new Rotate(rotation));
}
@@ -69,5 +69,4 @@ public abstract class RaceObject extends Group {
public abstract int[] getRaceIds ();
public abstract void toggleAnnotations ();
}
+17 -9
View File
@@ -21,6 +21,7 @@ class Wake extends Group {
private Arc[] arcs = new Arc[numWakes];
private double[] rotations = new double[numWakes];
private int velocitiesIndex = 0;
private double sum = 0;
/**
* Create a wake at the given location.
@@ -32,14 +33,7 @@ class Wake extends Group {
super.setLayoutY(startingY);
Arc arc;
for (int i = 0; i < numWakes; i++) {
arc = new Arc(
0,
0,
30 + RADIUS_INCREASE * i,
30 + RADIUS_INCREASE * i,
-110,
40
);
arc = new Arc(0,0,0,0,-110,40);
arc.setFill(new Color(0.18, 0.7, 1.0, 0.50 + OPACITY_INCREASE * i));
arc.setType(ArcType.ROUND);
arcs[i] = arc;
@@ -52,9 +46,23 @@ class Wake extends Group {
* the latest given velocity.
* @param rotationalVelocity The rotationalVelocity the wake should move at.
*/
void setRotationalVelocity (double rotationalVelocity) {
void setRotationalVelocity (double rotationalVelocity, double rotationGoal, double velocityX, double velocityY) {
sum -= Math.abs(velocities[velocitiesIndex]);
sum += Math.abs(rotationalVelocity);
if (sum < 0.0001)
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.
velocitiesIndex = (velocitiesIndex + 1) % 14;
velocities[velocitiesIndex] = rotationalVelocity;
double scaleFactor = Math.abs(Math.log10(Math.abs(velocityX) + Math.abs(velocityY)));
double baseRad = 30;
for (Arc arc :arcs) {
double rad = baseRad + 5 * scaleFactor;
arc.setRadiusX(rad);
arc.setRadiusY(rad);
baseRad += RADIUS_INCREASE;
}
}
/**
@@ -28,10 +28,6 @@ public class MarkGroup extends RaceObject {
private Point2D[] nodeDestinations;
public MarkGroup (Mark mark, Point2D... points) {
// for (Point2D p : points) {
// System.out.println("p.getX() = " + p.getX());
// System.out.println("p.getY() = " + p.getY());
// }
marks.add(mark);
mainMark = mark;
Color color = Color.BLACK;
@@ -43,9 +39,6 @@ public class MarkGroup extends RaceObject {
System.out.println("HERE ARE THE CHILDREN LOL");
if (mark.getMarkType() == MarkType.SINGLE_MARK) {
super.getChildren().add(new Circle(0, 0, MARK_RADIUS, color));
// System.out.println("SingleMark?");
// System.out.println("super.getChildren().get(0).getLayoutX() = " + super.getChildren().get(0).getLayoutX());
// System.out.println("super.getChildren().get(0).getLayoutY() = " + super.getChildren().get(0).getLayoutY());
} else {
marks.add(((GateMark) mark).getSingleMark1());
marks.add(((GateMark) mark).getSingleMark2());
@@ -57,13 +50,6 @@ public class MarkGroup extends RaceObject {
color
)
);
// super.getChildren().add(new Circle(0, 0, MARK_RADIUS, color));
// super.getChildren().get(0).setLayoutX((points[1].getX() - points[0].getX()) / 2d);
// super.getChildren().get(0).setLayoutY((points[1].getY() - points[0].getY()) / 2d);
// System.out.println("!!!!!!!!!!!!!!!!!");
// System.out.println((points[1].getX() - points[0].getX()) / 2d);
// System.out.println((points[1].getY() - points[0].getY()) / 2d);
// System.out.println(super.getChildren().get(0));
super.getChildren().add(
new Circle(
-(points[1].getX() - points[0].getX()) / 2d,
@@ -72,9 +58,6 @@ public class MarkGroup extends RaceObject {
color
)
);
// super.getChildren().add(new Circle(0, 0, MARK_RADIUS, color));
// super.getChildren().get(1).setLayoutX(-(points[1].getX() - points[0].getX()) / 2d);
// super.getChildren().get(1).setLayoutY(-(points[1].getY() - points[0].getY()) / 2d);
Line line = new Line(
(points[1].getX() - points[0].getX()) / 2d,
(points[1].getY() - points[0].getY()) / 2d,
@@ -93,22 +76,8 @@ public class MarkGroup extends RaceObject {
new Point2D(super.getChildren().get(0).getLayoutX(), super.getChildren().get(0).getLayoutY()),
new Point2D(super.getChildren().get(1).getLayoutX(), super.getChildren().get(1).getLayoutY())
};
// nodeDestinations = new Point2D[]{new Point2D(0,0), new Point2D(0,0)};
// System.out.println("super.getChildren().get(0).getLayoutX() = " + super.getChildren().get(0).getLayoutX());
// System.out.println("super.getChildren().get(0).getLayoutY() = " + super.getChildren().get(0).getLayoutY());
// System.out.println("super.getChildren().get(1).getLayoutX() = " + super.getChildren().get(1).getLayoutX());
// System.out.println("super.getChildren().get(1).getLayoutY() = " + super.getChildren().get(1).getLayoutY());
}
moveTo(points[0].getX(), points[0].getY());
// System.out.println("OKAY HERE IS A MARK");
// System.out.println("super.getLayoutX() = " + super.getLayoutX());
// System.out.println("super.getLayoutY() = " + super.getLayoutY());
// System.out.println("super.getChildren().get(0).getLayoutX() = " + super.getChildren().get(0).getLayoutX());
// System.out.println("super.getChildren().get(0).getLayoutY() = " + super.getChildren().get(0).getLayoutY());
// pixelVelocityX = 0;
// pixelVelocityY = 0;
// rotationalVelocity = 0;
// rotationalGoal = 0;
}
public void setDestination (double x, double y, double rotation, int... raceIds) {
@@ -146,14 +115,7 @@ public class MarkGroup extends RaceObject {
public void rotateTo (double rotation) {
super.getTransforms().clear();
// super.getTransforms().add(
// new Rotate(
// rotation,
// super.getChildren().get(1).getLayoutX() - super.getChildren().get(0).getLayoutX(),
// super.getChildren().get(1).getLayoutY() - super.getChildren().get(0).getLayoutY()
// )
// );
super.getTransforms().add(new Rotate(rotation, 0 , 0));
super.getTransforms().add(new Rotate(rotation));
}
public void updatePosition (long timeInterval) {