Fixed boats moving in the correct heading as according to the stream and attempted to fix the wakes direction.

#story[818]
This commit is contained in:
Kusal Ekanayake
2017-04-27 18:52:37 +12:00
parent 0a22812165
commit d1289b0de1
6 changed files with 62 additions and 41 deletions
-1
View File
@@ -22,7 +22,6 @@ public class App extends Application
StreamReceiver sr = new StreamReceiver("livedata.americascup.com", 4941, "TestThread1");
sr.start();
StreamParser streamParser = new StreamParser("TestThread2");
streamParser.start();
}
@@ -39,7 +39,7 @@ public class CanvasController {
private GraphicsContext gc;
private final int MARK_SIZE = 10;
private final int BUFFER_SIZE = 25;
private final int BUFFER_SIZE = 100;
private final int CANVAS_WIDTH = 1000;
private final int CANVAS_HEIGHT = 1000;
private final int LHS_BUFFER = BUFFER_SIZE;
@@ -596,7 +596,7 @@ public class CanvasController {
//System.out.println("3");
// System.out.println(distanceFromReference);
angleFromReference = Math.abs(angleFromReference);
System.out.println(Math.cos(angleFromReference) * distanceFromReference);
// System.out.println(Math.cos(angleFromReference) * distanceFromReference);
xAxisLocation -= (int) Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
yAxisLocation -= (int) Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
} else {
+35 -30
View File
@@ -35,7 +35,7 @@ public class BoatGroup extends RaceObject{
private List<Wake> wakes = new ArrayList<>();
private List<Line> lines = new ArrayList<>();
private Polygon boatPoly;
private Polygon wakePoly;
// private Polygon wakePoly;
private Text teamNameObject;
private Text velocityObject;
@@ -55,13 +55,13 @@ public class BoatGroup extends RaceObject{
// boatPoly.setLayoutX(0);
// boatPoly.setLayoutY(0);
// boatPoly.relocate(boatPoly.getLayoutX(), boatPoly.getLayoutY());
wakePoly = new Polygon(
5.0,0.0,
10.0, boat.getVelocity() * VELOCITY_WAKE_RATIO,
0.0, boat.getVelocity() * VELOCITY_WAKE_RATIO
);
wakePoly.setFill(Color.DARKBLUE);
//
// wakePoly = new Polygon(
// 5.0,0.0,
// 10.0, boat.getVelocity() * VELOCITY_WAKE_RATIO,
// 0.0, boat.getVelocity() * VELOCITY_WAKE_RATIO
// );
// wakePoly.setFill(Color.DARKBLUE);
teamNameObject = new Text(boat.getShortName());
velocityObject = new Text(String.valueOf(boat.getVelocity()));
@@ -74,7 +74,8 @@ public class BoatGroup extends RaceObject{
velocityObject.setY(VELOCITY_Y_OFFSET);
velocityObject.relocate(velocityObject.getX(), velocityObject.getY());
super.getChildren().addAll(wakePoly, boatPoly, teamNameObject, velocityObject);
// super.getChildren().addAll(wakePoly, boatPoly, teamNameObject, velocityObject);
super.getChildren().addAll(teamNameObject, velocityObject, boatPoly);
}
private void initChildren (Color color) {
@@ -96,9 +97,9 @@ public class BoatGroup extends RaceObject{
teamNameObject.setLayoutY(teamNameObject.getLayoutY() + dy);
velocityObject.setLayoutX(velocityObject.getLayoutX() + dx);
velocityObject.setLayoutY(velocityObject.getLayoutY() + dy);
wakePoly.setLayoutX(wakePoly.getLayoutX() + dx);
wakePoly.setLayoutY(wakePoly.getLayoutY() + dy);
rotateTo(currentRotation + rotation);
// wakePoly.setLayoutX(wakePoly.getLayoutX() + dx);
// wakePoly.setLayoutY(wakePoly.getLayoutY() + dy);
rotateTo(currentRotation);
}
/**
@@ -109,7 +110,6 @@ public class BoatGroup extends RaceObject{
public void moveTo (double x, double y, double rotation) {
rotateTo(rotation);
moveTo(x, y);
}
public void moveTo (double x, double y) {
@@ -119,8 +119,8 @@ public class BoatGroup extends RaceObject{
teamNameObject.setLayoutY(y);
velocityObject.setLayoutX(x);
velocityObject.setLayoutY(y);
wakePoly.setLayoutX(x);
wakePoly.setLayoutY(y);
// wakePoly.setLayoutX(x);
// wakePoly.setLayoutY(y);
}
public void updatePosition (double timeInterval) {
@@ -158,9 +158,9 @@ public class BoatGroup extends RaceObject{
boatPoly.getLayoutX(),
boatPoly.getLayoutY(),
pixelVelocityX,
pixelVelocityY,
currentRotation
);
pixelVelocityY, rotation);
// wake.getTransforms().clear();
// wake.getTransforms().add(new Rotate(rotation, 0, 0));
super.getChildren().add(wake);
wakes.add(wake);
}
@@ -186,6 +186,7 @@ public class BoatGroup extends RaceObject{
this.pixelVelocityY = (newYValue - boatPoly.getLayoutY()) / expectedUpdateInterval;
this.rotationalGoal = rotation;
calculateRotationalVelocity();
rotateTo(rotation);
}
}
@@ -198,23 +199,27 @@ public class BoatGroup extends RaceObject{
)
)
);
if (boatPoly.getLayoutY() >= newYValue && boatPoly.getLayoutX() <= newXValue)
rotation = 90 - rotation;
else if (boatPoly.getLayoutY() < newYValue && boatPoly.getLayoutX() <= newXValue)
rotation = 90 + rotation;
else if (boatPoly.getLayoutY() >= newYValue && boatPoly.getLayoutX() > newXValue)
rotation = 270 + rotation;
else
rotation = 270 - rotation;
// if (boatPoly.getLayoutY() >= newYValue && boatPoly.getLayoutX() <= newXValue)
// rotation = 90 - rotation;
// else if (boatPoly.getLayoutY() < newYValue && boatPoly.getLayoutX() <= newXValue)
// rotation = 90 + rotation;
// else if (boatPoly.getLayoutY() >= newYValue && boatPoly.getLayoutX() > newXValue)
// rotation = 270 + rotation;
// else
// rotation = 270 - rotation;
setDestination(newXValue, newYValue, rotation, raceIDs);
}
}
public void rotateTo (double rotation) {
boatPoly.getTransforms().clear();
boatPoly.getTransforms().add(new Rotate(rotation, 0, 0));
wakePoly.getTransforms().clear();
wakePoly.getTransforms().add(new Rotate(rotation, 0, 0));
if(rotation != 0) {
rotationalGoal = rotation;
boatPoly.getTransforms().clear();
boatPoly.getTransforms().add(new Rotate(rotation, BOAT_WIDTH / 2, 0));
}
// wakePoly.getTransforms().clear();
// wakePoly.getTransforms().add(new Rotate(rotation, 0, 0));
}
public void forceRotation () {
+3 -2
View File
@@ -4,6 +4,7 @@ import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Translate;
/**
* Created by CJIRWIN on 27/04/2017.
@@ -22,13 +23,13 @@ class Wake extends Arc {
private int lifespan = MAX_LIFESPAN;
Wake (double startingX, double startingY, double velocityX, double velocityY, double rotation) {
super(startingX + 20, startingY + 30, 20, 30, 180, 0);
super(startingX, startingY, 20, 30, 180, 0);
//super.setFill(Color.BLUE);
super.setStroke(Color.DEEPSKYBLUE);
super.setType(ArcType.OPEN);
super.setFill(new Color(0, 0, 0 ,0));
super.setStrokeWidth(2.0);
super.getTransforms().add(new Rotate(rotation - 270, startingX + 20, startingY + 20));
super.getTransforms().add(new Rotate(rotation, 5, -15));
// this.velocityX = -velocityX;
// this.velocityY = -velocityY;
this.velocityX = 0;
@@ -167,7 +167,7 @@ public class MarkGroup extends RaceObject {
public void moveGroupBy (double x, double y, double rotation) {
super.setLayoutX(super.getLayoutX() + x);
super.setLayoutY(super.getLayoutY() + y);
rotateTo(rotation + currentRotation);
rotateTo(rotation);
}
private void updateChildren (double timeInterval) {
@@ -14,10 +14,9 @@ import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -29,6 +28,7 @@ public class StreamParser extends Thread{
private static ArrayList<Long> boat_IDS = new ArrayList<>();
private String threadName;
private Thread t;
private static boolean raceStarted = false;
public StreamParser(String threadName){
this.threadName = threadName;
@@ -120,7 +120,23 @@ public class StreamParser extends Thread{
int raceStatus = payload[11];
// System.out.println("raceStatus = " + raceStatus);
long expectedStartTime = extractTimeStamp(Arrays.copyOfRange(payload,12,18), 6);
// System.out.println("Race starting in: " + expectedStartTime);
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
long timeTillStart = ((new Date (expectedStartTime)).getTime() - (new Date (currentTime)).getTime())/1000;
if (timeTillStart > 0 && timeTillStart % 10 == 0) {
System.out.println("Time till start: " + timeTillStart + " Seconds");
} else {
if (raceStatus == 4 || raceStatus == 8){
System.out.println("RACE HAS FINISHED");
} else if (!raceStarted){
raceStarted = true;
System.out.println("RACE HAS STARTED");
}
if (timeTillStart % 10 == 0){
System.out.println("Time since start: " + -1 * timeTillStart + " Seconds");
}
}
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
long windSpeed = bytesToLong(Arrays.copyOfRange(payload,20,22));
int noBoats = payload[22];