RandyGaul / qu3e

Lightweight and Simple 3D Open Source Physics Engine in C++
zlib License
928 stars 111 forks source link

How can I read the XYZ euler angles from a q3Mat3? #56

Open wmcnamara opened 3 years ago

wmcnamara commented 3 years ago

I am having a bit of trouble extracting the XYZ euler angles from a 3x3 rotation matrix. I have this code that updates the position based on the transform given from the GetTransform() function.

const q3Transform& tr = body->GetTransform();
m_transform.SetPosition(tr.position)

I want to be able to set a rotation aswell, but I am not sure how to extract euler angles from the rotation matrix in the transform variable.

How would I go about getting euler angles from a rotation q3Mat3?

RandyGaul commented 3 years ago

Hi there, this is a math question unrelated to qu3e, but we can find some solutions with a google search on converting a rotation matrix to euler angles: http://www.close-range.com/docs/Computing_Euler_angles_from_a_rotation_matrix.pdf

There are multiple different sets of euler angles for a single rotation matrix. Typically in 3D games euler angles aren't used by the lower level parts of the engine due to inconvenience in doing so. Sometimes artists or similar like to input euler angles through a user interface, but generally those angles are converted to a rotation matrix for the runtime.

So there's no built-in function in qu3e to do this. But you can write the code to do this yourself, if you like :)