Sign in to follow this  

Angles to Quaternion

Recommended Posts

I am attempting to apply BVH motion capture data to MD5 models. Generally, BVH files use ZXY angles to describe bone rotations. MD5 uses quaternions. I'd like to convert the angles into a quaternion. "Essential Mathematics for Games and Interactive Applications" describes a method to convert a ZYX angle into a quaternion. Does this need to be modified to use the ZXY format from a BVH file? Here is the source code from the book's Quaternion class:

// @ IvQuat::Set()
// Set quaternion based on fixed angles
IvQuat::Set( float zRotation, float yRotation, float xRotation )
zRotation *= 0.5f;
yRotation *= 0.5f;
xRotation *= 0.5f;

// get sines and cosines of half angles
float Cx, Sx;
IvSinCos(xRotation, Sx, Cx);

float Cy, Sy;
IvSinCos(yRotation, Sy, Cy);

float Cz, Sz;
IvSinCos(zRotation, Sz, Cz);

// multiply it out
w = Cx*Cy*Cz - Sx*Sy*Sz;
x = Sx*Cy*Cz + Cx*Sy*Sz;
y = Cx*Sy*Cz - Sx*Cy*Sz;
z = Cx*Cy*Sz + Sx*Sy*Cx;

} // End of IvQuat::Set()

Share this post

Link to post
Share on other sites
The variable here is axis order. If the code you have there happens to combine the rotations in the order ZXY, then you're all set. Otherwise, you'll probably need to revise the code so that it uses that order.

An easy way to ensure the right order is simply to create three separate quaternions and combine them. This will introduce some unnecessary operations, but that'll only be a problem if the conversion process is a bottleneck. (Or course if you want maximum efficiency, you can work out the optimized version by hand.)

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