cleaned up code for merging back to develop #story[923]

This commit is contained in:
Peter Galloway
2017-05-17 19:18:31 +12:00
parent 95e353c14e
commit 2e375978bd
5 changed files with 2 additions and 151 deletions
+1 -42
View File
@@ -1,16 +1,10 @@
package seng302.models;
import javafx.geometry.Point2D;
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.stage.Stage;
import java.util.ArrayList;
import java.util.List;
/**
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2 dimensional boat.
@@ -34,14 +28,6 @@ public class BoatGroup extends Group{
private double yIncrement;
private long lastTimeValid = 0;
private long framesToMove;
private Point2D lastPoint;
double oldTime;
double newTime;
double lastYValue = 0;
double lastXValue = 0;
private double pixelVelocityX;
private double pixelVelocityY;
private static final int expectedUpdateInterval = 200;
//Graphical objects
private Yacht boat;
private Group lineGroup = new Group();
@@ -163,21 +149,12 @@ public class BoatGroup extends Group{
lastTimeValid = timeValid - 200;
moveTo(newXValue, newYValue, rotation);
}
rotateTo(rotation);
framesToMove = Math.round((frameRate/(1000.0f/(timeValid-lastTimeValid))));
double dx = newXValue - boatPoly.getLayoutX();
double dy = newYValue - boatPoly.getLayoutY();
xIncrement = dx/framesToMove;
yIncrement = dy/framesToMove;
if (id == 106){
System.out.println(framesToMove);
System.out.println("xIncrement = " + xIncrement);
}
rotateTo(rotation);
velocityObject.setText(String.format("%.2f m/s", groundSpeed));
lastTimeValid = timeValid;
@@ -186,10 +163,6 @@ public class BoatGroup extends Group{
public void setTeamNameObjectVisible(Boolean visible) {
teamNameObject.setVisible(visible);
}
@@ -210,20 +183,6 @@ public class BoatGroup extends Group{
return boat;
}
// /**
// * Returns true if this BoatGroup contains at least one of the given IDs.
// *
// * @param raceIds The ID's to check the BoatGroup for.
// * @return True if the BoatGroup contains at east one of the given IDs, false otherwise.
// */
// public boolean hasRaceId (long... raceIds) {
// for (long id : raceIds) {
// if (id == boat.getSourceID())
// return true;
// }
// return false;
// }
/**
* Returns all raceIds associated with this group. For BoatGroups the ID's are for the boat.
*
@@ -1,75 +0,0 @@
package seng302.models;
import javafx.geometry.Point2D;
import javafx.scene.Group;
/**
* 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
protected static double expectedUpdateInterval = 200;
protected double rotationalGoal;
protected double currentRotation;
protected double rotationalVelocity;
protected double pixelVelocityX;
protected double pixelVelocityY;
public Point2D getPosition () {
return new Point2D(super.getLayoutX(), getLayoutY());
}
public static double getExpectedUpdateInterval() {
return expectedUpdateInterval;
}
/**
*
*/
public static void setExpectedUpdateInterval(double expectedUpdateInterval) {
RaceObject.expectedUpdateInterval = expectedUpdateInterval;
}
/**
* Calculates the rotational velocity required to reach the rotationalGoal from the currentRotation.
*/
protected void calculateRotationalVelocity () {
if (Math.abs(rotationalGoal - currentRotation) > 180) {
if (rotationalGoal - currentRotation >= 0) {
this.rotationalVelocity = ((rotationalGoal - currentRotation) - 360) / expectedUpdateInterval;
} else {
this.rotationalVelocity = (360 + (rotationalGoal - currentRotation)) / expectedUpdateInterval;
}
} else {
this.rotationalVelocity = (rotationalGoal - currentRotation) / expectedUpdateInterval;
}
//Sometimes the rotation is too large to be realistic. In that case just do it instantly.
// if (Math.abs(rotationalVelocity) > 1) {
// rotationalVelocity = 0;
// rotateTo(rotationalGoal);
// }
}
/**
* 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 X co-ordinate to move the graphics to.
* @param y Y co-ordinate to move the graphics to.
* @param rotation Rotation to move graphics to.
* @param raceIds RaceID of the object to move.
*/
public abstract void setDestination (double x, double y, double rotation, double groundSpeed, int... raceIds);
public abstract void updatePosition (long timeInterval);
public abstract void moveTo (double x, double y, double rotation);
public abstract void moveGroupBy(double x, double y, double rotation);
public abstract boolean hasRaceId (int... raceIds);
public abstract int[] getRaceIds ();
}