Angular movement when auto vmg is pressed is smoothed. #story[1196]
This commit is contained in:
@@ -15,6 +15,7 @@ public abstract class ObserverCommand implements Command, Observer {
|
||||
public ObserverCommand(MockRace race, MockBoat boat) {
|
||||
this.race = race;
|
||||
this.boat = boat;
|
||||
boat.setAutoVMG(false);
|
||||
race.addObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ public class TackGybeCommand extends ObserverCommand {
|
||||
totalRotation += offset;
|
||||
} else {
|
||||
System.out.println(goalAngle + " " + boat.getBearing().degrees());
|
||||
boat.setBearing(Bearing.fromDegrees(goalAngle));
|
||||
race.deleteObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package mock.model.commandFactory;
|
||||
|
||||
import mock.model.MockBoat;
|
||||
import mock.model.MockRace;
|
||||
import mock.model.NewPolars;
|
||||
import mock.model.VMG;
|
||||
import shared.model.Bearing;
|
||||
|
||||
import java.util.Observable;
|
||||
|
||||
@@ -9,6 +12,10 @@ import java.util.Observable;
|
||||
* Command class for autoVMG
|
||||
*/
|
||||
public class VMGCommand extends ObserverCommand {
|
||||
private double goalAngle;
|
||||
private double goalRotation;
|
||||
private double totalRotation = 0;
|
||||
private int direction;
|
||||
|
||||
/**
|
||||
* Constructor for class
|
||||
@@ -26,10 +33,38 @@ public class VMGCommand extends ObserverCommand {
|
||||
} else {
|
||||
boat.setAutoVMG(true);
|
||||
}
|
||||
newOptimalVMG(boat);
|
||||
|
||||
goalRotation = goalAngle - boat.getBearing().degrees();
|
||||
if (goalRotation < 0) {
|
||||
goalRotation += 360;
|
||||
}
|
||||
if (goalRotation > 180) {
|
||||
goalRotation = 360 - goalRotation;
|
||||
direction = -1;
|
||||
} else {
|
||||
direction = 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void newOptimalVMG(MockBoat boat) {
|
||||
long tackPeriod = 1000;
|
||||
if (boat.getTimeSinceTackChange() > tackPeriod) {
|
||||
VMG newVMG = NewPolars.setBestVMG(race.getWindDirection(), race.getWindSpeed(), boat.getBearing());
|
||||
goalAngle = newVMG.getBearing().degrees();
|
||||
}
|
||||
}
|
||||
|
||||
@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());
|
||||
boat.setBearing(Bearing.fromDegrees(goalAngle));
|
||||
race.deleteObserver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user