Steven Saunderson wrote:
I'm trying to rotate a camera on all axes but my code fails when the
x-axis or y-axis rotation approaches 90 degrees. I am using a
viewer.frame loop to avoid the default manipulator supplied by
viewer.run. My current camera code is :
cameraRotation.makeRotate (
yrads, osg::Vec3 (0, 1, 0) , // roll Y
xrads, osg::Vec3 (1, 0, 0) , // pitch X
zrads, osg::Vec3 (0, 0, 1) ); // yaw Z
cameraTrans.makeTranslate (xdist, ydist, zdist);
myCameraMatrix = cameraRotation * cameraTrans;
inverseMatrix = myCameraMatrix.inverse (myCameraMatrix);
inverseMatrix *= osg::Matrixd::rotate (-(osg::PI_2), 1, 0, 0);
viewer.getCamera ()->setViewMatrix (inverseMatrix);
When the pitch (xrads) is 0 everything works properly. But when xrads
is PI/2 the effect of yrads is identical to zrads (both do z-axis
rotation). I've tried applying the rotations in various orders but
the code fails when one of the rotations is PI/2.
Can anyone suggest what I am doing wrong here or point me to a sample
of working code ?
You've hit upon a phenomenon called 'gimbal lock'.
See
http://web.archive.org/web/20041029003853/http:/www.j3d.org/matrix_faq/matrfaq_latest.html#Q34
for an explanation (and possibly some different ways of controling your
camera).
Paul
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org