Polar velocities should now work as intended.

Snapping to VMG still needs to be implemented.
Still an issue of not being able to pass the total upwind or downwind point

tags: #story[986]
This commit is contained in:
William Muir
2017-07-25 22:19:03 +12:00
parent c8a96dcce9
commit a56dac1e87
5 changed files with 46 additions and 32 deletions
+28 -12
View File
@@ -4,6 +4,7 @@ import static seng302.utilities.GeoUtility.getGeoCoordinate;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javafx.scene.paint.Color;
import seng302.client.ClientPacketParser;
@@ -110,8 +111,8 @@ public class Yacht {
this.position = "-";
this.sailIn = false;
this.location = new GeoPoint(57.670341, 11.826856);
this.heading = 120.0;
this.velocity = 50000.0;
this.heading = 120.0; //In degrees
this.velocity = 0d; //in mms-1
}
/**
@@ -120,13 +121,14 @@ public class Yacht {
public void update(Long timeInterval) {
if (sailIn) {
Double secondsElapsed = timeInterval / 1000000.0;
Double thisHeading = ((double) Math.floorMod(heading.longValue(), 360L));
Double windSpeedKnots = 0d;
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, thisHeading);
velocity = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 3000;
//System.out.println("velocity = " + velocity);
Double windSpeedKnots = GameState.getWindSpeedKnots();
Double trueWindAngle = Math.abs(GameState.getWindDirection() - heading);
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, trueWindAngle);
velocity = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 1000;
Double metersCovered = velocity * secondsElapsed;
location = getGeoCoordinate(location, heading, metersCovered);
} else {
velocity = 0d;
}
}
@@ -136,13 +138,16 @@ public class Yacht {
}
public void adjustHeading(Double amount) {
Double newVal = heading + amount;
lastHeading = heading;
// TODO: 24/07/17 wmu16 - '%' in java does remainder, we need modulo. All this must be changed here, this is why we have neg values!
heading = (heading + amount) % 360.0;
heading = (double) Math.floorMod(newVal.longValue(), 360L);
}
public void tackGybe(Double windDirection) {
adjustHeading(-2 * ((heading - windDirection) % 360));
Double normalizedHeading = heading - GameState.windDirection;
normalizedHeading = (double) Math.floorMod(normalizedHeading.longValue(), 360);
adjustHeading(-2 * normalizedHeading);
}
public void toggleSailIn() {
@@ -150,7 +155,8 @@ public class Yacht {
}
public void turnUpwind() {
Double normalizedHeading = (heading - GameState.windDirection) % 360;
Double normalizedHeading = heading - GameState.windDirection;
normalizedHeading = (double) Math.floorMod(normalizedHeading.longValue(), 360);
if (normalizedHeading == 0) {
if (lastHeading < 180) {
adjustHeading(-TURN_STEP);
@@ -171,7 +177,8 @@ public class Yacht {
}
public void turnDownwind() {
Double normalizedHeading = (heading - GameState.windDirection) % 360;
Double normalizedHeading = heading - GameState.windDirection;
normalizedHeading = (double) Math.floorMod(normalizedHeading.longValue(), 360);
if (normalizedHeading == 0) {
if (lastHeading < 180) {
adjustHeading(TURN_STEP);
@@ -191,6 +198,11 @@ public class Yacht {
}
}
public void turnToVMG() {
// TODO: 25/07/17 wmu16 - Fix this so it grabs the optimal value from the optimal Polar
}
public String getBoatType() {
return boatType;
@@ -294,10 +306,14 @@ public class Yacht {
this.markRoundTime = markRoundingTime;
}
public double getVelocity() {
public double getVelocityMMS() {
return velocity;
}
public Double getVelocityKnots() {
return velocity / 1000 * ClientPacketParser.MS_TO_KNOTS;
}
public Long getTimeTillNext() {
return timeTillNext;
}