From 89ef6e5277adc02799d3b370fcc9ca7b347db054 Mon Sep 17 00:00:00 2001 From: Calum Date: Sun, 14 May 2017 17:24:15 +1200 Subject: [PATCH 1/8] Wake calculation now changed to be based off of the separation between wakes. This allows wakes to auto correct their position better and stops the system reliance on "realistic data". Wakes have several options for behaviour until the ideal settings are decided upon. Note that MarkGroup position updating is currently disabled. #implement #refactor #issue[1] #story[923] --- src/main/java/seng302/App.java | 3 +- src/main/java/seng302/models/BoatGroup.java | 24 ++- src/main/java/seng302/models/Wake.java | 143 +++++++++++++----- .../java/seng302/models/mark/MarkGroup.java | 72 ++++----- 4 files changed, 158 insertions(+), 84 deletions(-) diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index 1a400afd..4aa14563 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -62,7 +62,8 @@ public class App extends Application } //Change the StreamReceiver in this else block to change the default data source. else{ - sr = new StreamReceiver("localhost", 4949, "RaceStream"); +// sr = new StreamReceiver("localhost", 4949, "RaceStream"); + sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream"); } sr.start(); diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index 57dd48db..70b979ff 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -204,25 +204,23 @@ public class BoatGroup extends RaceObject{ double dx = newXValue - boatPoly.getLayoutX(); double dy = newYValue - boatPoly.getLayoutY(); //Check movement is reasonable. Assumes a 1000 * 1000 canvas - if (Math.abs(dx) > 50 || Math.abs(dy) > 50) { - dx = 0; - dy = 0; - moveTo(newXValue, newYValue); - } +// if (Math.abs(dx) > 50 || Math.abs(dy) > 50) { +// dx = 0; +// dy = 0; +// moveTo(newXValue, newYValue); +// } pixelVelocityX = dx / expectedUpdateInterval; pixelVelocityY = dy / expectedUpdateInterval; rotationalGoal = rotation; calculateRotationalVelocity(); - - if (wakeGenerationDelay > 0) { - wake.rotate(rotationalGoal); - rotateTo(rotationalGoal); //Need to test with this removed. + if (Math.abs(rotationalVelocity) > 0.075) { + System.out.println("rotationalVelocity = " + rotationalVelocity); rotationalVelocity = 0; - wakeGenerationDelay--; - } else { - wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, boat.getVelocity()); + rotateTo(rotationalGoal); + wake.rotate(rotationalGoal); } + wake.setRotationalVelocity(rotationalVelocity, boat.getVelocity()); velocityObject.setText(String.format("%.2f m/s", boat.getVelocity())); } else { setToInitialLocation = true; @@ -347,7 +345,7 @@ public class BoatGroup extends RaceObject{ App.start() -> Controller.setContentPane -> RaceViewController -> CanvasController */ this.stage = stage; - this.stage.iconifiedProperty().addListener(e -> { + this.stage.iconifiedProperty().addListener( e -> { isMaximized = !stage.isIconified(); if (!lineStorage.isEmpty()) { lineGroup.getChildren().addAll(lineStorage); diff --git a/src/main/java/seng302/models/Wake.java b/src/main/java/seng302/models/Wake.java index 55d4381c..9f6ef621 100644 --- a/src/main/java/seng302/models/Wake.java +++ b/src/main/java/seng302/models/Wake.java @@ -4,6 +4,7 @@ import javafx.scene.Group; import javafx.scene.paint.Color; import javafx.scene.shape.Arc; import javafx.scene.shape.ArcType; +import javafx.scene.shape.StrokeLineCap; import javafx.scene.transform.Rotate; /** @@ -15,13 +16,22 @@ import javafx.scene.transform.Rotate; */ class Wake extends Group { - private int numWakes = 5; - private double[] velocities = new double[13]; + //Wake Settings. Should probably be hard coded in when the final values are decided upon. + private enum functionType {LINEAR, LOGARITHMIC, POWER, ROOT, POWOUT_LOGIN} + private functionType wakeFunction = functionType.LOGARITHMIC; + private ArcType arcType = ArcType.OPEN; + private int numWakes = 10; + private double offSet = 0; + private final double MAX_DIFF = 75.0; + private final int UNIFICATION_SPEED = 500; + private final int POWER = 2; + private Arc[] arcs = new Arc[numWakes]; + private double[] rotationalVelocities = new double[numWakes]; private double[] rotations = new double[numWakes]; - private int[] velocityIndices = new int[numWakes]; - private double sum = 0; - private static double max; + private double baseRad; + private boolean spawnNewWake = false; + private int count = 10; /** * Create a wake at the given location. @@ -34,11 +44,22 @@ class Wake extends Group { Arc arc; for (int i = 0; i < numWakes; i++) { //Default triangle is -110 deg out of phase with a default wake and has angle of 40 deg. - arc = new Arc(0,0,0,0,-110,40); - //Opacity increases from 0.5 -> 0 evenly over the 5 wake arcs. - arc.setFill(new Color(0.18, 0.7, 1.0, 1.0 + -0.175 * i)); + arc = new Arc(0, 0, 0, 0, -110, 40); + + if (arcType == ArcType.ROUND) { + arc.setFill(new Color(0.18, 0.7, 1.0, 0.4 + (-0.35 / numWakes * i))); arc.setType(ArcType.ROUND); - arcs[i] = arc; + baseRad = 10; + + } else if (arcType == ArcType.OPEN) { + arc.setType(ArcType.OPEN); + arc.setStroke(new Color(0.18, 0.7, 1.0, 1.0 + (-0.99 / numWakes * i))); + arc.setStrokeWidth(3.0); + arc.setStrokeLineCap(StrokeLineCap.ROUND); + arc.setFill(new Color(0.0, 0.0, 0.0, 0.0)); + baseRad = (20 / numWakes); + arcs[i] = arc; + } } super.getChildren().addAll(arcs); } @@ -47,38 +68,91 @@ class Wake extends Group { * Sets the rotationalVelocity of each arc. Each arc is 3 velocities behind the next smallest arc. The smallest uses * the latest given velocity. * @param rotationalVelocity The rotationalVelocity the wake should move at. - * @param rotationGoal Where the wake will rotate to if the wake is calculated to be on a straight section. This is - * used to prevent desynchronisation with the Boat polygon. * @param velocity The real world velocity of the boat in m/s. */ - void setRotationalVelocity (double rotationalVelocity, double rotationGoal, double velocity) { - sum -= Math.abs(velocities[(velocityIndices[0] + 10) % 13]); - sum += Math.abs(rotationalVelocity); - max = Math.max(max, rotationalVelocity); - if (sum < (max / 3)) - 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 accounts for rogue rotations that are greater than what would be realistic. Value is kinda rough. - //Basically just for our internal mock. - if (Math.abs(rotationalVelocity) > 0.05) { - rotationalVelocity = 0; - rotate(rotationGoal); + void setRotationalVelocity (double rotationalVelocity, double velocity) { + rotationalVelocities[0] = rotationalVelocity; + for (int i = 1; i < numWakes; i++) { + double difference = Math.atan2( + Math.sin( + Math.toRadians( + rotations[i - 1] - rotations[i] + ) + ), + Math.cos( + Math.toRadians( + rotations[i - 1] - rotations[i] + ) + ) + ); + difference = Math.toDegrees(difference); + + if (wakeFunction == functionType.LOGARITHMIC) { + if (rotationalVelocities[i-1] < 0.01 && rotationalVelocities[i-1] > -0.01) { + rotationalVelocities[i] = (MAX_DIFF / numWakes) / UNIFICATION_SPEED * Math.log(Math.abs(difference) + 1) / Math.log(MAX_DIFF / numWakes) * 1.5; + if (difference < 0) + { + rotationalVelocities[i] = -rotationalVelocities[i]; + } + } else { + rotationalVelocities[i] = rotationalVelocities[i-1] * Math.log(Math.abs(difference) + 1) / Math.log(MAX_DIFF / numWakes); + } + + } else if (wakeFunction == functionType.LINEAR) { + if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) { + rotationalVelocities[i] = difference / UNIFICATION_SPEED * 2; + } else { + if (difference < (MAX_DIFF / numWakes)) + rotationalVelocities[i] = rotationalVelocities[i - 1] * difference / (MAX_DIFF / numWakes); + else + rotationalVelocities[i] = rotationalVelocities[i - 1]; + } + } else if (wakeFunction == functionType.POWER) { + if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) { + rotationalVelocities[i] = difference / UNIFICATION_SPEED * Math.pow(difference, POWER) / Math.pow((MAX_DIFF / numWakes), POWER); + } else { + if (difference < (MAX_DIFF / numWakes)) + rotationalVelocities[i] = rotationalVelocities[i - 1] * Math.pow(difference, POWER) / Math.pow((MAX_DIFF / numWakes), POWER); + else + rotationalVelocities[i] = rotationalVelocities[i - 1]; + } + } else if (wakeFunction == functionType.ROOT) { + if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) { + rotationalVelocities[i] = (MAX_DIFF / numWakes) / UNIFICATION_SPEED * Math.sqrt(Math.abs(difference)) / Math.sqrt(MAX_DIFF / numWakes); + } else { + if (difference < (MAX_DIFF / numWakes)) + rotationalVelocities[i] = rotationalVelocities[i - 1] * Math.sqrt(Math.abs(difference)) / Math.sqrt(MAX_DIFF / numWakes); + else + rotationalVelocities[i] = rotationalVelocities[i - 1]; + } + if (difference < 0) + rotationalVelocities[i] = -rotationalVelocities[i]; + } else if (wakeFunction == functionType.POWOUT_LOGIN) { + if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) { + rotationalVelocities[i] = difference / UNIFICATION_SPEED * Math.log(Math.abs(difference) + 1) / Math.log(MAX_DIFF / numWakes); + } else { + if (difference < (MAX_DIFF / numWakes)) + rotationalVelocities[i] = rotationalVelocities[i - 1] * Math.pow(difference, POWER) / Math.pow((MAX_DIFF / numWakes), POWER); + else + rotationalVelocities[i] = rotationalVelocities[i - 1]; + } + } + } - //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; - velocities[velocityIndices[0]] = rotationalVelocity; - for (int i = 1; i < numWakes; i++) - velocityIndices[i] = (velocityIndices[0] + 3 * i) % 13; //Scale wakes based on velocity. - double baseRad = 20; - double rad; +// if (count-- == 0) +// { +// count = 10; +// offSet = 0; +// } else { +// offSet += baseRad / 5; +// } + double rad = baseRad + velocity + offSet; for (Arc arc :arcs) { - rad = baseRad + velocity; arc.setRadiusX(rad); arc.setRadiusY(rad); - baseRad += 5 + (velocity / 2); + rad += (20 / numWakes) + (velocity / 2); } } @@ -88,7 +162,7 @@ class Wake extends Group { */ void updatePosition (long timeInterval) { for (int i = 0; i < numWakes; i++) { - rotations[i] = rotations[i] + velocities[velocityIndices[i]] * timeInterval; + rotations[i] = rotations[i] + rotationalVelocities[i] * timeInterval; arcs[i].getTransforms().setAll(new Rotate(rotations[i])); } } @@ -100,6 +174,7 @@ class Wake extends Group { void rotate (double rotation) { for (int i = 0; i < arcs.length; i++) { rotations[i] = rotation; + rotationalVelocities[i] = 0; arcs[i].getTransforms().setAll(new Rotate(rotation)); } } diff --git a/src/main/java/seng302/models/mark/MarkGroup.java b/src/main/java/seng302/models/mark/MarkGroup.java index 29931e01..a0f12dcc 100644 --- a/src/main/java/seng302/models/mark/MarkGroup.java +++ b/src/main/java/seng302/models/mark/MarkGroup.java @@ -126,42 +126,42 @@ public class MarkGroup extends RaceObject { } public void updatePosition (long timeInterval) { - Circle markCircle = (Circle) super.getChildren().get(0); - - if (nodePixelVelocitiesX[0] > 0 && markCircle.getCenterX() > nodeDestinations[0].getX() || - nodePixelVelocitiesX[0] < 0 && markCircle.getCenterX() < nodeDestinations[0].getY()) - nodePixelVelocitiesX[0] = 0; - else if (nodePixelVelocitiesX[0] != 0) - markCircle.setCenterX(markCircle.getCenterX() + nodePixelVelocitiesX[0] * timeInterval); - - if (nodePixelVelocitiesY[0] > 0 && markCircle.getCenterY() > nodeDestinations[0].getY() || - nodePixelVelocitiesY[0] < 0 && markCircle.getCenterY() < nodeDestinations[0].getY()) - nodePixelVelocitiesY[0] = 0; - else if (nodePixelVelocitiesY[0] != 0) - markCircle.setCenterY(markCircle.getCenterY() + nodePixelVelocitiesY[0] * timeInterval); - - if (mainMark.getMarkType() != MarkType.SINGLE_MARK) { - - Line line = (Line) super.getChildren().get(2); - line.setStartX(markCircle.getCenterX()); - line.setStartY(markCircle.getCenterY()); - - markCircle = (Circle) super.getChildren().get(1); - - if (nodePixelVelocitiesX[1] > 0 && markCircle.getCenterX() >= nodeDestinations[1].getX() || - nodePixelVelocitiesX[1] < 0 && markCircle.getCenterX() <= nodeDestinations[1].getX()) - nodePixelVelocitiesX[1] = 0; - else if (nodePixelVelocitiesX[1] != 0) - markCircle.setCenterX(markCircle.getCenterX() + nodePixelVelocitiesX[1] * timeInterval); - - if (nodePixelVelocitiesY[1] > 0 && markCircle.getCenterY() > nodeDestinations[1].getY() || - nodePixelVelocitiesY[1] < 0 && markCircle.getCenterY() < nodeDestinations[1].getY()) - nodePixelVelocitiesY[1] = 0; - else if (nodePixelVelocitiesY[1] != 0) - markCircle.setCenterY(markCircle.getCenterY() + nodePixelVelocitiesY[1] * timeInterval); - line.setEndX(markCircle.getCenterX()); - line.setEndY(markCircle.getCenterY()); - } +// Circle markCircle = (Circle) super.getChildren().get(0); +// +// if (nodePixelVelocitiesX[0] > 0 && markCircle.getCenterX() > nodeDestinations[0].getX() || +// nodePixelVelocitiesX[0] < 0 && markCircle.getCenterX() < nodeDestinations[0].getY()) +// nodePixelVelocitiesX[0] = 0; +// else if (nodePixelVelocitiesX[0] != 0) +// markCircle.setCenterX(markCircle.getCenterX() + nodePixelVelocitiesX[0] * timeInterval); +// +// if (nodePixelVelocitiesY[0] > 0 && markCircle.getCenterY() > nodeDestinations[0].getY() || +// nodePixelVelocitiesY[0] < 0 && markCircle.getCenterY() < nodeDestinations[0].getY()) +// nodePixelVelocitiesY[0] = 0; +// else if (nodePixelVelocitiesY[0] != 0) +// markCircle.setCenterY(markCircle.getCenterY() + nodePixelVelocitiesY[0] * timeInterval); +// +// if (mainMark.getMarkType() != MarkType.SINGLE_MARK) { +// +// Line line = (Line) super.getChildren().get(2); +// line.setStartX(markCircle.getCenterX()); +// line.setStartY(markCircle.getCenterY()); +// +// markCircle = (Circle) super.getChildren().get(1); +// +// if (nodePixelVelocitiesX[1] > 0 && markCircle.getCenterX() >= nodeDestinations[1].getX() || +// nodePixelVelocitiesX[1] < 0 && markCircle.getCenterX() <= nodeDestinations[1].getX()) +// nodePixelVelocitiesX[1] = 0; +// else if (nodePixelVelocitiesX[1] != 0) +// markCircle.setCenterX(markCircle.getCenterX() + nodePixelVelocitiesX[1] * timeInterval); +// +// if (nodePixelVelocitiesY[1] > 0 && markCircle.getCenterY() > nodeDestinations[1].getY() || +// nodePixelVelocitiesY[1] < 0 && markCircle.getCenterY() < nodeDestinations[1].getY()) +// nodePixelVelocitiesY[1] = 0; +// else if (nodePixelVelocitiesY[1] != 0) +// markCircle.setCenterY(markCircle.getCenterY() + nodePixelVelocitiesY[1] * timeInterval); +// line.setEndX(markCircle.getCenterX()); +// line.setEndY(markCircle.getCenterY()); +// } } public void moveGroupBy (double x, double y, double rotation) { From 8fbb9d6d4e1d7729f44bf1484aec56252ae5da8b Mon Sep 17 00:00:00 2001 From: Calum Date: Mon, 15 May 2017 15:36:18 +1200 Subject: [PATCH 2/8] Added/improved documentation #chore --- src/main/java/seng302/models/Wake.java | 35 +++++---- .../java/seng302/models/mark/MarkGroup.java | 72 +++++++++---------- 2 files changed, 53 insertions(+), 54 deletions(-) diff --git a/src/main/java/seng302/models/Wake.java b/src/main/java/seng302/models/Wake.java index 9f6ef621..94312780 100644 --- a/src/main/java/seng302/models/Wake.java +++ b/src/main/java/seng302/models/Wake.java @@ -8,30 +8,29 @@ import javafx.scene.shape.StrokeLineCap; import javafx.scene.transform.Rotate; /** - * By default wake is a group containing 5 arcs. Each arc starts from the same point. Each arc is larger and more - * transparent than the last. On calling updatePositions() arcs rotate at velocities given by setRotationalVelocity(). - * The larger and more transparent an arc is the longer the delay before it rotates at the latest velocity. It is - * assumed that rotationalVelocities() are set regularly as wakes do not stop rotating and an array of velocities needs - * to be populated for the class to work as expected. + * A group containing objects used to represent wakes onscreen. Contains functionality for their animation. */ class Wake extends Group { - //Wake Settings. Should probably be hard coded in when the final values are decided upon. + //Wake Settings. + //Changes the relationship between separation of wakes and velocity. Only logarithmic is guaranteed to work always since it's my favourite :/. private enum functionType {LINEAR, LOGARITHMIC, POWER, ROOT, POWOUT_LOGIN} private functionType wakeFunction = functionType.LOGARITHMIC; + //Change the wake style. Currently can be ArcType.OPEN or ArcType.ROUND private ArcType arcType = ArcType.OPEN; + //The number of wakes private int numWakes = 10; - private double offSet = 0; - private final double MAX_DIFF = 75.0; + //The total possible difference between the first wake and the last. Increasing/Decreasing this will make wakes fan out more/less. + private final double MAX_DIFF = 75; + //Increasing/decreasing this will alter the speed that wakes converge when the heading stop changing. Anything over about 1500 may cause oscillation. private final int UNIFICATION_SPEED = 500; + //The power used for the power function. Changing this will probably break stuff in a cool way. private final int POWER = 2; private Arc[] arcs = new Arc[numWakes]; private double[] rotationalVelocities = new double[numWakes]; private double[] rotations = new double[numWakes]; private double baseRad; - private boolean spawnNewWake = false; - private int count = 10; /** * Create a wake at the given location. @@ -65,8 +64,8 @@ class Wake extends Group { } /** - * Sets the rotationalVelocity of each arc. Each arc is 3 velocities behind the next smallest arc. The smallest uses - * the latest given velocity. + * Sets the rotationalVelocity of each arc. + * * @param rotationalVelocity The rotationalVelocity the wake should move at. * @param velocity The real world velocity of the boat in m/s. */ @@ -89,11 +88,11 @@ class Wake extends Group { if (wakeFunction == functionType.LOGARITHMIC) { if (rotationalVelocities[i-1] < 0.01 && rotationalVelocities[i-1] > -0.01) { - rotationalVelocities[i] = (MAX_DIFF / numWakes) / UNIFICATION_SPEED * Math.log(Math.abs(difference) + 1) / Math.log(MAX_DIFF / numWakes) * 1.5; - if (difference < 0) - { - rotationalVelocities[i] = -rotationalVelocities[i]; - } + rotationalVelocities[i] = difference / UNIFICATION_SPEED * Math.log(Math.abs(difference) + 1) / Math.log(MAX_DIFF / numWakes) * 1.5; +// if (difference < 0) +// { +// rotationalVelocities[i] = -rotationalVelocities[i]; +// } } else { rotationalVelocities[i] = rotationalVelocities[i-1] * Math.log(Math.abs(difference) + 1) / Math.log(MAX_DIFF / numWakes); } @@ -148,7 +147,7 @@ class Wake extends Group { // } else { // offSet += baseRad / 5; // } - double rad = baseRad + velocity + offSet; + double rad = baseRad + velocity; for (Arc arc :arcs) { arc.setRadiusX(rad); arc.setRadiusY(rad); diff --git a/src/main/java/seng302/models/mark/MarkGroup.java b/src/main/java/seng302/models/mark/MarkGroup.java index a0f12dcc..29931e01 100644 --- a/src/main/java/seng302/models/mark/MarkGroup.java +++ b/src/main/java/seng302/models/mark/MarkGroup.java @@ -126,42 +126,42 @@ public class MarkGroup extends RaceObject { } public void updatePosition (long timeInterval) { -// Circle markCircle = (Circle) super.getChildren().get(0); -// -// if (nodePixelVelocitiesX[0] > 0 && markCircle.getCenterX() > nodeDestinations[0].getX() || -// nodePixelVelocitiesX[0] < 0 && markCircle.getCenterX() < nodeDestinations[0].getY()) -// nodePixelVelocitiesX[0] = 0; -// else if (nodePixelVelocitiesX[0] != 0) -// markCircle.setCenterX(markCircle.getCenterX() + nodePixelVelocitiesX[0] * timeInterval); -// -// if (nodePixelVelocitiesY[0] > 0 && markCircle.getCenterY() > nodeDestinations[0].getY() || -// nodePixelVelocitiesY[0] < 0 && markCircle.getCenterY() < nodeDestinations[0].getY()) -// nodePixelVelocitiesY[0] = 0; -// else if (nodePixelVelocitiesY[0] != 0) -// markCircle.setCenterY(markCircle.getCenterY() + nodePixelVelocitiesY[0] * timeInterval); -// -// if (mainMark.getMarkType() != MarkType.SINGLE_MARK) { -// -// Line line = (Line) super.getChildren().get(2); -// line.setStartX(markCircle.getCenterX()); -// line.setStartY(markCircle.getCenterY()); -// -// markCircle = (Circle) super.getChildren().get(1); -// -// if (nodePixelVelocitiesX[1] > 0 && markCircle.getCenterX() >= nodeDestinations[1].getX() || -// nodePixelVelocitiesX[1] < 0 && markCircle.getCenterX() <= nodeDestinations[1].getX()) -// nodePixelVelocitiesX[1] = 0; -// else if (nodePixelVelocitiesX[1] != 0) -// markCircle.setCenterX(markCircle.getCenterX() + nodePixelVelocitiesX[1] * timeInterval); -// -// if (nodePixelVelocitiesY[1] > 0 && markCircle.getCenterY() > nodeDestinations[1].getY() || -// nodePixelVelocitiesY[1] < 0 && markCircle.getCenterY() < nodeDestinations[1].getY()) -// nodePixelVelocitiesY[1] = 0; -// else if (nodePixelVelocitiesY[1] != 0) -// markCircle.setCenterY(markCircle.getCenterY() + nodePixelVelocitiesY[1] * timeInterval); -// line.setEndX(markCircle.getCenterX()); -// line.setEndY(markCircle.getCenterY()); -// } + Circle markCircle = (Circle) super.getChildren().get(0); + + if (nodePixelVelocitiesX[0] > 0 && markCircle.getCenterX() > nodeDestinations[0].getX() || + nodePixelVelocitiesX[0] < 0 && markCircle.getCenterX() < nodeDestinations[0].getY()) + nodePixelVelocitiesX[0] = 0; + else if (nodePixelVelocitiesX[0] != 0) + markCircle.setCenterX(markCircle.getCenterX() + nodePixelVelocitiesX[0] * timeInterval); + + if (nodePixelVelocitiesY[0] > 0 && markCircle.getCenterY() > nodeDestinations[0].getY() || + nodePixelVelocitiesY[0] < 0 && markCircle.getCenterY() < nodeDestinations[0].getY()) + nodePixelVelocitiesY[0] = 0; + else if (nodePixelVelocitiesY[0] != 0) + markCircle.setCenterY(markCircle.getCenterY() + nodePixelVelocitiesY[0] * timeInterval); + + if (mainMark.getMarkType() != MarkType.SINGLE_MARK) { + + Line line = (Line) super.getChildren().get(2); + line.setStartX(markCircle.getCenterX()); + line.setStartY(markCircle.getCenterY()); + + markCircle = (Circle) super.getChildren().get(1); + + if (nodePixelVelocitiesX[1] > 0 && markCircle.getCenterX() >= nodeDestinations[1].getX() || + nodePixelVelocitiesX[1] < 0 && markCircle.getCenterX() <= nodeDestinations[1].getX()) + nodePixelVelocitiesX[1] = 0; + else if (nodePixelVelocitiesX[1] != 0) + markCircle.setCenterX(markCircle.getCenterX() + nodePixelVelocitiesX[1] * timeInterval); + + if (nodePixelVelocitiesY[1] > 0 && markCircle.getCenterY() > nodeDestinations[1].getY() || + nodePixelVelocitiesY[1] < 0 && markCircle.getCenterY() < nodeDestinations[1].getY()) + nodePixelVelocitiesY[1] = 0; + else if (nodePixelVelocitiesY[1] != 0) + markCircle.setCenterY(markCircle.getCenterY() + nodePixelVelocitiesY[1] * timeInterval); + line.setEndX(markCircle.getCenterX()); + line.setEndY(markCircle.getCenterY()); + } } public void moveGroupBy (double x, double y, double rotation) { From c63c8e4d73036d4bec453d1c8082c2d5732b8e06 Mon Sep 17 00:00:00 2001 From: Calum Date: Wed, 17 May 2017 16:33:45 +1200 Subject: [PATCH 3/8] Stripped out excess code in Wake class. --- src/main/java/seng302/models/BoatGroup.java | 34 +++++-- src/main/java/seng302/models/Wake.java | 102 ++++---------------- 2 files changed, 44 insertions(+), 92 deletions(-) diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index 70b979ff..cc6b3e22 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -1,6 +1,7 @@ package seng302.models; import javafx.geometry.Point2D; +import javafx.scene.CacheHint; import javafx.scene.Group; import javafx.scene.paint.Color; import javafx.scene.shape.Line; @@ -47,6 +48,10 @@ public class BoatGroup extends RaceObject{ private boolean isMaximized= true; private List lineStorage = new ArrayList<>(); private int setCallCount = 5; + private int frameCount = 90; + + private double lastX; + private double lastY; /** * Creates a BoatGroup with the default triangular boat polygon. @@ -80,9 +85,16 @@ public class BoatGroup extends RaceObject{ private void initChildren (Color color, double... points) { boatPoly = new Polygon(points); boatPoly.setFill(color); + boatPoly.setCache(true); + boatPoly.setCacheHint(CacheHint.SPEED); + teamNameObject = new Text(boat.getShortName()); + teamNameObject.setCache(true); + teamNameObject.setCacheHint(CacheHint.SPEED); velocityObject = new Text(String.valueOf(boat.getVelocity())); + velocityObject.setCache(true); + velocityObject.setCacheHint(CacheHint.SPEED); teamNameObject.setX(TEAMNAME_X_OFFSET); teamNameObject.setY(TEAMNAME_Y_OFFSET); @@ -114,8 +126,8 @@ public class BoatGroup extends RaceObject{ * @param dy The amount to move the Y coordinate by */ public void moveGroupBy(double dx, double dy, double rotation) { - boatPoly.setLayoutX(boatPoly.getLayoutX() + dx); - boatPoly.setLayoutY(boatPoly.getLayoutY() + dy); + boatPoly.setLayoutX(lastX + dx); + boatPoly.setLayoutY(lastY + dy); teamNameObject.setLayoutX(teamNameObject.getLayoutX() + dx); teamNameObject.setLayoutY(teamNameObject.getLayoutY() + dy); velocityObject.setLayoutX(velocityObject.getLayoutX() + dx); @@ -166,21 +178,21 @@ public class BoatGroup extends RaceObject{ distanceTravelled += Math.abs(dx) + Math.abs(dy); moveGroupBy(dx, dy, rotation); //Draw a new section of the trail every 20 pixels of movement. - if (distanceTravelled > 20) { - distanceTravelled = 0; + if (frameCount-- == 0) { + frameCount = (int) (300 - boat.getVelocity() * 10); if (lastPoint != null) { Line l = new Line( lastPoint.getX(), lastPoint.getY(), - boatPoly.getLayoutX(), - boatPoly.getLayoutY() + lastX, + lastY ); l.getStrokeDashArray().setAll(3d, 7d); l.setStroke(boatPoly.getFill()); lineGroup.getChildren().add(l); } if (destinationSet) { //Only begin drawing after the first destination is set - lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY()); + lastPoint = new Point2D(lastX, lastY); } } wake.updatePosition(timeInterval); @@ -201,8 +213,8 @@ public class BoatGroup extends RaceObject{ boat.setVelocity(groundSpeed); if (currentRotation < 0) currentRotation = 360 - currentRotation; - double dx = newXValue - boatPoly.getLayoutX(); - double dy = newYValue - boatPoly.getLayoutY(); + double dx = newXValue - lastX; + double dy = newYValue - lastY; //Check movement is reasonable. Assumes a 1000 * 1000 canvas // if (Math.abs(dx) > 50 || Math.abs(dy) > 50) { // dx = 0; @@ -212,6 +224,8 @@ public class BoatGroup extends RaceObject{ pixelVelocityX = dx / expectedUpdateInterval; pixelVelocityY = dy / expectedUpdateInterval; + lastX = newXValue; + lastY = newYValue; rotationalGoal = rotation; calculateRotationalVelocity(); if (Math.abs(rotationalVelocity) > 0.075) { @@ -259,7 +273,7 @@ public class BoatGroup extends RaceObject{ double rotation = Math.abs( Math.toDegrees( Math.atan( - (newYValue - boatPoly.getLayoutY()) / (newXValue - boatPoly.getLayoutX()) + (newYValue - lastY) / (newXValue - lastX) ) ) ); diff --git a/src/main/java/seng302/models/Wake.java b/src/main/java/seng302/models/Wake.java index 94312780..664e7501 100644 --- a/src/main/java/seng302/models/Wake.java +++ b/src/main/java/seng302/models/Wake.java @@ -1,5 +1,6 @@ package seng302.models; +import javafx.scene.CacheHint; import javafx.scene.Group; import javafx.scene.paint.Color; import javafx.scene.shape.Arc; @@ -12,20 +13,13 @@ import javafx.scene.transform.Rotate; */ class Wake extends Group { - //Wake Settings. - //Changes the relationship between separation of wakes and velocity. Only logarithmic is guaranteed to work always since it's my favourite :/. - private enum functionType {LINEAR, LOGARITHMIC, POWER, ROOT, POWOUT_LOGIN} - private functionType wakeFunction = functionType.LOGARITHMIC; - //Change the wake style. Currently can be ArcType.OPEN or ArcType.ROUND - private ArcType arcType = ArcType.OPEN; //The number of wakes - private int numWakes = 10; + private int numWakes = 8; //The total possible difference between the first wake and the last. Increasing/Decreasing this will make wakes fan out more/less. private final double MAX_DIFF = 75; //Increasing/decreasing this will alter the speed that wakes converge when the heading stop changing. Anything over about 1500 may cause oscillation. private final int UNIFICATION_SPEED = 500; - //The power used for the power function. Changing this will probably break stuff in a cool way. - private final int POWER = 2; + private Arc[] arcs = new Arc[numWakes]; private double[] rotationalVelocities = new double[numWakes]; @@ -34,6 +28,7 @@ class Wake extends Group { /** * Create a wake at the given location. + * * @param startingX x location where the tip of wake arcs will be. * @param startingY y location where the tip of wake arcs will be. */ @@ -44,21 +39,15 @@ class Wake extends Group { for (int i = 0; i < numWakes; i++) { //Default triangle is -110 deg out of phase with a default wake and has angle of 40 deg. arc = new Arc(0, 0, 0, 0, -110, 40); - - if (arcType == ArcType.ROUND) { - arc.setFill(new Color(0.18, 0.7, 1.0, 0.4 + (-0.35 / numWakes * i))); - arc.setType(ArcType.ROUND); - baseRad = 10; - - } else if (arcType == ArcType.OPEN) { - arc.setType(ArcType.OPEN); - arc.setStroke(new Color(0.18, 0.7, 1.0, 1.0 + (-0.99 / numWakes * i))); - arc.setStrokeWidth(3.0); - arc.setStrokeLineCap(StrokeLineCap.ROUND); - arc.setFill(new Color(0.0, 0.0, 0.0, 0.0)); - baseRad = (20 / numWakes); - arcs[i] = arc; - } + arc.setCache(true); + arc.setCacheHint(CacheHint.SPEED); + arc.setType(ArcType.OPEN); + arc.setStroke(new Color(0.18, 0.7, 1.0, 1.0 + (-0.99 / numWakes * i))); + arc.setStrokeWidth(3.0); + arc.setStrokeLineCap(StrokeLineCap.ROUND); + arc.setFill(new Color(0.0, 0.0, 0.0, 0.0)); + baseRad = (20 / numWakes); + arcs[i] = arc; } super.getChildren().addAll(arcs); } @@ -86,67 +75,17 @@ class Wake extends Group { ); difference = Math.toDegrees(difference); - if (wakeFunction == functionType.LOGARITHMIC) { - if (rotationalVelocities[i-1] < 0.01 && rotationalVelocities[i-1] > -0.01) { - rotationalVelocities[i] = difference / UNIFICATION_SPEED * Math.log(Math.abs(difference) + 1) / Math.log(MAX_DIFF / numWakes) * 1.5; -// if (difference < 0) -// { -// rotationalVelocities[i] = -rotationalVelocities[i]; -// } - } else { - rotationalVelocities[i] = rotationalVelocities[i-1] * Math.log(Math.abs(difference) + 1) / Math.log(MAX_DIFF / numWakes); - } + if (rotationalVelocities[i-1] < 0.01 && rotationalVelocities[i-1] > -0.01) { + rotationalVelocities[i] = difference / UNIFICATION_SPEED * Math.log(Math.abs(difference) + 1) / Math.log(MAX_DIFF / numWakes) * 1.5; - } else if (wakeFunction == functionType.LINEAR) { - if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) { - rotationalVelocities[i] = difference / UNIFICATION_SPEED * 2; - } else { - if (difference < (MAX_DIFF / numWakes)) - rotationalVelocities[i] = rotationalVelocities[i - 1] * difference / (MAX_DIFF / numWakes); - else - rotationalVelocities[i] = rotationalVelocities[i - 1]; - } - } else if (wakeFunction == functionType.POWER) { - if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) { - rotationalVelocities[i] = difference / UNIFICATION_SPEED * Math.pow(difference, POWER) / Math.pow((MAX_DIFF / numWakes), POWER); - } else { - if (difference < (MAX_DIFF / numWakes)) - rotationalVelocities[i] = rotationalVelocities[i - 1] * Math.pow(difference, POWER) / Math.pow((MAX_DIFF / numWakes), POWER); - else - rotationalVelocities[i] = rotationalVelocities[i - 1]; - } - } else if (wakeFunction == functionType.ROOT) { - if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) { - rotationalVelocities[i] = (MAX_DIFF / numWakes) / UNIFICATION_SPEED * Math.sqrt(Math.abs(difference)) / Math.sqrt(MAX_DIFF / numWakes); - } else { - if (difference < (MAX_DIFF / numWakes)) - rotationalVelocities[i] = rotationalVelocities[i - 1] * Math.sqrt(Math.abs(difference)) / Math.sqrt(MAX_DIFF / numWakes); - else - rotationalVelocities[i] = rotationalVelocities[i - 1]; - } - if (difference < 0) - rotationalVelocities[i] = -rotationalVelocities[i]; - } else if (wakeFunction == functionType.POWOUT_LOGIN) { - if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) { - rotationalVelocities[i] = difference / UNIFICATION_SPEED * Math.log(Math.abs(difference) + 1) / Math.log(MAX_DIFF / numWakes); - } else { - if (difference < (MAX_DIFF / numWakes)) - rotationalVelocities[i] = rotationalVelocities[i - 1] * Math.pow(difference, POWER) / Math.pow((MAX_DIFF / numWakes), POWER); - else - rotationalVelocities[i] = rotationalVelocities[i - 1]; - } + } else { + if (difference < (MAX_DIFF / numWakes)) + rotationalVelocities[i] = rotationalVelocities[i-1] * Math.log(Math.abs(difference) + 1) / Math.log(MAX_DIFF / numWakes); + else + rotationalVelocities[i] = rotationalVelocities[i - 1]; } - } - //Scale wakes based on velocity. -// if (count-- == 0) -// { -// count = 10; -// offSet = 0; -// } else { -// offSet += baseRad / 5; -// } double rad = baseRad + velocity; for (Arc arc :arcs) { arc.setRadiusX(rad); @@ -177,5 +116,4 @@ class Wake extends Group { arcs[i].getTransforms().setAll(new Rotate(rotation)); } } - } From 7c39368126ebf15519c92cc07a2406a1897038b3 Mon Sep 17 00:00:00 2001 From: Calum Date: Wed, 17 May 2017 17:23:10 +1200 Subject: [PATCH 4/8] Removed unnecessary constant --- src/main/java/seng302/models/BoatGroup.java | 43 +++++++++---------- src/main/java/seng302/models/Wake.java | 2 +- .../seng302/models/parsers/StreamParser.java | 5 ++- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index cc6b3e22..d4c08344 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -48,10 +48,6 @@ public class BoatGroup extends RaceObject{ private boolean isMaximized= true; private List lineStorage = new ArrayList<>(); private int setCallCount = 5; - private int frameCount = 90; - - private double lastX; - private double lastY; /** * Creates a BoatGroup with the default triangular boat polygon. @@ -126,8 +122,8 @@ public class BoatGroup extends RaceObject{ * @param dy The amount to move the Y coordinate by */ public void moveGroupBy(double dx, double dy, double rotation) { - boatPoly.setLayoutX(lastX + dx); - boatPoly.setLayoutY(lastY + dy); + boatPoly.setLayoutX(boatPoly.getLayoutX() + dx); + boatPoly.setLayoutY(boatPoly.getLayoutY() + dy); teamNameObject.setLayoutX(teamNameObject.getLayoutX() + dx); teamNameObject.setLayoutY(teamNameObject.getLayoutY() + dy); velocityObject.setLayoutX(velocityObject.getLayoutX() + dx); @@ -178,21 +174,26 @@ public class BoatGroup extends RaceObject{ distanceTravelled += Math.abs(dx) + Math.abs(dy); moveGroupBy(dx, dy, rotation); //Draw a new section of the trail every 20 pixels of movement. - if (frameCount-- == 0) { - frameCount = (int) (300 - boat.getVelocity() * 10); + if (distanceTravelled > 20) { + distanceTravelled = 0; if (lastPoint != null) { Line l = new Line( - lastPoint.getX(), - lastPoint.getY(), - lastX, - lastY + lastPoint.getX() * 3 - 1000, + lastPoint.getY() * 3 - 1000, + boatPoly.getLayoutX() * 3 - 1000, + boatPoly.getLayoutY() * 3 - 1000 ); l.getStrokeDashArray().setAll(3d, 7d); l.setStroke(boatPoly.getFill()); + if (lastPoint.getX() * 3 - 1000 < 0 || lastPoint.getY() * 3 - 1000 < 0 || boatPoly.getLayoutX() * 3 - 1000 < 0 || boatPoly.getLayoutY() * 3 - 1000 < 0) + l.setVisible(false); + else + l.setVisible(true); + lineGroup.getChildren().add(l); } if (destinationSet) { //Only begin drawing after the first destination is set - lastPoint = new Point2D(lastX, lastY); + lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY()); } } wake.updatePosition(timeInterval); @@ -213,8 +214,8 @@ public class BoatGroup extends RaceObject{ boat.setVelocity(groundSpeed); if (currentRotation < 0) currentRotation = 360 - currentRotation; - double dx = newXValue - lastX; - double dy = newYValue - lastY; + double dx = newXValue - boatPoly.getLayoutX(); + double dy = newYValue - boatPoly.getLayoutY(); //Check movement is reasonable. Assumes a 1000 * 1000 canvas // if (Math.abs(dx) > 50 || Math.abs(dy) > 50) { // dx = 0; @@ -224,8 +225,6 @@ public class BoatGroup extends RaceObject{ pixelVelocityX = dx / expectedUpdateInterval; pixelVelocityY = dy / expectedUpdateInterval; - lastX = newXValue; - lastY = newYValue; rotationalGoal = rotation; calculateRotationalVelocity(); if (Math.abs(rotationalVelocity) > 0.075) { @@ -250,10 +249,10 @@ public class BoatGroup extends RaceObject{ setCallCount = 5; if (lastPoint != null) { Line l = new Line( - lastPoint.getX(), - lastPoint.getY(), - newXValue, - newYValue + lastPoint.getX() * 1.5, + lastPoint.getY() * 1.5, + newXValue * 1.5, + newYValue * 1.5 ); l.getStrokeDashArray().setAll(3d, 7d); l.setStroke(boatPoly.getFill()); @@ -273,7 +272,7 @@ public class BoatGroup extends RaceObject{ double rotation = Math.abs( Math.toDegrees( Math.atan( - (newYValue - lastY) / (newXValue - lastX) + (newYValue - boatPoly.getLayoutY()) / (newXValue - boatPoly.getLayoutX()) ) ) ); diff --git a/src/main/java/seng302/models/Wake.java b/src/main/java/seng302/models/Wake.java index 664e7501..7c9bb14c 100644 --- a/src/main/java/seng302/models/Wake.java +++ b/src/main/java/seng302/models/Wake.java @@ -18,7 +18,7 @@ class Wake extends Group { //The total possible difference between the first wake and the last. Increasing/Decreasing this will make wakes fan out more/less. private final double MAX_DIFF = 75; //Increasing/decreasing this will alter the speed that wakes converge when the heading stop changing. Anything over about 1500 may cause oscillation. - private final int UNIFICATION_SPEED = 500; + private final int UNIFICATION_SPEED = 750; private Arc[] arcs = new Arc[numWakes]; diff --git a/src/main/java/seng302/models/parsers/StreamParser.java b/src/main/java/seng302/models/parsers/StreamParser.java index deea3184..12e4b538 100644 --- a/src/main/java/seng302/models/parsers/StreamParser.java +++ b/src/main/java/seng302/models/parsers/StreamParser.java @@ -17,6 +17,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.PriorityBlockingQueue; /** @@ -36,8 +37,8 @@ public class StreamParser extends Thread{ private static boolean raceFinished = false; private static boolean streamStatus = false; private static long timeSinceStart = -1; - private static Map boats = new HashMap<>(); - private static Map boatsPos = new TreeMap<>(); + private static Map boats = new ConcurrentHashMap<>(); + private static Map boatsPos = new ConcurrentSkipListMap<>(); private static double windDirection = 0; private static String currentTimeString; private static boolean appRunning; From f41858e2c7a2087422887cd58fb92b78b9386b29 Mon Sep 17 00:00:00 2001 From: Calum Date: Wed, 17 May 2017 17:35:59 +1200 Subject: [PATCH 5/8] Tidied variable names. --- src/main/java/seng302/models/Wake.java | 37 +++++++++++--------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/main/java/seng302/models/Wake.java b/src/main/java/seng302/models/Wake.java index 7c9bb14c..630b075a 100644 --- a/src/main/java/seng302/models/Wake.java +++ b/src/main/java/seng302/models/Wake.java @@ -56,38 +56,31 @@ class Wake extends Group { * Sets the rotationalVelocity of each arc. * * @param rotationalVelocity The rotationalVelocity the wake should move at. - * @param velocity The real world velocity of the boat in m/s. + * @param velocity The real world velocity of the boat in m/s. */ - void setRotationalVelocity (double rotationalVelocity, double velocity) { + void setRotationalVelocity(double rotationalVelocity, double velocity) { rotationalVelocities[0] = rotationalVelocity; for (int i = 1; i < numWakes; i++) { - double difference = Math.atan2( - Math.sin( - Math.toRadians( - rotations[i - 1] - rotations[i] - ) - ), - Math.cos( - Math.toRadians( - rotations[i - 1] - rotations[i] - ) - ) + double wakeSeparationRad = Math.toRadians(rotations[i - 1] - rotations[i]); + double shortestDistance = Math.atan2( + Math.sin(wakeSeparationRad), + Math.cos(wakeSeparationRad) ); - difference = Math.toDegrees(difference); + double distDeg = Math.toDegrees(shortestDistance); - if (rotationalVelocities[i-1] < 0.01 && rotationalVelocities[i-1] > -0.01) { - rotationalVelocities[i] = difference / UNIFICATION_SPEED * Math.log(Math.abs(difference) + 1) / Math.log(MAX_DIFF / numWakes) * 1.5; + if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) { + rotationalVelocities[i] = distDeg / UNIFICATION_SPEED * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes); } else { - if (difference < (MAX_DIFF / numWakes)) - rotationalVelocities[i] = rotationalVelocities[i-1] * Math.log(Math.abs(difference) + 1) / Math.log(MAX_DIFF / numWakes); + if (distDeg < (MAX_DIFF / numWakes)) + rotationalVelocities[i] = rotationalVelocities[i - 1] * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes); else rotationalVelocities[i] = rotationalVelocities[i - 1]; } } double rad = baseRad + velocity; - for (Arc arc :arcs) { + for (Arc arc : arcs) { arc.setRadiusX(rad); arc.setRadiusY(rad); rad += (20 / numWakes) + (velocity / 2); @@ -96,9 +89,10 @@ class Wake extends Group { /** * Arcs rotate based on the distance they would have travelled over the supplied time interval. + * * @param timeInterval the time interval, in microseconds, that the wake should move. */ - void updatePosition (long timeInterval) { + void updatePosition(long timeInterval) { for (int i = 0; i < numWakes; i++) { rotations[i] = rotations[i] + rotationalVelocities[i] * timeInterval; arcs[i].getTransforms().setAll(new Rotate(rotations[i])); @@ -107,9 +101,10 @@ class Wake extends Group { /** * Rotate all wakes to the given rotation. + * * @param rotation the from north angle in degrees to rotate to. */ - void rotate (double rotation) { + void rotate(double rotation) { for (int i = 0; i < arcs.length; i++) { rotations[i] = rotation; rotationalVelocities[i] = 0; From 8a3a41294aa2bcba5d8720b0ba078b57b044c5af Mon Sep 17 00:00:00 2001 From: Calum Date: Wed, 17 May 2017 17:41:45 +1200 Subject: [PATCH 6/8] Fixed error causing build failure. #story[923] #bug #refactor --- src/main/java/seng302/models/BoatGroup.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index b2d72099..57950f24 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -286,8 +286,7 @@ public class BoatGroup extends RaceObject { rotationalVelocity = 0; wakeGenerationDelay--; } else { - wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, - boat.getVelocity()); + wake.setRotationalVelocity(rotationalVelocity, boat.getVelocity()); rotateTo(rotationalGoal); wake.rotate(rotationalGoal); } From 45db731a60f65db00d9b0da3d6d0c4b25dc20785 Mon Sep 17 00:00:00 2001 From: Calum Date: Wed, 17 May 2017 18:06:36 +1200 Subject: [PATCH 7/8] Fixed a merge issue. #story[923] #bug #refactor --- src/main/java/seng302/App.java | 4 +- src/main/java/seng302/models/BoatGroup.java | 82 ++++++--------------- 2 files changed, 26 insertions(+), 60 deletions(-) diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index 3625db47..deb5656f 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -62,8 +62,8 @@ public class App extends Application { } //Change the StreamReceiver in this else block to change the default data source. else{ -// sr = new StreamReceiver("localhost", 4949, "RaceStream"); - sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); + sr = new StreamReceiver("localhost", 4949, "RaceStream"); +// sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); } sr.start(); diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index 57950f24..8a1446d0 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -222,33 +222,30 @@ public class BoatGroup extends RaceObject { * on. */ public void updatePosition(long timeInterval) { - //Calculate the movement of the boat. - if (isMaximized) { - double dx = pixelVelocityX * timeInterval; - double dy = pixelVelocityY * timeInterval; - double rotation = rotationalVelocity * timeInterval; - distanceTravelled += Math.abs(dx) + Math.abs(dy); - moveGroupBy(dx, dy, rotation); - //Draw a new section of the trail every 20 pixels of movement. - if (distanceTravelled > 20) { - distanceTravelled = 0; - if (lastPoint != null) { - Line l = new Line( - lastPoint.getX(), - lastPoint.getY(), - boatPoly.getLayoutX(), - boatPoly.getLayoutY() - ); - l.getStrokeDashArray().setAll(3d, 7d); - l.setStroke(boat.getColour()); - lineGroup.getChildren().add(l); - } - if (destinationSet) { //Only begin drawing after the first destination is set - lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY()); - } + double dx = pixelVelocityX * timeInterval; + double dy = pixelVelocityY * timeInterval; + double rotation = rotationalVelocity * timeInterval; + distanceTravelled += Math.abs(dx) + Math.abs(dy); + moveGroupBy(dx, dy, rotation); + //Draw a new section of the trail every 20 pixels of movement. + if (distanceTravelled > 20) { + distanceTravelled = 0; + if (lastPoint != null) { + Line l = new Line( + lastPoint.getX(), + lastPoint.getY(), + boatPoly.getLayoutX(), + boatPoly.getLayoutY() + ); + l.getStrokeDashArray().setAll(3d, 7d); + l.setStroke(boat.getColour()); + lineGroup.getChildren().add(l); + } + if (destinationSet) { //Only begin drawing after the first destination is set + lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY()); } - wake.updatePosition(timeInterval); } + wake.updatePosition(timeInterval); } /** @@ -265,28 +262,18 @@ public class BoatGroup extends RaceObject { if (setToInitialLocation) { destinationSet = true; boat.setVelocity(groundSpeed); - if (currentRotation < 0) { - currentRotation = 360 - currentRotation; - } double dx = newXValue - boatPoly.getLayoutX(); double dy = newYValue - boatPoly.getLayoutY(); - //Check movement is reasonable. Assumes a 1000 * 1000 canvas -// if (Math.abs(dx) > 50 || Math.abs(dy) > 50) { -// dx = 0; -// dy = 0; -// moveTo(newXValue, newYValue); -// } + pixelVelocityX = dx / expectedUpdateInterval; pixelVelocityY = dy / expectedUpdateInterval; rotationalGoal = rotation; calculateRotationalVelocity(); + if (Math.abs(rotationalVelocity) > 0.075) { System.out.println("rotationalVelocity = " + rotationalVelocity); rotationalVelocity = 0; - wakeGenerationDelay--; - } else { - wake.setRotationalVelocity(rotationalVelocity, boat.getVelocity()); rotateTo(rotationalGoal); wake.rotate(rotationalGoal); } @@ -312,27 +299,6 @@ public class BoatGroup extends RaceObject { } } //If minimized generate lines every 5 calls to set destination. - if (!isMaximized) { - setToInitialLocation = false; - wakeGenerationDelay = 2; - if (setCallCount-- == 0) { - setCallCount = 5; - if (lastPoint != null) { - Line l = new Line( - lastPoint.getX(), - lastPoint.getY(), - newXValue, - newYValue - ); - l.getStrokeDashArray().setAll(3d, 7d); - l.setStroke(boatPoly.getFill()); - lineStorage.add(l); - } - if (destinationSet) { //Only begin drawing after the first destination is set - lastPoint = new Point2D(newXValue, newYValue); - } - } - } } public void setDestination(double newXValue, double newYValue, double groundSpeed, From 73eeeb0ef9200b763f8fe53c98ed78852f2e0252 Mon Sep 17 00:00:00 2001 From: Michael Rausch Date: Thu, 18 May 2017 11:45:06 +1200 Subject: [PATCH 8/8] Removed extra print stmt and changed default server back to official --- src/main/java/seng302/App.java | 4 ++-- src/main/java/seng302/models/BoatGroup.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index deb5656f..afcd3430 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -62,8 +62,8 @@ public class App extends Application { } //Change the StreamReceiver in this else block to change the default data source. else{ - sr = new StreamReceiver("localhost", 4949, "RaceStream"); -// sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); + //sr = new StreamReceiver("localhost", 4949, "RaceStream"); + sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); } sr.start(); diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index 8a1446d0..767ca893 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -272,7 +272,6 @@ public class BoatGroup extends RaceObject { calculateRotationalVelocity(); if (Math.abs(rotationalVelocity) > 0.075) { - System.out.println("rotationalVelocity = " + rotationalVelocity); rotationalVelocity = 0; rotateTo(rotationalGoal); wake.rotate(rotationalGoal);