Question

I had skeletal animation in my program working fine, but I was interpolating between the 4x4 matrices stored for each bone between frames in a linear way, i.e.


bMatrix bMathbMathInterpolate(bMatrix const * const p_a,bMatrix const * const p_b, float p_delta)
{
    bMatrix l_mat;

   for(unsigned char i = 0;i lessthan (edit: sorry less than symbol break it) 16;i++)
         l_mat.m_values[i] = bMathInterpolate(p_a->m_values[i], p_b->m_values[i], p_delta);

   return l_mat;
}

Which is O.K. unless of course there is a large amount of rotation in the matrix - the model becomes slightly squashed between keyframes.

So, I made a separate interpolation algorithm than converts the rotation part only of a 4x4 matrix into a quaternion, performs SLERP, and replaces the rotation part only of the matrix with the matrix version of the quaternion. For the translation part of the matrix, I just interpolated it in a linear way.

Looking at the results, this is obviously wrong!!! :'(

If you understand all this very well (unlike myself), you're probably thinking "No! That's not how you do it!" - if so, please tell me what I'm doing wrong!!

I don't know what to do with the translation part of the matrix, because I can only find resources that tell you how to convert back and forth between a quaternion and 3x3 matrix.

Any help will be much appreciated!!!!

Was it helpful?

Solution

You should be able to convert the translation component of the matrices to vectors, and then linearly interpolate them, and then convert the rotation component to a quaternion, and slerp (or lerp, or nlerp) them, and then recombine the resulting vector and quaterion back into a matrix.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top