Jump to content
  • Advertisement
Sign in to follow this  

Angles to Quaternion

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

If you intended to correct an error in the post then please contact us.

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
Does your book have a matrix to quaternion function? I would use that instead.
If you put the angles in a matrix, you can extract them in any order you want.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!