# Quaternions and motion capture

This topic is 5461 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
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 on other sites
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 on other sites
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.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 13
• 14
• 40
• 63