Currently I'm using NewtonBodyGetRotation to retrieve each body's rotation matrix, followed by GetEulerAngles to get the rotation in the form of euler angles to pass into glm::quat. However, GetEulerAngles returns two dVectors rather than just one as I would expect, and I'm not sure how to combine them to get a single euler angles vector.
Alternatively, if there's a simpler way to keep my rotations in sync that I missed, please let me know.
EDIT: I got so caught up in using euler angles, that I did not try simply converting the rotation matrix returned by NewtonBodyGetRotation directly into a glm::quat. Syncing rotation this way works as expected, and is more performant too. I am still curious about the fact that GetEulerAngles returns two dVectors instead of 1, but regardless my question is solved. Here's the code I used:
- Code: Select all
dMatrix rot;
NewtonBodyGetRotation(body, &rot[0][0]);
glm::quat q(rot[0].m_w, rot[0].m_x, rot[0].m_y, rot[0].m_z);
GO->rotation = glm::toMat4(q);