Sign in to follow this  
Toby Evetts

Quaternions and motion capture

Recommended Posts

Toby Evetts    122
Ok, here goes. I'm trying to write an importer of BVH motion capture data which has a heirarchical structure and gives me offsets for bones and frame by frame rotations. I figured out how to make it work wonderfully with rotational matrices but I'm getting what I take to be gimbal lock issues when I play back the data (some of my bones frame by frame flp round 180 degrees for a moment). So full of bravery and without caution I started looking at quaternions. I've written functions that convert all the euler angles in my matrices into quaternions, multiply them together and then give me a result but what I can't figure out is how to apply that back to the positional data. In matrices I just had two 4x4 matrices that I mulltiplied together. One had the rotation for that bone and their offsets and the other the cumulative rotations and transformations for the parent bones. When I multiplied them together it gave me a new matrix with the new translational xyz for the bone. How would I do this with quaternions? I can convert all my rotations to quaternions and I can multiply them together but I can't figure out how I would combine this with my xyz coordinates to give me new positions. Would I multply the two transition bits togerher the first three in column 3 of my matrices and them put this back in the final matrix, would I turn them into quaternions and mulitply them? I'm lost.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
The main problem with gimble lock with matrices come when you are interpolating as the path taken by a vector can swing around since the matrix can represent a direction but not how you ar eoriented in that direction.

The ideal is to take your euler angles, convert them straight to quaternion. Then you can do any interpolation and other operations you need (such as a slerp to interpolate). Once you are ready to render, you can simply convert your quaternion back to a matrix and use that as-is.

At least, this is what i do in my animation system and it works just fine :)

Share this post


Link to post
Share on other sites
Toby Evetts    122
But I need to combine the two (parent and current) matrices with the translations and I figured that's was causing my lock. Is it possible there's something else causing bones to flip around for a frame or so?

How would I combine two matirces (including translational data) if I wanted to do it with quaternions?

Share this post


Link to post
Share on other sites
jvsquare    184
Assuming you're using column matrices for your vectors, then you combine the 4x4 matrices as
M' = M2*M1
where you transform by M1 and then M2.

If you broke these into the upper-left 3x3 rotation matrix R and the right-most translation vector t, you'd find that
R' = R2*R1
t' = R2*t1 + t2
Basically you need to rotate the child's translation vector into the parent frame before adding it to the parent's translation vector.

For quaternions, you do the same thing, except that rotating your translation vector is a little different:
q' = q2*q1
t' = q2*t1*q2^-1 + t2

If you're using a uniform scale factor s, then it's
s' = s2*s1
q' = q2*q1
t' = s2*(q2*t1*q2^-1) + t2

Non-uniform scale doesn't work with this, btw.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this