Quaternion to Euler xyz

I have looked in a lot of places and have been unable to find and answer to this problems, so I thought I might try here. Anyway, I am loading up a 3D file that uses quaternion to rotate object (I am programming in C++). I need to convert this rotation into a euler rotation. The rotation of the euler goes X then Y then Z. I don’t know much about quaternion rotations, but I just need to make a function that takes in w,x,y,z in quaternion and puts out the equivalent euler x,y,z. Is this possible? I don’t really know much about how the file stores the quaternion rotations, but as a test, I exported something with a rotation and found what the file said the quaternion is.
I got the following:
In: 90,1,0,0 File: 1.570796, -1.000000 0.000000 0.000000
In:180,1,0,0 File: 3.141593, -1.000000 0.000000 0.000000
This makes sense. It’s just exporting in radians not degrees. But, when I run any of the converters that I have found so far I get results that are way off.
Out:-135.000000 0.000000 0.000000
Out:-116.565041 0.000000 0.000000
I don’t think I need to post the code because it is clearly wrong. I just want to start clean. Could someone post a c++ source, a link to the source or at least a tip to point me in the right direction. That would be great.
Hopefully this is enough information.
Thanks in Advance for the help.

You might try taking a look at the Wild Magic library. He has routines for going back and forth between quaternions, rotation matrices and euler angles.

Relevant files are:




You can get the code either by buying the book or maybe scraping the website??
If you want to go this way I can testify that the math library is very ‘stand-alone’ and you can
easily incorporate the parts you want.

Just a thought…

This is probably the best resource to understand (and implement) the various rotation formats, including quaternion, Euler, matrix and so on: