Convert quaternions from D3D to OpenGL

Started by
17 comments, last by Zakwayda 14 years, 4 months ago
Hi there. I'm reading the model files from Dawn of war, and i've come into a bit of trouble. All the quaternions stored there are assuming an axis orientation of Direct3D. (Z axis coming toward the user), while I'm using OpenGL (Z axis going away from the user). So, the models appear somewhat "reflected". It appears correctly if i just invert the Z coordinate, but then I don't know how to invert the rotation quaternions of the animations. How can i do it? Basically, it's just inverting the Z axis (I think).
Advertisement
To invert the rotation represented by a quaternion, invert the quaternion (which, for unit-length quaternions, is equivalent to conjugation). Or, you can just negate the 'w' component (which will give you the negative of the conjugate, and since q and -q represent the same rotation, the result will still be correct).
Hmm, but won't that negate the whole rotation? I just want to negate the Z axis.

So, for example, if the rotation means 30 degrees clockwise, i want it to remain exactly the same, but with negative Z.


But, again, I don't know what i want so surely, anymore. been fighting with this for a few months, now. I'll try your sugestion.
Hmm, but won't that negate the whole rotation? I just want to negate the Z axis.

So, for example, if the rotation means 30 degrees clockwise, i want it to remain exactly the same, but with negative Z.


But, again, I don't know what i want so surely, anymore. been fighting with this for a few months, now. I'll try your sugestion.
A quaternion cannot represent a flip in a coordinate. What you need to do is flip the z coordinate of the points as you load your model.
Try negating the X and Y components (i and j).
-- gekko
Fliping the Z coordinate of the model displays the model correctly, yes.
All the vertices of the model are relative to (0,0,0), with no transformations or rotations.

The problem is the skeleton. If I just flip the Z coordinate of the bones do you imagine what happens? Mayhem.

So, that should not be the solution.

I'm gonna try inverting w later today, when i get home.
And then, invert x and y, as suggested. Let's see what comes from that...


For the quaternions, try negating the z and w elements (no guarantee that'll work, but it seems that reflecting the axis across the xy plane and reversing the direction of rotation might have the desired effect).
Ok, negate W on the quaternion.
or X and Y.
or X and Z.

AAAAAAAAAHHHHHHHHHHHHHHHHHH

(bangs head on wall)

or just leave programming and open a bakery
Ok, negate W on the quaternion.
or X and Y.
or X and Z.

AAAAAAAAAHHHHHHHHHHHHHHHHHH

(bangs head on wall)

or just leave programming and open a bakery

This topic is closed to new replies.

Advertisement