Jump to content
  • Advertisement
Sign in to follow this  
GavinC

Quaternion woes with animation.

This topic is 3990 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, this is one of those "I'm pretty sure someone has already come up with a solution to this, but I can't seem to find it" kind of things. It's a situation so common that either "someone has solved this already", or "there is no solution, but there's a work-around". Basically, the situation I have is that I have a format exporter which exports a skeletal hierarchy, and all rotations are exported in quaternion format. This much works fine throughout. Then I have an animation-exporter which iterates through all anim-curves and exports the local rotation and translation of the skeleton-joint at that each keyframe. Again, this works fine. The problem occurs if the bind-pose rotation around a specific axis on a specific joint is non-zero (e.g. 0, 0, 180 in euler), and then the animation rotates around that same joint. The issue, simply put is that the rotation exported for an animation will not be relative to the bind-pose, but will be absolute, e.g. a rotation of 2 degrees on-top of the bind-pose position given above would be 0, 0, 182 in euler, resulting in a rotation of 0, 0, 362 instead! What I need to be able to do (without converting to Euler) is get a Quaternion representation of the difference between the desired rotation and the initial rotation. So if I started with an initial rotation of 0, 10, 90 (but stored a quaternion), and the desired rotation on the keyframe was 10, 30, 100, I'd need a way to return a quaternion, such that quaternion(fromeuler(0,10,90)) * thisquat = quaternion(fromeuler(10,30,100))... I need to know how to find 'thisquat'. Sorry if I didn't explain that clearly enough, but any help at all (including pointing me to relevant materials) is much appreciated.

Share this post


Link to post
Share on other sites
Advertisement
The inverse of a unit quaternion is its conjugate.

q1 * result = q2
inverse(q1) * q1 * result = inverse(q1)*q2
result = inverse(q1)*q2

similiar to:

point1 + vec = point2
vec = point2 - point1

to find the vector from one point to another, except that you're dealing with rotations and rotations aren't commutative.

Share this post


Link to post
Share on other sites
That's odd, I'm sure I tried that (wherein the inverse/conjugate of the quaternion is simply q(-x,-y,-z,w)).

It's quite possible that I was just multiplying them in the incorrect order.

As a happy side-note coincidence, I don't actually need to use this anymore, the main flaw in my animation code was coming from an error in the bind-pose on my test model. Once I fixed that all the problems went away.

Naturally, though, it's just good to know this kind of thing, so thanks anyway *remembers for later-use no-doubt*.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!