Sails now slowly spin to the correct position #story[1297]

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

@ -317,32 +317,62 @@ public class RaceViewController extends Controller {
Subject3D sailsSubject = new Subject3D(sails3D, 0);
sails3D.setMaterial(boatColorMat);
sailsSubject.setXRot(0d);
sailsSubject.setHeading(visualiserRace.getVisualiserRaceState().getWindDirection().degrees());
viewSubjects.add(sailsSubject);
AnimationTimer sailsFollowBoat = new AnimationTimer() {
double sailCurrent = visualiserRace.getVisualiserRaceState().getWindDirection().degrees();
boolean canLuff = true;
@Override
public void handle(long now) {
double windDir = visualiserRace.getVisualiserRaceState().getWindDirection().degrees();
double windOffset = (360 - windDir + boat.getBearing().degrees()) % 360;
double sailDir = windOffset / 180 * 270 + windDir + 180;
boolean leftOfWind = windOffset >= 180;
if (leftOfWind){
System.out.println("is left");
sailDir = -sailDir;
//if sails are out
double sailDir;
//if sails are luffing
if (boat.isSailsOut()) {
double windDir = visualiserRace.getVisualiserRaceState().getWindDirection().degrees();
double windOffset = (360 - windDir + boat.getBearing().degrees()) % 360;
sailDir = windOffset / 180 * 270 + windDir + 180;
boolean leftOfWind = windOffset >= 180;
if (leftOfWind){
sailDir = -sailDir;
} else {
sailDir = windDir - sailDir;
}
} else {
System.out.println("is right");
sailDir = windDir - sailDir;
sailDir = visualiserRace.getVisualiserRaceState().getWindDirection().degrees();
}
if (boat.isSailsOut()) {
sailsSubject.setHeading(sailDir);
if (sails3D.isLuffing()) {
sails3D.stopLuffing();
double compA = ((sailCurrent - sailDir) % 360 + 360) % 360;
double compB = ((sailDir - sailCurrent) % 360 + 360) % 360;
if (compB < compA){
if (compB < compA - 5){
sailCurrent += 5;
canLuff = false;
} else {
sailCurrent = sailDir;
canLuff = true;
}
} else {
sailsSubject.setHeading(visualiserRace.getVisualiserRaceState().getWindDirection().degrees());
if (!sails3D.isLuffing()){
sails3D.startLuffing();
if (compA > compB + 5){
sailCurrent -= 5;
canLuff = false;
} else {
sailCurrent = sailDir;
canLuff = true;
}
}
sailsSubject.setHeading(sailCurrent);
if (canLuff) {
if (boat.isSailsOut()) {
if (sails3D.isLuffing()) {
sails3D.stopLuffing();
}
} else {
if (!sails3D.isLuffing()) {
sails3D.startLuffing();
}
}
}
sailsSubject.setX(gpsConverter.convertGPS(boat.getPosition()).getX());

Loading…
Cancel
Save