TackGybeCommand now smooths the rotation of the boat. #story[1196]

main
Joseph Gardner 8 years ago
parent f4cb1a3ac4
commit 00cedf4d4d

@ -148,6 +148,10 @@ public class RaceLogic implements RunnableWithFramePeriod, Observer {
// Execute commands from clients.
commands.execute();
// Notify Observers
race.setChanged();
race.notifyObservers();
//Update race time.
race.updateRaceTime(currentTime);
@ -185,10 +189,6 @@ public class RaceLogic implements RunnableWithFramePeriod, Observer {
previousFrameTime = currentTime;
}
// Notify Observers
race.setChanged();
race.notifyObservers();
waitForFramePeriod(previousFrameTime, currentTime, 50);
previousFrameTime = currentTime;
}

@ -10,6 +10,10 @@ import java.util.Observable;
* Command class for tacking and gybing
*/
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
@ -22,18 +26,26 @@ public class TackGybeCommand extends ObserverCommand {
@Override
public void execute() {
boat.setAutoVMG(false);
double boatAngle = boat.getBearing().degrees();
double windAngle = race.getWindDirection().degrees();
double differenceAngle = calcDistance(boatAngle, windAngle);
double angleA = windAngle + differenceAngle;
double angleB = windAngle - differenceAngle;
if (angleA % 360 == boatAngle) {
boat.setBearing(Bearing.fromDegrees(angleB));
goalAngle = angleB % 360;
} 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
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.
*/
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;
/**

Loading…
Cancel
Save