simple quaternion question
Hi all, i know a bit about quaternions, but what i can''t seem to get to work is rotating a point in 3d space by a quaternion.
point P = (x, y, z)
quad q = (X, Y, Z, W)
the quad is the orientation of the object relative to the identity matrix. If i rotate an object i just calculate the axis angle representation of the quaternion and call glRotatef. Now if i''m calculating shadow volumes i want my lightvector to correspond to the light position in world coordinates. Because i rotated the modelviewmatrix for the drawing of the object i should also do that for the shadowvolume. The direction of the light has to be rotated the inverse of this rotation for the volume to be correct. The problem is that i don''t know how to rotate a vector with a quaternion in a direct and fast way.
Thanx,
Marty
_____ /____ /|| | || MtY | ||_____|/Marty
I thought of an easyer way to say this
this is what it should do, but in a direct way, not using the matrix:
m = QuaternionToMatrix(q); // get the equivalent rotation matrix from the quaternion q
Invert(m); // we need the rotation to undo the rotation done by m, so we use the inverse rotation matrix
v = v*m; // rotate the vector v with this rotation matrix
this is what it should do, but in a direct way, not using the matrix:
m = QuaternionToMatrix(q); // get the equivalent rotation matrix from the quaternion q
Invert(m); // we need the rotation to undo the rotation done by m, so we use the inverse rotation matrix
v = v*m; // rotate the vector v with this rotation matrix
_____ /____ /|| | || MtY | ||_____|/Marty
The basic method is as follows:
Represent the vector as a quaternion, using your notation this is:
(X = x, Y = y, Z = z, W = 0)
Now the rotated vector is:
T(x) = q * x * q*
Where q is your quaternion rotation (i.e. unit) and x is the quaternion representation of your vector as above.
EDIT: doh got the formula wrong, and this is an excellent concise treatment of quaternions.
[edited by - JuNC on January 31, 2004 4:23:26 PM]
Represent the vector as a quaternion, using your notation this is:
(X = x, Y = y, Z = z, W = 0)
Now the rotated vector is:
T(x) = q * x * q*
Where q is your quaternion rotation (i.e. unit) and x is the quaternion representation of your vector as above.
EDIT: doh got the formula wrong, and this is an excellent concise treatment of quaternions.
[edited by - JuNC on January 31, 2004 4:23:26 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement