Erik Hofman wrote:
> What method would you recommend for a script that basically has to run
> forever.
>
> What I'm trying to do is add continuous motion to the sailship by
> interpolating between +10 and -10 degrees pitch, but I haven't found a
> clue on how to do this with Nasal.
Probably the best way to do this is with interpolate(). This code
should swing the pitch linearly between -10 and +10 and back 5 times
over 10 seconds, and then set a timer to do it again:
rockBoat = func {
# Arguments: property, value, delta, value, delta, ...
# Start at 10 degrees immediately, then back and forth five times:
interpolate("/sim/ai/wherever/boat/pitch-deg", -10, 0,
10, 1, -10, 1,
10, 1, -10, 1,
10, 1, -10, 1,
10, 1, -10, 1,
10, 1, -10, 1);
# When we're done, start it again:
settimer(rockBoat, 10);
}
With a little work, you could populate that table with random numbers,
etc... This avoids the need to run a Nasal script every frame to
iterate your animation; the interpolator is a C++ module.
A useful feature that doesn't yet exist would be the ability to
register a callback function for the end of an interpolation; this
would eliminate the need for the settimer call and any race conditions
that result from slightly different timeouts.
What you are asking for, the ability to run a script in a loop
forever, will require more work. This would essentially be a
multithreaded interpreter, and the NasalSys subsystem would have to
maintain separate execution contexts for each thread. That is, by
design, supposed to work in Nasal, But for this kind of animation
problem, it's probably not the right solution. The per-thread
overhead is rather high.
Andy
_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel