Wind oscillates, replaces random wind with shifting wind. #story[1187]
This commit is contained in:
@@ -13,10 +13,11 @@ public class ShiftingWindGenerator implements WindGenerator {
|
||||
double baseLineSpeed;
|
||||
double speedVariance = 4;
|
||||
double bearingVariance = 5; // In degrees
|
||||
double oscillationPeriod = 3e6; // In milliseconds
|
||||
double oscillationVariance = 0.25;
|
||||
double oscillationPeriod = 1e3 * 60 * 1; // In milliseconds
|
||||
|
||||
double timeOfLastOscillationReset = 0;
|
||||
double timeSinceLastChange = 0;
|
||||
double timeOfLastChange = 0;
|
||||
double timeSinceLastShift = 0; // Back / veer
|
||||
|
||||
boolean oscillationLeft = false;
|
||||
@@ -42,13 +43,39 @@ public class ShiftingWindGenerator implements WindGenerator {
|
||||
oscillateWind(newWind);
|
||||
shiftWind(newWind);
|
||||
changeWindSpeed(newWind);
|
||||
timeOfLastChange = System.currentTimeMillis();
|
||||
return newWind;
|
||||
}
|
||||
|
||||
private void oscillateWind(Wind wind) {
|
||||
double timeSinceLastOscillationReset = System.currentTimeMillis() - timeOfLastOscillationReset;
|
||||
if (oscillationLeft) {
|
||||
double timeSinceLastChange = System.currentTimeMillis() - timeOfLastChange;
|
||||
double newBearing = wind.getWindDirection().degrees();
|
||||
double degreeChange = timeSinceLastChange * 2 * bearingVariance / oscillationPeriod;
|
||||
degreeChange = (1 - oscillationVariance) * degreeChange + (2 * oscillationVariance) * degreeChange * Math.random();
|
||||
|
||||
if (timeSinceLastOscillationReset >= oscillationPeriod) {
|
||||
timeOfLastOscillationReset = System.currentTimeMillis();
|
||||
oscillationLeft = !oscillationLeft;
|
||||
}
|
||||
if (oscillationLeft) {
|
||||
newBearing -= degreeChange;
|
||||
if (newBearing < baselineBearing.degrees() - bearingVariance) {
|
||||
System.out.println(timeSinceLastOscillationReset);
|
||||
oscillationLeft = !oscillationLeft;
|
||||
timeOfLastOscillationReset = System.currentTimeMillis();
|
||||
} else {
|
||||
wind.setWindDirection(Bearing.fromDegrees(newBearing % 360));
|
||||
}
|
||||
} else {
|
||||
newBearing += degreeChange;
|
||||
if (newBearing > baselineBearing.degrees() + bearingVariance) {
|
||||
System.out.println(timeSinceLastOscillationReset);
|
||||
oscillationLeft = !oscillationLeft;
|
||||
timeOfLastOscillationReset = System.currentTimeMillis();
|
||||
} else {
|
||||
wind.setWindDirection(Bearing.fromDegrees(newBearing % 360));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user