mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge branch 'wake_remake' into Mark_to_MarkGroup
# Conflicts: # src/main/java/seng302/controllers/CanvasController.java # src/main/java/seng302/models/BoatGroup.java # src/main/java/seng302/models/Wake.java # src/main/java/seng302/models/parsers/StreamParser.java # src/main/resources/views/RaceView.fxml
This commit is contained in:
@@ -1,45 +1,42 @@
|
||||
package seng302.models;
|
||||
|
||||
import javafx.geometry.Point2D;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Line;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import javafx.scene.transform.Translate;
|
||||
import seng302.models.parsers.StreamParser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by CJIRWIN on 25/04/2017.
|
||||
*/
|
||||
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;
|
||||
//Time between sections of race - Should be changed to 200 for actual program.
|
||||
private static final int LINE_INTERVAL = 180;
|
||||
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 List<Wake> wakes = new ArrayList<>();
|
||||
private List<Line> lines = new ArrayList<>();
|
||||
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;
|
||||
|
||||
public BoatGroup (Boat boat, Color color){
|
||||
this.boat = boat;
|
||||
@@ -54,16 +51,6 @@ public class BoatGroup extends RaceObject{
|
||||
private void initChildren (Color color, double... points) {
|
||||
boatPoly = new Polygon(points);
|
||||
boatPoly.setFill(color);
|
||||
// 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);
|
||||
|
||||
teamNameObject = new Text(boat.getShortName());
|
||||
velocityObject = new Text(String.valueOf(boat.getVelocity()));
|
||||
@@ -76,14 +63,17 @@ public class BoatGroup extends RaceObject{
|
||||
velocityObject.setY(VELOCITY_Y_OFFSET);
|
||||
velocityObject.relocate(velocityObject.getX(), velocityObject.getY());
|
||||
destinationSet = false;
|
||||
super.getChildren().addAll(wakePoly, boatPoly, teamNameObject, velocityObject);
|
||||
|
||||
wake = new Wake(0, 0);
|
||||
wakeGenerationDelay = wake.numWakes;
|
||||
super.getChildren().addAll(teamNameObject, velocityObject, boatPoly);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,9 +88,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);
|
||||
wake.setLayoutX(wake.getLayoutX() + dx);
|
||||
wake.setLayoutY(wake.getLayoutY() + dy);
|
||||
rotateTo(rotation + currentRotation);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,78 +110,55 @@ public class BoatGroup extends RaceObject{
|
||||
teamNameObject.setLayoutY(y);
|
||||
velocityObject.setLayoutX(x);
|
||||
velocityObject.setLayoutY(y);
|
||||
wakePoly.setLayoutX(x);
|
||||
wakePoly.setLayoutY(y);
|
||||
wake.setLayoutX(x);
|
||||
wake.setLayoutY(y);
|
||||
wake.rotate(currentRotation);
|
||||
}
|
||||
|
||||
public void updatePosition (double timeInterval) {
|
||||
public void updatePosition (long timeInterval) {
|
||||
double dx = pixelVelocityX * timeInterval;
|
||||
double dy = pixelVelocityY * timeInterval;
|
||||
double rotation = 0d;
|
||||
if (rotationalGoal > currentRotation && rotationalVelocity > 0) {
|
||||
rotation = rotationalVelocity * timeInterval;
|
||||
} else if (rotationalGoal < currentRotation && rotationalVelocity < 0) {
|
||||
rotation = rotationalVelocity * timeInterval;
|
||||
}
|
||||
moveGroupBy(dx, dy, rotation);
|
||||
// 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) {
|
||||
// if (boat.getShortName().equals("BAR"))
|
||||
// System.out.println("thinking");
|
||||
wakeCounter = WAKE_FRAME_INTERVAL;
|
||||
if (pixelVelocityX > 0 && pixelVelocityY > 0) {
|
||||
// super.getChildren().add(
|
||||
// new Wake(
|
||||
// super.getLayoutX() + BOAT_HEIGHT, super.getLayoutY() + BOAT_HEIGHT, pixelVelocityX, pixelVelocityY
|
||||
// )
|
||||
// );
|
||||
Wake wake = new Wake(
|
||||
boatPoly.getLayoutX(),
|
||||
boatPoly.getLayoutY(),
|
||||
pixelVelocityX,
|
||||
pixelVelocityY,
|
||||
rotation);
|
||||
super.getChildren().add(wake);
|
||||
wakes.add(wake);
|
||||
}
|
||||
|
||||
}
|
||||
if (framesForNewLine == 0) {
|
||||
framesForNewLine = 121;
|
||||
moveGroupBy(dx, dy, rotation);
|
||||
|
||||
if (framesForNewLine-- == 0) {
|
||||
framesForNewLine = LINE_INTERVAL;
|
||||
if (lastPoint != null) {
|
||||
Line l = new Line(lastPoint.getX(), lastPoint.getY(), boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
||||
l.getStrokeDashArray().setAll(4d, 4d);
|
||||
lines.add(l);
|
||||
super.getChildren().add(l);
|
||||
Line l = new Line(
|
||||
lastPoint.getX(),
|
||||
lastPoint.getY(),
|
||||
boatPoly.getLayoutX(),
|
||||
boatPoly.getLayoutY()
|
||||
);
|
||||
l.getStrokeDashArray().setAll(4d, 6d);
|
||||
l.setStroke(boatPoly.getFill());
|
||||
lineGroup.getChildren().add(l);
|
||||
}
|
||||
if (destinationSet){
|
||||
lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
||||
}
|
||||
if (lineGroup.getChildren().size() > 100)
|
||||
lineGroup.getChildren().remove(0);
|
||||
}
|
||||
framesForNewLine -= 1;
|
||||
wake.updatePosition(timeInterval);
|
||||
}
|
||||
|
||||
public void setDestination (double newXValue, double newYValue, double rotation, int... raceIds) {
|
||||
//System.out.println("MADE IT");
|
||||
destinationSet = true;
|
||||
boat.setVelocity(StreamParser.boatSpeeds.get((long)boat.getId()));
|
||||
resizeWake();
|
||||
if (hasRaceId(raceIds)) {
|
||||
this.pixelVelocityX = (newXValue - boatPoly.getLayoutX()) / expectedUpdateInterval;
|
||||
this.pixelVelocityY = (newYValue - boatPoly.getLayoutY()) / expectedUpdateInterval;
|
||||
this.rotationalGoal = rotation;
|
||||
calculateRotationalVelocity();
|
||||
rotateTo(rotation);
|
||||
if (wakeGenerationDelay > 0) {
|
||||
wake.rotate(rotationalGoal);
|
||||
wakeGenerationDelay--;
|
||||
} else {
|
||||
wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, pixelVelocityX, pixelVelocityY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,15 +173,6 @@ 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;
|
||||
setDestination(newXValue, newYValue, rotation, raceIDs);
|
||||
}
|
||||
}
|
||||
@@ -235,31 +193,23 @@ public class BoatGroup extends RaceObject{
|
||||
}
|
||||
|
||||
public void rotateTo (double rotation) {
|
||||
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 Translate(0, BOAT_HEIGHT));
|
||||
wakePoly.getTransforms().add(new Rotate(rotation, BOAT_WIDTH/2, -BOAT_HEIGHT));
|
||||
}
|
||||
currentRotation = rotation;
|
||||
boatPoly.getTransforms().clear();
|
||||
boatPoly.getTransforms().add(new Rotate(rotation));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void forceRotation () {
|
||||
rotateTo (rotationalGoal);
|
||||
wake.rotate(rotationalGoal);
|
||||
}
|
||||
|
||||
public void toggleAnnotations () {
|
||||
teamNameObject.setVisible(!teamNameObject.isVisible());
|
||||
velocityObject.setVisible(!velocityObject.isVisible());
|
||||
for (Wake wake : wakes) {
|
||||
wake.setVisible(!wake.isVisible());
|
||||
}
|
||||
for (Line line : lines) {
|
||||
line.setVisible(!line.isVisible());
|
||||
}
|
||||
lineGroup.setVisible(!lineGroup.isVisible());
|
||||
wake.setVisible(!wake.isVisible());
|
||||
}
|
||||
|
||||
public Boat getBoat() {
|
||||
@@ -277,4 +227,10 @@ public class BoatGroup extends RaceObject{
|
||||
public int[] getRaceIds () {
|
||||
return new int[] {boat.getId()};
|
||||
}
|
||||
|
||||
public Group getLowPriorityAnnotations () {
|
||||
Group group = new Group();
|
||||
group.getChildren().addAll(wake, lineGroup);
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,12 @@ import javafx.geometry.Point2D;
|
||||
import javafx.scene.Group;
|
||||
|
||||
/**
|
||||
* Created by CJIRWIN on 26/04/2017.
|
||||
* RaceObject defines the behaviour that animated objects whose position is updated from a yacht race data stream must
|
||||
* adhere to.
|
||||
*/
|
||||
public abstract class RaceObject extends Group {
|
||||
|
||||
//Time between sections of race - Should be changed to 200 for actual program.
|
||||
//Time between sections of race
|
||||
protected static double expectedUpdateInterval = 200;
|
||||
|
||||
protected double rotationalGoal;
|
||||
@@ -17,10 +18,6 @@ public abstract class RaceObject extends Group {
|
||||
protected double pixelVelocityX;
|
||||
protected double pixelVelocityY;
|
||||
|
||||
public boolean isSamePos (Point2D point) {
|
||||
return point.getX() == super.getLayoutX() && point.getY() == super.getLayoutY();
|
||||
}
|
||||
|
||||
public Point2D getPosition () {
|
||||
return new Point2D(super.getLayoutX(), getLayoutY());
|
||||
}
|
||||
@@ -45,11 +42,19 @@ public abstract class RaceObject extends Group {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the destination of everything within the RaceObject that has an ID in the array raceIds. The destination is
|
||||
* set to the co-ordinates (x, y) with the given rotation.
|
||||
* @param x
|
||||
* @param y
|
||||
* @param rotation
|
||||
* @param raceIds
|
||||
*/
|
||||
public abstract void setDestination (double x, double y, double rotation, int... raceIds);
|
||||
|
||||
public abstract void setDestination (double x, double y, int... raceIds);
|
||||
|
||||
public abstract void updatePosition (double timeInterval);
|
||||
public abstract void updatePosition (long timeInterval);
|
||||
|
||||
public abstract void moveTo (double x, double y, double rotation);
|
||||
|
||||
@@ -64,5 +69,4 @@ public abstract class RaceObject extends Group {
|
||||
public abstract int[] getRaceIds ();
|
||||
|
||||
public abstract void toggleAnnotations ();
|
||||
|
||||
}
|
||||
|
||||
@@ -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,17 +115,10 @@ 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 (double timeInterval) {
|
||||
public void updatePosition (long timeInterval) {
|
||||
double x = pixelVelocityX * timeInterval;
|
||||
double y = pixelVelocityY * timeInterval;
|
||||
double rotation = rotationalVelocity * timeInterval;
|
||||
|
||||
Reference in New Issue
Block a user