1
\$\begingroup\$

I am implementing a typical skeletal animation system, and it requires the usage of quaternion to interpolate rotations between each poses. The asset I import only has a transform matrix for each joint, so I need code to convert a rotation matrix to a quaternion. However, my game is in left-hand system, and most code snippet online out there are for right-hand system only. I tried the code for such conversion in a right-hand system from this gamasutra post. The animation interpolates correctly in some cases, but most of the time it's not working correctly, and here's the symptom:

Say I am animating a guy, in the first key frame he is in bind pose, and in the second key frame he's supposed to raise his right arm by 30 degrees. If my system interpolates the rotation correctly, his arm would slowly raise up to 30 degrees in the interval, maybe first frame it's 10 degrees, then its 15 degrees, and eventually 30 degrees. However, with the code I have, the guy's arm is rotating the longest path. First frame, the guy's arm rotates -30 degrees, then -60 degrees, and comes to the same place to where 30 degree is. Can anyone give me the code snippet that's equivalent to the gamasutra one, but for left-hand coordinate system? Thanks!

\$\endgroup\$
1
\$\begingroup\$

It sounds like you are (s)lerping the quaternion the long way around.

in your slerp (or nlerp) you should have a check that the dot(a,b) is greater than 0. Otherwise negate one of them.

\$\endgroup\$
  • \$\begingroup\$ Oh my god you are my hero!!! After adding that check it works now, thanks a lot!!! \$\endgroup\$ – ForeignDevil Aug 3 '17 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.