Sign in to follow this  

Quaternion woes with animation.

This topic is 3778 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
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

This topic is 3778 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.

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