# 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.

## 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//-------------------------------------------------------------------------------void 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 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 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.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5
JoeJ
13

• 9
• 14
• 10
• 25
• 9
• ### Forum Statistics

• Total Topics
632645
• Total Posts
3007629
• ### Who's Online (See full list)

There are no registered users currently online

×