Fixed small bug where the sail never stopps jittering after moving #story[1297]

main
Fan-Wu Yang 8 years ago
parent 2b8ca9265f
commit 088e73414b

@ -324,6 +324,7 @@ public class RaceViewController extends Controller {
AnimationTimer sailsFollowBoat = new AnimationTimer() { AnimationTimer sailsFollowBoat = new AnimationTimer() {
double sailCurrent = visualiserRace.getVisualiserRaceState().getWindDirection().degrees(); double sailCurrent = visualiserRace.getVisualiserRaceState().getWindDirection().degrees();
boolean canLuff = true; boolean canLuff = true;
double turnRate = 5;
@Override @Override
public void handle(long now) { public void handle(long now) {
@ -344,19 +345,20 @@ public class RaceViewController extends Controller {
sailDir = visualiserRace.getVisualiserRaceState().getWindDirection().degrees(); sailDir = visualiserRace.getVisualiserRaceState().getWindDirection().degrees();
} }
double compA = ((sailCurrent - sailDir) % 360 + 360) % 360; double compA = ((sailCurrent - sailDir) % 360 + 360) % 360;//degrees right
double compB = ((sailDir - sailCurrent) % 360 + 360) % 360; if (compA > 180) compA = 360 - compA;
if (compB < compA){ double compB = ((sailDir - sailCurrent) % 360 + 360) % 360;//degrees left
if (compB < compA - 5){ if (compB > compA){
sailCurrent += 5; if (compA > turnRate){
sailCurrent = ((sailCurrent - turnRate) % 360 + 360) % 360;
canLuff = false; canLuff = false;
} else { } else {
sailCurrent = sailDir; sailCurrent = sailDir;
canLuff = true; canLuff = true;
} }
} else { } else {
if (compA > compB + 5){ if (compB > turnRate){
sailCurrent -= 5; sailCurrent = ((sailCurrent + turnRate) % 360 + 360) % 360;
canLuff = false; canLuff = false;
} else { } else {
sailCurrent = sailDir; sailCurrent = sailDir;
@ -370,6 +372,7 @@ public class RaceViewController extends Controller {
sails3D.stopLuffing(); sails3D.stopLuffing();
} }
} else { } else {
System.out.println("luffing");
if (!sails3D.isLuffing()) { if (!sails3D.isLuffing()) {
sails3D.startLuffing(); sails3D.startLuffing();
} }
@ -377,6 +380,7 @@ public class RaceViewController extends Controller {
} }
sailsSubject.setX(gpsConverter.convertGPS(boat.getPosition()).getX()); sailsSubject.setX(gpsConverter.convertGPS(boat.getPosition()).getX());
sailsSubject.setZ(gpsConverter.convertGPS(boat.getPosition()).getY()); sailsSubject.setZ(gpsConverter.convertGPS(boat.getPosition()).getY());
} }
}; };
sailsFollowBoat.start(); sailsFollowBoat.start();

Loading…
Cancel
Save