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