VECTOR vecWind;
VECTOR vecWindTarget;
void weatherWind ()
{
double directionChangeTimer = 0;
double jitterTimer = 0;
while (1) {
// Big direction and strength change after time
if (directionChangeTimer <= 0) {
directionChangeTimer = random(10) * 16; // Define new change interval
// Rotate and scale target
VECTOR* r = vector(15 - random(30), 15 - random(30), 0);
ang_add(&vecWindTarget, r);
vec_normalize(&vecWindTarget, 2 - random(1.5));
}
// Jitter
if (jitterTimer <= 0) {
jitterTimer = random(1) * 16; // Define new jitter interval
// Slightly rotate the target vector
VECTOR* r = vector(2 - random(4), 2 - random(4), 0);
ang_add(&vecWindTarget, r);
}
// Let the wind vector smoothly transist towards the target vector
vec_lerp(&vecWind, &vecWind, &vecWindTarget, 0.1 * time_step);
// Count the timers down
directionChangeTimer -= time_step;
jitterTimer -= time_step;
wait(1);
}
}