Sign in to follow this  
Thorgrim

Euler to Quaternion problem

Recommended Posts

Ok, here is what I'm trying to do: I'm making a 3d model format converter, and at the moment I'm working on animations. What I want to do is export an animation that is in quaternion rotation format, to SMD format (Euler angles). So far this works fairly well, I can export meshes bound to these animated skeletons to SMD format, load them into any animation package, and they display pretty much ok. The bones are often not aligned quite right in the reference pose, however they rotate fine, as does the mesh that is bound to them. My problem is when I try to import these animations back into Quaternion format. Of course euler angles can be converted to 2 possible quaternions (positive and negative). My problem is that I cannot think of an easy way to ensure that when imported, the right quaternion is used. Currently poses are seemingly randomly the opposite to what they should be, resulting in bones often rotating the wrong way. So has anyone done thing kind of thing before? Is the only way to get the right quaternions, to check against previous frames, and animations it might be morphed from, and ensuring the quaternion that results in a rotation of less than 180 degrees is picked? Or am I maybe exporting wrong? There must be some way to do it, since the importers for 3dsmax etc can manage to import what I export. If anyone has some ideas / suggestions / example code etc that would be great...

Share this post


Link to post
Share on other sites
Well, I worked on it a little more, and added a check against the reference pose, and negated the quaternion if the rotation from the reference pose was greater than 180 degrees. It seems to work for everything I have tried so far, though it may be better to try compare with the idle pose, since thats what most animations are closest to. Just thought I would post my fix incase anyone comes up against the same problem.

Share this post


Link to post
Share on other sites
Your result is unusual. A single rotation can be expressed as two different quaternions, q(s,v) and q(-s,-v). But it shouldn't matter which one you use, the result will be the same. Though I guess if you are slerping, it could affect the intermediate results. Perhaps the solution is to ensure that q.w >= 0, which would mean that the rotation is in the range [-pi,+pi]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this