Sails now slowly spin to the correct position #story[1297]
This commit is contained in:
@@ -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;
|
||||
} else {
|
||||
System.out.println("is right");
|
||||
sailDir = windDir - sailDir;
|
||||
}
|
||||
//if sails are out
|
||||
double sailDir;
|
||||
//if sails are luffing
|
||||
if (boat.isSailsOut()) {
|
||||
sailsSubject.setHeading(sailDir);
|
||||
if (sails3D.isLuffing()) {
|
||||
sails3D.stopLuffing();
|
||||
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 {
|
||||
sailsSubject.setHeading(visualiserRace.getVisualiserRaceState().getWindDirection().degrees());
|
||||
if (!sails3D.isLuffing()){
|
||||
sails3D.startLuffing();
|
||||
sailDir = visualiserRace.getVisualiserRaceState().getWindDirection().degrees();
|
||||
}
|
||||
|
||||
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 {
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user