View Full Version : Connecting rotations

03-11-2005, 02:17 PM
I have a human model with an animation. If that animation is over, the prog starts another one. The only problem is, that the first anim and the next are not 'connected' to each other. I mean, there is like a rupture, a sudden jump from one anim to the other.
I decided to create a tween animation (I think it is called like that) which connects the two. I just define how many steps (frames) this tween anim will last and then the app should calculate the rotations between the last frame's and the first frame's rotations.

Can someone tell me, how I can 'connect' them? Do I have to use quaternions, or does OpenGL have something for this?

I mean, surely not by dividing the angle, x,y,and z axis to 10 parts (for a 10 frame tween) and add these portions together frame by frame...


03-12-2005, 12:42 AM
Hey Fortikur, is this a skeletal or key-frame animation?

For tweening key-frames, like Quake2 models, usually a simple lerp (Linear intERPolation) is performed.

For skeletal stuff, like Doom3 models, quaternions can be use to slerp (Spherical Linear intERPolation) between poses. And then a skin is fitted over the resulting pose.

For stuff in between, like Quake3 models, a hybrid approch can be used. It all really depends on what you're doing.

03-12-2005, 04:30 AM
It's a key frame animation. No bones are used. I will see what I can find about linear interpolation math on the web. I hope this will work (I'm almost sure).
Thank you for the answer - and the term I have to look for.

03-12-2005, 10:15 AM
Yeah, for playing key-frame animations, where you're playing a series of composed vertex frames, you can lerp between the frames of the animation.

Let's say you have some vertex from frame 1, V1, and its corresponding vertex in frame 2, V2. To find the tweened vertex, lerp between the 2 vertices based on the animation time between them:

V = V1 + (V2 - V1) * t,

or equivalently,

V = V1 * (1-t) + V2 * t,

where t is in [0,1]. You could also think of t as the fractional part of the frame number, and let the floating-point frame number increase based on time.

You can interpolate other vertex attributes this way as well, including normals (you may need to normalize afterwards). OpenGL can do this normalization for you if you glEnable( GL_NORMALIZE ) (in case you didn't know).

Then you can issue your GL calls with an intepolated set of vertices, possibly using vertex buffers, for example.

The tricky part is dealing with a change of sequence in the midst of a currently playing animation. It's perhaps easier to let the current sequence reach a whole frame number, then begin a lerp to the new sequence. Otherwise, a bilinear interpolation could be used to take the current linear interpolation to the beginning of the next sequence.

Anyway, I hope this helps.