Notifications
Clear all

[Closed] Quaternions and twisted joints

Hi,
I wrote some tools that import characters from certain game (Thief 1/2, System Shock2) and build IK/FK rigs, so you can animate the characters and import/export motions from and back to the engine. And while it works well for most of the part (example: https://www.youtube.com/watch?v=McMNFFnUevg&index=13&list=PLxCqosMVZXAc1ICSxOXRgHAwhBNyDOaYA ), I get problems with some of the motions – particularly player arms.
So, whenever I import motions onto these arm rigs, I get these twists – see attachment. The overall motion is OK – you can see the trajectory – it looks fine, but the joints are twisted like 180 degrees each.

Now, what is happening upon the import – the motions are stored as quaternions. I convert them to euler using quatToEuler function:


quatRot = (quat (ReadFloat MCfile) (ReadFloat MCfile) (ReadFloat MCfile) (ReadFloat MCfile))
eulerRot = quatToEuler quatRot order:AxisOrder.XYZ

I know that there’s more than one euler angles representation for a quaternion rotation value, and this might be my problem. But I have no idea how to detect it and how to choose an alternative representation.
I tried messing around with getEulerQuatAngleRatio function, but I don’t know what am I supposed to do with the value I’m getting. The Maxscript documentation says, that the axis flip occurs when the angle ratio is higher than PI, which it happens from time to time, but I don’t see a clear correlation between the frames it happens on and the resulting animation curves in Track Editor.
Does anyone have any hint on where should I look for a solution to these twisted joints?
Thanks!