Hi Steven,
Steven Saunderson wrote:
----- From: John Vidar Larring at 2008-10-30 21:42-----
Here is a snipplet of code from the osgautocapture example that I just
sent to osg-submissions (if my email got through?), provided as is. I
hope it might be of help:
Thanks for the code. I tried it (and it also rekindled my interest in
ViewMatrixLookAt) but I still got gimbal-lock. Perhaps my
implementation of your code is faulty.
I've spent days now trying to learn enough about quaternions. This
almost works but my calculation for the rotation angle is still
wrong. Is there a function in OSG for calculating a quaternion from
euler angles ? I've searched but haven't found anything.
Maybe the following is an easier way to accomplish what you want, as I
don't see why you are trying to calculate angles...
Assume that you want to apply the pitch, roll and yaw rotations to your
plane in that order. Also assume that you have your plane centered at
the origin with its nose looking down the positive Y axis and its
top-side pointing in direction of the positive Z axis. The pitch
rotation can then simply be around the global X axis.
However, the roll and yaw rotations will need to be around axes other
than the global Y and Z, as otherwise they don't take the changed plane
orientation due to pitch (and roll for the yaw rotation) into account.
For this, keep track of two helper points (osg::Vec3's): the first one,
p1, is at (0, 1, 0), the second one, p2, is at (0, 0, 1).
When you have calculated your pitch transformation, using for example,
osg::Quat(pitch_angle /* in radians */, osg::X_AXIS), you also transform
p1 with this quaternion. Let's call this transformed point p1t, and you
can simply p1t = q * p1 to get the transformed point. To apply the roll
rotation to the plane we then need to rotate around the vector that goes
through pt1 and the origin. This vector is simply p1t. So the roll
rotation would then be osg::Quat(roll_angle, p1t).
To apply the yaw rotation we need to transform p2 first by the pitch
rotation followed by the roll rotation: p2t = pitch_transform *
roll_transform * p2.
Then the yaw rotation will be osg::Quat(yaw_angle, p2t).
We now have three rotations defined by three quaternions. We only have
to combine these into a single transformtion to get the final plane
transformation:
q_final = q_pitch * q_roll * q_yaw
To convert q_final to a transformation matrix that you can pass to e.g.
osg::MatrixTransform::setMatrix() you can use
osg::Matrix m;
q_final.get(m);
// m will now contain the quaternion in matrix form
Hope this helps,
Paul
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org