Chen96
Chen 21 posts

#12725
Help: matrixtoquaternion in lefthand coordinate system 2 months, 2 weeks ago
Hi all, I need help on converting a pure rotation matrix to quaternion for my animation system in lefthand coordinate system. I've been trying out matrixtoquaternion equation from this gamasutra post. In the post, the author stated that the conversion code snippet that he provided has the assumption that the rotation matrix is in righthand system. However matrices in my game are always in lefthanded coordinate system. I copied the code snippet anyway, and as expected, it wasn't doing the right thing.
It didn't make sense why handedness would make a difference, so I did some testing on the code. I convert rotation matrices generated with Euler angles to quaternions using the code snippet from the gamasutra post. Then I convert the same Euler angles to quaternions using an online tool. The quaternion generated in my code and the quaternion generated by the online tool always have different signs, but euler angles they map to are the same. So it seems like their final orientation is the same, but the path the rotation takes are opposite. I have no idea how to fix this. I later stumble across this stackoverflow post. In the post, one guy commented "Matrixtoquaternion has to make a choice that stays always on the same halfsphere of unit quaternions". I feel like that is the key to solve my problem, but I don't know how because I have no idea how that snippet code works or how to always "stay in the same halfsphere" :( So my question is, why was the code snippet in that gamasutra post "handedness sensitive", how it's derived, and what changes should be made to that code so that the converted quaternion always "stays in the same halfsphere" in a lefthanded system? Thanks a lot! Alex 