I am rotating points using quaternions of the form [w x y z]
. My initial quaternion is the identity, [1 0 0 0]
.
When I press Q, I multiple my current quaternion by [0.1 0 1 0]
to get a rotation around the y-axis. This works correctly, for the most part.
However, if I continue to rotate (as long as I hold down Q), the rectangle I am rotating constantly flips back and forth producing a ghost-like image of itself. It appears as if it is drawing itself forwards, backwards, forwards, backwards, forwards, backwards, etc.
The following is the code I use to generate the transformation matrix from the quaternion:
1 - 2yy - 2zz 2xy - 2wz 2xz - 2wy
2xy + 2wz 1 - 2xx - 2zz 2yz - 2wx
2xz - 2wy 2yz + 2wx 1 - 2xx - 2yy
As I said, though, it seems to be rotating correctly. It just flips back and forth very quickly. (So quickly that I was unable to capture an animated GIF of the problem.)
What could be the issue?
I think your equation is off by a sign in the top right corner, does this work for you
1.0 - 2.0yy - 2.0zz, 2.0xy - 2.0zw, 2.0xz + 2.0yw
2.0xy + 2.0zw, 1.0 - 2.0xx - 2.0zz, 2.0yz - 2.0xw
2.0xz - 2.0yw, 2.0yz + 2.0xw, 1.0 - 2.0xx - 2.0yy