Tuesday, January 10, 2006

Fun with Animation

Here are a few notes on animation:

The animation commands for OBJ8 take two changes (a start and end rotation or translation) and two dataref values and map them. For example,
ANIM_rotate 0 1 0 -40 70 0 1 sim/flightmodel/whatever
would rotate the following geometry around the Y axis from -40 to 70 degrees as the dataref goes from 0 to 1. Intermediate values between 0 and 1 are interpolated. (For example, 0.5 maps to 15 degrees.) But what happens if the dataref exceeds the bounds specified?

The answer is: the result is extrapolated. If this dataref goe sto 2.0, the rotation will go to 180 degrees. (How I came up with that is left as an exercise for the reader.)

You can take advantage of this to animate rotating things like radar dishes and beacons using the sim/time/total_running_time_sec dataref. This dataref is the number of seconds x-plane has been running. For examlpe:
ANIM_rotate 0 1 0 0 360 0 5 sim/time/total_running_time_sec
This will cause the following geometry to continuously rotate, making a full rotation every 5 seconds. But why does the animation loop? Well, let's take a look in detail:

When the time is 0 the rotation is 0. 5 seconds later the rotation has made it up to 360, one full turn. Then what? At 6 seconds the rotation will now be 420 degrees. But 420 degrees is the same as 60 degrees; you can't tell whether the object has made one, two or a hundred full revolutions before turning the extra sixty degrees. So the rotation is actually becoming a huge number but the wrap-around cannot be seen, making the appearance of continuous rotation.

Rotations always occur around the origin. But what if we want to rotate around another point in our object? We must use the ANIM_translate command to move the rotation to where we want. For example:
ANIM_trans  3  4  5    3  4  5   0 0   no_ref
ANIM_rotate 0 -1 0 -90 90 -1 1 jetway/circle1
ANIM_trans -3 -4 -5 -3 -4 -5 0 0 no_ref
This will rotate the geometry around the Y axis from -90 to 90 degrees as the circle goes from -1 to 1. But the rotation happens around the point 3,4,5.

Note that the animation-translate commands have the same coordinates for both translations and no dataref. This is a static translation - it is alawys the same and its sole purpose is to move the rotation to be around a useful point. It is always followed by an opposite translation.

(It is possible to omit the second translation and simply build your animated sub-part with 0,0,0 = rotation point instead of 0,0,0 = the object's location in x-plane. But this is an advanced optimization.)

An example:

A rotating radar dish

And from the end of the OBJ:
LIGHTS 0 2
TRIS 0 1536
ANIM_begin
ANIM_trans 20.226 22.468 -0.039 20.226 22.468 -0.039 0.0 1.0 no_ref
ANIM_rotate 0 -1 0 0 360 0 6 sim/time/total_running_time_sec
TRIS 1536 1116
ANIM_end

4 comments:

Daniele Saguto said...
This comment has been removed by a blog administrator.
Daniele Saguto said...
This comment has been removed by a blog administrator.
Daniele Saguto said...

What if the object to loop 360° would be a rotor mast related to prop rpm? I'm trying various datarefs such as POINT_tacrad with rotation 0 1 0 0 360 0 6 but I only can see the object spinning a couple of times and then slowing down until it stops.

Daniele Saguto said...

Nothing to do. Maybe we can try to obtain a 360° loop by using a math formula like 360*PI/180? Or -at least- there is any chance to get the d*mn rotor following engine rpms without an action dataref like 0 1?