This was passed to the developers list today, sorry for the delay in
responding - I have added myself to the users list now so I can answer any
further questions =)
Thats a neat way of rotating with quaternions, I think its cool that it
works - but its not the best way to do it =)
If you dig into the quaternion code you will find:
inline void sgRotQuat ( sgQuat dst, const SGfloat angle, const sgVec3 axis )
{
sgQuat q ;
sgAngleAxisToQuat ( q, angle, axis ) ;
sgPostMultQuat ( dst, q ) ;
sgNormaliseQuat ( dst ) ;
} ;
As you can see when you want to rotate a quaternion the axis vector gets
combined with the angle to make a new rotation quaternion - and then it
*post* multiplies the two of them together.
Because of the complex math behind quaternions Q1 x Q2 is NOT equal to Q2
x Q1.
So if a post multiply rotates around the worlds axis, what could a pre
multiply do? It rotates around the local axis of course!
void sgPreRotQuat ( sgQuat dst, const SGfloat angle, const sgVec3 axis )
{
sgQuat q ;
sgAngleAxisToQuat ( q, angle, axis ) ;
sgPreMultQuat ( dst, q ) ;
sgNormaliseQuat ( dst ) ;
}
So why isnt there a PreRotQuat function (or something with a much better
name) in SG? Oversight I suppose. Nobody has been using them so it hasn't
been missed. Before we add something to SG I think we need to come up with a
clear name for the rotations that will convey what they do. Just calling
them sgPreRotQuat and sgPostRotQuat isn't very clear.
What about sgWorldRotQuat (for post), and sgLocalRotQuat (for pre) ?
-Michael Kurth
-----Original Message-----
From: pli...@li...
[mailto:pli...@li...]On Behalf Of Bob Hammond
Sent: Saturday, September 02, 2000 1:30 PM
To: pli...@li...
Subject: [Plib-users] Quaternion rotations
Hi,
I downloaded the latest CVS version of plib and found the new quaternion
demo (with the two rotating cubes). This demo rotates the quaternions
around the world axes (using sgRotQuat(..) ).
How can I use quaternions to rotate an object around it's axes? I've got an
idea that might work. Say I want to rotate around the x axis, I convert my
quaternion to a matrix, extract the first column and use this as the vector
passed to sgRotQuat.
Ie.
sgMat4 tmpMat ;
sgQuatToMat ( tmpMat, myQuat ) ; // Make the matrix from the quaternion
sgRotQuat ( myQuat, 5.0, tmpMat [0] ) ; // Rotate 5 degress around objects x
axis
Since we're only using the first row of the matrix the above can probably be
simplified.
Will this work? Is there anything else I need to know (stuff that might bite
me in the ass?) ?
|