TackGybeCommand now smooths the rotation of the boat. #story[1196]
This commit is contained in:
@@ -148,6 +148,10 @@ public class RaceLogic implements RunnableWithFramePeriod, Observer {
|
|||||||
// Execute commands from clients.
|
// Execute commands from clients.
|
||||||
commands.execute();
|
commands.execute();
|
||||||
|
|
||||||
|
// Notify Observers
|
||||||
|
race.setChanged();
|
||||||
|
race.notifyObservers();
|
||||||
|
|
||||||
//Update race time.
|
//Update race time.
|
||||||
race.updateRaceTime(currentTime);
|
race.updateRaceTime(currentTime);
|
||||||
|
|
||||||
@@ -185,10 +189,6 @@ public class RaceLogic implements RunnableWithFramePeriod, Observer {
|
|||||||
previousFrameTime = currentTime;
|
previousFrameTime = currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify Observers
|
|
||||||
race.setChanged();
|
|
||||||
race.notifyObservers();
|
|
||||||
|
|
||||||
waitForFramePeriod(previousFrameTime, currentTime, 50);
|
waitForFramePeriod(previousFrameTime, currentTime, 50);
|
||||||
previousFrameTime = currentTime;
|
previousFrameTime = currentTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ import java.util.Observable;
|
|||||||
* Command class for tacking and gybing
|
* Command class for tacking and gybing
|
||||||
*/
|
*/
|
||||||
public class TackGybeCommand extends ObserverCommand {
|
public class TackGybeCommand extends ObserverCommand {
|
||||||
|
private double goalRotation;
|
||||||
|
private double totalRotation = 0;
|
||||||
|
private int direction; // -1 for anticlockwise, 1 for clockwise
|
||||||
|
private double goalAngle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for class
|
* Constructor for class
|
||||||
@@ -22,18 +26,26 @@ public class TackGybeCommand extends ObserverCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
|
|
||||||
boat.setAutoVMG(false);
|
|
||||||
|
|
||||||
double boatAngle = boat.getBearing().degrees();
|
double boatAngle = boat.getBearing().degrees();
|
||||||
double windAngle = race.getWindDirection().degrees();
|
double windAngle = race.getWindDirection().degrees();
|
||||||
double differenceAngle = calcDistance(boatAngle, windAngle);
|
double differenceAngle = calcDistance(boatAngle, windAngle);
|
||||||
double angleA = windAngle + differenceAngle;
|
double angleA = windAngle + differenceAngle;
|
||||||
double angleB = windAngle - differenceAngle;
|
double angleB = windAngle - differenceAngle;
|
||||||
if (angleA % 360 == boatAngle) {
|
if (angleA % 360 == boatAngle) {
|
||||||
boat.setBearing(Bearing.fromDegrees(angleB));
|
goalAngle = angleB % 360;
|
||||||
} else {
|
} else {
|
||||||
boat.setBearing(Bearing.fromDegrees(angleA));
|
goalAngle = angleA % 360;
|
||||||
|
}
|
||||||
|
|
||||||
|
goalRotation = goalAngle - boatAngle;
|
||||||
|
if (goalRotation < 0) {
|
||||||
|
goalRotation += 360;
|
||||||
|
}
|
||||||
|
if (goalRotation > 180) {
|
||||||
|
goalRotation = 360 - goalRotation;
|
||||||
|
direction = -1;
|
||||||
|
} else {
|
||||||
|
direction = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +62,14 @@ public class TackGybeCommand extends ObserverCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable o, Object arg) {
|
public void update(Observable o, Object arg) {
|
||||||
|
double offset = 3.0;
|
||||||
|
if (totalRotation < goalRotation) {
|
||||||
|
boat.setBearing(Bearing.fromDegrees(boat.getBearing().degrees() + offset * direction));
|
||||||
|
totalRotation += offset;
|
||||||
|
} else {
|
||||||
|
System.out.println(goalAngle + " " + boat.getBearing().degrees());
|
||||||
|
race.deleteObserver(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ public class Constants {
|
|||||||
/**
|
/**
|
||||||
* The race pre-start time, in milliseconds. 3 minutes.
|
* The race pre-start time, in milliseconds. 3 minutes.
|
||||||
*/
|
*/
|
||||||
public static final long RacePreStartTime = 3 * 60 * 1000;
|
//
|
||||||
|
// TODO: CHANGE BACK TO 3 MINUTES BEFORE MERGING TO MASTER
|
||||||
|
public static final long RacePreStartTime = 30000; //3 * 60 * 1000;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user