Fixed markergroup bugs. Improved wakes. Still WIP

This commit is contained in:
Calum
2017-04-27 11:58:50 +12:00
parent 245bd184b4
commit 65c0e6f77d
6 changed files with 142 additions and 62 deletions
@@ -37,7 +37,6 @@ public class CanvasController {
private ResizableCanvas canvas;
private Group group;
private GraphicsContext gc;
private List<BoatGroup> boatGroups = new ArrayList<>();
private final int MARK_SIZE = 10;
private final int BUFFER_SIZE = 25;
@@ -154,6 +153,7 @@ public class CanvasController {
Mark nextMark;
//if (countdown == 0) {
//System.out.println("called the at");
for (RaceObject raceObject : raceObjects) {
//if (currentRaceMarker[boatIndex] < marks.size()) {
//if (currentRaceMarker[boatIndex] == 6) {
@@ -166,9 +166,13 @@ public class CanvasController {
//descending = nextMark.getY() > boatGroup.getLayoutY();
//leftToRight = nextMark.getX() < boatGroup.getLayoutX();
raceObject.updatePosition(1000 / 60);
for (int id : raceObject.getRaceIds()) {
if (StreamParser.boatPositions.containsKey(id)) {
//System.out.println("id = " + id);
if (id != 0 && StreamParser.boatPositions.size() > 0) {
boolean test = StreamParser.boatPositions.containsKey(id);
if (StreamParser.boatPositions.containsKey((long) id)) {
Point3D p = StreamParser.boatPositions.get((long) id);
Point2D p2d = latLonToXY(p.getX(), p.getY());
//System.out.println("p2d = " + p2d);
@@ -179,6 +183,7 @@ public class CanvasController {
}
StreamParser.boatPositions.remove((long) id);
}
}
//Point3D p = StreamParser.boatPositions.get((long) raceObject.getRaceIds()[0]);
//System.out.println("boatGroup = " + boatGroup.getBoat().getId());
//System.out.println("StreamParser.boatPositions.toString() = " + StreamParser.boatPositions.toString());
@@ -292,10 +297,11 @@ public class CanvasController {
private void drawBoats() {
// Map<Boat, TimelineInfo> timelineInfos = raceViewController.getTimelineInfos();
List<Boat> boats = raceViewController.getStartingBoats();
Double startingX = group.getChildren().get(0).getLayoutX();
Double startingY = group.getChildren().get(0).getLayoutY();
Double firstMarkX = group.getChildren().get(1).getLayoutX();
Double firstMarkY = group.getChildren().get(1).getLayoutY();
System.out.println("raceObjects " + raceObjects);
Double startingX = raceObjects.get(0).getLayoutX();
Double startingY = raceObjects.get(0).getLayoutY();
Double firstMarkX = raceObjects.get(1).getLayoutX();
Double firstMarkY = raceObjects.get(1).getLayoutY();
for (Boat boat : boats) {
BoatGroup boatGroup = new BoatGroup(boat, Colors.getColor());
@@ -303,7 +309,7 @@ public class CanvasController {
boatGroup.setDestination(firstMarkX, firstMarkY);
boatGroup.forceRotation();
group.getChildren().add(boatGroup);
boatGroups.add(boatGroup);
raceObjects.add(boatGroup);
// drawBoat(boat.getLongitude(), boat.getLatitude(), boat.getColor(), boat.getShortName(), boat.getSpeedInKnots(), boat.getHeading());
}
}
@@ -529,12 +535,14 @@ public class CanvasController {
*/
private void givePointsXY() {
//Point2D canvasLocation;
// List<Mark> allPoints = new ArrayList<>(raceViewController.getRace().getCourse());
Set<Mark> unqiuePoints = new HashSet<>(raceViewController.getRace().getCourse());
System.out.println("unqiuePoints = " + unqiuePoints);
List<Mark> allPoints = new ArrayList<>(raceViewController.getRace().getCourse());
List<Mark> processed = new ArrayList<>();
//Set<Mark> unqiuePoints = new HashSet<>(raceViewController.getRace().getCourse());
//System.out.println("unqiuePoints = " + unqiuePoints);
RaceObject markGroup;
for (Mark mark : unqiuePoints) {
for (Mark mark : allPoints) {
if (!processed.contains(mark)) {
if (mark.getMarkType() != MarkType.SINGLE_MARK) {
GateMark gateMark = (GateMark) mark;
// canvasLocation = findScaledXY(gateMark.getSingleMark1());
@@ -547,12 +555,15 @@ public class CanvasController {
markGroup = new MarkGroup(mark, findScaledXY(gateMark.getSingleMark1()), findScaledXY(gateMark.getSingleMark2()));
group.getChildren().add(markGroup);
}
else {
raceObjects.add(markGroup);
} else {
// canvasLocation = findScaledXY(mark);
// mark.setX((int) canvasLocation.getX());
// mark.setY((int) canvasLocation.getY());
markGroup = new MarkGroup(mark, findScaledXY(mark));
group.getChildren().add(markGroup);
}
processed.add(mark);
}
}
}
+30 -7
View File
@@ -7,6 +7,9 @@ import javafx.scene.text.Text;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Translate;
import java.util.ArrayList;
import java.util.List;
/**
* Created by CJIRWIN on 25/04/2017.
*/
@@ -21,10 +24,11 @@ public class BoatGroup extends RaceObject{
private static final double BOAT_WIDTH = 10d;
//Time between sections of race - Should be changed to 200 for actual program.
private static double expectedUpdateInterval = 200;
private static int WAKE_FRAME_INTERVAL = 40;
private static int WAKE_FRAME_INTERVAL = 80;
private Boat boat;
private int wakeCounter = WAKE_FRAME_INTERVAL;
private List<Wake> wakes = new ArrayList<>();
public BoatGroup (Boat boat, Color color){
this.boat = boat;
@@ -107,21 +111,40 @@ public class BoatGroup extends RaceObject{
rotation = rotationalVelocity * timeInterval;
}
moveGroupBy(dx, dy, rotation);
for (Node wake : super.getChildren().subList(4, super.getChildren().size())) {
if (!((Wake) wake).updatePosition(timeInterval))
// if (super.getChildren().size() > 3) {
// for (Node wake : super.getChildren().subList(4, super.getChildren().size())) {
// if (!((Wake) wake).updatePosition(timeInterval))
// super.getChildren().remove(wake);
// }
// }
for (Wake wake : wakes) {
if (wake.updatePosition(timeInterval)) {
super.getChildren().remove(wake);
}
}
if (wakeCounter-- == 0) {
wakeCounter = WAKE_FRAME_INTERVAL;
super.getChildren().add(
new Wake(
super.getLayoutX(), super.getLayoutY(), pixelVelocityX, pixelVelocityY
)
if (pixelVelocityX > 0 && pixelVelocityY > 0) {
// super.getChildren().add(
// new Wake(
// super.getLayoutX() + BOAT_HEIGHT, super.getLayoutY() + BOAT_HEIGHT, pixelVelocityX, pixelVelocityY
// )
// );
Wake wake = new Wake(
super.getLayoutX(),
super.getLayoutY(),
pixelVelocityX,
pixelVelocityY
);
super.getChildren().add(wake);
wakes.add(wake);
}
}
}
public void setDestination (double newXValue, double newYValue, double rotation, int... raceIds) {
//System.out.println("MADE IT");
if (hasRaceId(raceIds)) {
this.pixelVelocityX = (newXValue - super.getLayoutX()) / expectedUpdateInterval;
this.pixelVelocityY = (newYValue - super.getLayoutY()) / expectedUpdateInterval;
+15 -7
View File
@@ -10,27 +10,35 @@ import javafx.scene.shape.ArcType;
class Wake extends Arc {
private static int VELOCITY_SCALE_FACTOR = 3;
private static int MAX_LIFESPAN = 180;
private static int MAX_LIFESPAN = 420;
private static double LIFESPAN_PER_FRAME = 1.0 / MAX_LIFESPAN;
//private static double LENGTH_PER_FRAME = 120 / MAX_LIFESPAN;
private static double LENGTH_PER_FRAME = 0.08;
private double velocityX;
private double velocityY;
private double opacity;
private int lifespan = MAX_LIFESPAN;
Wake (double startingX, double startingY, double velocityX, double velocityY) {
super(startingX, startingY, 25, 15, 160, 40);
super.setFill(Color.BLUE);
super(0, 0, 20, 30, 180, 0);
//super.setFill(Color.BLUE);
super.setStroke(Color.BLUE);
super.setType(ArcType.OPEN);
super.setStrokeWidth(2.0);
this.velocityX = -velocityX;
this.velocityY = -velocityY;
this.velocityX = -velocityX / 2;
this.velocityY = -velocityY / 2;
}
boolean updatePosition (double timeInterval) {
lifespan--;
//super.setOpacity(LIFESPAN_PER_FRAME * lifespan * super.getOpacity());
opacity = LIFESPAN_PER_FRAME * lifespan * opacity;
super.setFill(new Color(0.0f, 0.0f, 1.0f, opacity));
super.setLayoutX(super.getLayoutX() + velocityX * timeInterval);
super.setLayoutX(super.getLayoutX() + velocityX * timeInterval);
super.setOpacity(LIFESPAN_PER_FRAME * lifespan * super.getOpacity());
super.setLayoutY(super.getLayoutY() + velocityY * timeInterval);
super.setStartAngle(super.getStartAngle() - LENGTH_PER_FRAME);
super.setLength(super.getLength() + LENGTH_PER_FRAME * 2);
return lifespan == 0;
}
@@ -28,6 +28,10 @@ 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;
@@ -36,43 +40,75 @@ public class MarkGroup extends RaceObject {
} else if (mark.getName().equals("Finish")){
color = Color.RED;
}
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());
super.getChildren().add(
new Circle(
(points[1].getX() - points[0].getX() / 2),
(points[1].getY() - points[0].getY() / 2),
(points[1].getX() - points[0].getX()) / 2d,
(points[1].getY() - points[0].getY()) / 2d,
MARK_RADIUS,
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() / 2),
-(points[1].getY() - points[0].getY() / 2),
-(points[1].getX() - points[0].getX()) / 2d,
-(points[1].getY() - points[0].getY()) / 2d,
MARK_RADIUS,
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(
0,
0,
points[1].getX() - points[0].getX(),
points[1].getY() - points[0].getY()
(points[1].getX() - points[0].getX()) / 2d,
(points[1].getY() - points[0].getY()) / 2d,
-(points[1].getX() - points[0].getX()) / 2d,
-(points[1].getY() - points[0].getY()) / 2d
);
line.setStrokeWidth(LINE_THICKNESS);
line.setStroke(color);
if (mark.getMarkType() == MarkType.OPEN_GATE) {
line.getStrokeDashArray().addAll(DASHED_GAP_LEN, DASHED_LINE_LEN);
}
super.getChildren().add(line);
nodePixelVelocitiesX = new double[2];
nodePixelVelocitiesY = new double[2];
nodeDestinations = new Point2D[2];
nodePixelVelocitiesX = new double[]{0d,0d};
nodePixelVelocitiesY = new double[]{0d,0d};
nodeDestinations = new Point2D[]{
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) {
@@ -118,13 +154,14 @@ 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,
// 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));
}
public void updatePosition (double timeInterval) {
@@ -137,7 +174,7 @@ public class MarkGroup extends RaceObject {
public void moveGroupBy (double x, double y, double rotation) {
super.setLayoutX(super.getLayoutX() + x);
super.setLayoutY(super.getOpacity() + y);
super.setLayoutY(super.getLayoutY() + y);
rotateTo(rotation + currentRotation);
}
@@ -17,11 +17,11 @@ public class StreamPacket {
this.messageLength = messageLength;
this.timeStamp = timeStamp;
this.payload = payload;
System.out.println("type = " + this.type.toString());
//System.out.println("type = " + this.type.toString());
//switch the packet type to deal with what ever specific packet you want to deal with
if (this.type == PacketType.XML_MESSAGE){
System.out.println("--------");
System.out.println(new String(payload));
//System.out.println("--------");
//System.out.println(new String(payload));
StreamParser.parsePacket(this);
}
}
@@ -96,7 +96,8 @@ public class StreamParser extends Thread{
extractAvgWind(packet);
break;
default:
System.out.println(packet.getType().toString());
break;
//System.out.println(packet.getType().toString());
}
}