
How to interpolate between two rotation matrices? 
nonnus29
Member #2,606
August 2002

Right, so I've been reading up on skeletal animation and it all makes sense except for when it comes to applying the movement. If a model is keyframed then you have to apply the matrices to the vertices incrementally or it'd look like crap. So how do you interpolate a 4x4 matrix? Is it as simple as interpolating each of the elements of the matrix between the start and end matrix elements? Erm, if that doesn't make sense let me know... Edit; I gave credit once but it won't let me again? 
Kirr
Member #5,060
September 2004

exquat.c  
miran
Member #2,407
June 2002

Yeah, you can't just interpolate between matrices like that. You'd get totally unpredictable results. The first thing you'd think to do would be to interpolate between Euler angles and construct intermediate matrices at every step. This is very simple and easy to code, but has some negative side effects so you unless you want to see what those are, you shouldn't even try to implement it. Instead you should use quaternions, as Kirr said. Allegro conveniently has all the functions you need, and even an example...  
Evert
Member #794
November 2000

Quote: So how do you interpolate a 4x4 matrix? Is it as simple as interpolating each of the elements of the matrix between the start and end matrix elements? No. What you want to do is interpolating between a set of rotation angles (typically two or three for a rotation in threedimensional space). Interpolating between the matrix elements is a bad idea because they are not independent (although if they are `near to eachother' in the sense that the rotation angles are `close' (modulo 2pi) you should not introduce too big an error). You can look into Euler angles, but a better idea would indeed be to use quaternions instead: they can be interpolated more easily and directly. 
nonnus29
Member #2,606
August 2002

Ah, so this is what quaternions are used for.... Quote: Allegro conveniently has all the functions you need, and even an example...

Tobias Dammers
Member #2,604
August 2002

Yep. You could interpolate matrices, but the result would be quite different from what you expect. Imagine you have two versions of your object, one before and one after the rotation. You interpolate between these two per vertex; a bit like morphing and not at all desirable. Each vertex will move to its new position on a straight line.  
gillius
Member #119
April 2000

Everyone is right somewhat. It is impossible to "interpolate" a matrix in the general case and get a rational result. Tobias says you could do it, and he is right, but the result would be bad, as he said. So Evert is also right in the general case, although you can convert a matrix to a quanternion if and only if you know that the matrix is precisely a rotation matrix only. This is important if your keyframe generator generated only matrices as keyframes. You might be able to pull out the components needed to generate quanternions, which should be possible if you know that there is no scaling and only rotation and translation.
Gillius 
Tobias Dammers
Member #2,604
August 2002

Quote: You might be able to pull out the components needed to generate quanternions, which should be possible if you know that there is no scaling and only rotation and translation.
...which is what allegro's quat_to_matrix() does for you. It extracts rotation information from the matrix and transforms it into a quaternion. You can manually grab and interpolate the translation part, but you won't be able to use the scaling part.  
nonnus29
Member #2,606
August 2002

That's probably what I'll end up doing; this will be for the lwjgl 16k contest. So what I'm planning on doing is loading one set of vertices for the character, then tranform each joint for an animation frame and store the resulting set of vertices. And then simply morph the mesh between frames. This has the benefit that I'll at most need 2 angles per joint which can be stored in a byte (1 byte per angle). Aren't I clever? 
