From b9900925b865182ed0c159e1cd3ef9b562657747 Mon Sep 17 00:00:00 2001 From: Calum Date: Sun, 30 Apr 2017 19:00:07 +1200 Subject: [PATCH] Fixing wakes, bug caused by attempting to fix a issue with jittery boats actually caused by parser. #bug --- src/main/java/seng302/App.java | 4 +-- src/main/java/seng302/models/BoatGroup.java | 39 ++++++--------------- src/main/java/seng302/models/Wake.java | 17 ++++++--- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index f6630e7c..525b0c5b 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -18,8 +18,8 @@ public class App extends Application primaryStage.setScene(new Scene(root)); primaryStage.show(); -// StreamReceiver sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941,"TestThread1"); - StreamReceiver sr = new StreamReceiver("livedata.americascup.com", 4941, "TestThread1"); + StreamReceiver sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941,"TestThread1"); +// StreamReceiver sr = new StreamReceiver("livedata.americascup.com", 4941, "TestThread1"); sr.start(); StreamParser streamParser = new StreamParser("TestThread2"); streamParser.start(); diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index 0cdb6d82..80491fc9 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -18,23 +18,18 @@ public class BoatGroup extends RaceObject{ 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; - private static final int LINE_INTERVAL = 180; + private static final int LINE_INTERVAL = 30; private static double expectedUpdateInterval = 200; - private static int WAKE_FRAME_INTERVAL = 30; private double framesForNewLine = 0; private boolean destinationSet; private Point2D lastPoint; private int wakeGenerationDelay; private Boat boat; - private int wakeCounter = WAKE_FRAME_INTERVAL; private Group lineGroup = new Group(); - private Group wakeGroup = new Group(); private Polygon boatPoly; - private Polygon wakePoly; private Text teamNameObject; private Text velocityObject; private Wake wake; @@ -113,7 +108,7 @@ public class BoatGroup extends RaceObject{ velocityObject.setLayoutY(y); wake.setLayoutX(x); wake.setLayoutY(y); - wake.rotate(currentRotation); + //wake.rotate(currentRotation); } public void updatePosition (long timeInterval) { @@ -139,7 +134,7 @@ public class BoatGroup extends RaceObject{ if (destinationSet){ lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY()); } - if (lineGroup.getChildren().size() > 100) + if (lineGroup.getChildren().size() > 80) lineGroup.getChildren().remove(0); } wake.updatePosition(timeInterval); @@ -154,13 +149,14 @@ public class BoatGroup extends RaceObject{ this.pixelVelocityY = (newYValue - boatPoly.getLayoutY()) / expectedUpdateInterval; this.rotationalGoal = rotation; calculateRotationalVelocity(); + System.out.println("rotationalVelocity = " + rotationalVelocity); rotateTo(rotation); - if (wakeGenerationDelay > 0) { - wake.rotate(rotationalGoal); - wakeGenerationDelay--; - } else { +// if (wakeGenerationDelay > 0) { +// wake.rotate(rotationalGoal); +// wakeGenerationDelay--; +// } else { wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, pixelVelocityX, pixelVelocityY); - } +// } } } @@ -179,21 +175,6 @@ public class BoatGroup extends RaceObject{ } } - void resizeWake(){ - velocityObject.setText(String.valueOf(boat.getVelocity())); - super.getChildren().remove(wakePoly); - wakePoly = new Polygon( - 5.0,0.0, - 10.0, boat.getVelocity() * VELOCITY_WAKE_RATIO, - 0.0, boat.getVelocity() * VELOCITY_WAKE_RATIO - ); - wakePoly.setLayoutX(boatPoly.getLayoutX()); - wakePoly.setLayoutY(boatPoly.getLayoutY()); - wakePoly.setFill(Color.DARKBLUE); - super.getChildren().add(wakePoly); - - } - public void rotateTo (double rotation) { currentRotation = rotation; boatPoly.getTransforms().clear(); @@ -204,7 +185,7 @@ public class BoatGroup extends RaceObject{ public void forceRotation () { rotateTo (rotationalGoal); - wake.rotate(rotationalGoal); + //wake.rotate(rotationalGoal); } public void toggleAnnotations () { diff --git a/src/main/java/seng302/models/Wake.java b/src/main/java/seng302/models/Wake.java index 3c79d3a9..44c8d538 100644 --- a/src/main/java/seng302/models/Wake.java +++ b/src/main/java/seng302/models/Wake.java @@ -50,10 +50,13 @@ class Wake extends Group { void setRotationalVelocity (double rotationalVelocity, double rotationGoal, double velocityX, double velocityY) { sum -= Math.abs(velocities[velocityIndices[0]]); 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. - + if (sum < 0.0001) { + System.out.println("***************************************************************************"); + System.out.println(sum); + System.out.println("***************************************************************************"); + 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. + } //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; @@ -81,6 +84,12 @@ class Wake extends Group { rotations[i] = rotations[i] + velocities[velocityIndices[i]] * timeInterval; arcs[i].getTransforms().setAll(new Rotate(rotations[i])); } + System.out.println("rotations[0] = " + rotations[0]); + System.out.println("rotations[1] = " + rotations[1]); + System.out.println("rotations[2] = " + rotations[2]); + System.out.println("rotations[3] = " + rotations[3]); + System.out.println("rotations[4] = " + rotations[4]); + } /**