As Paul mentions the is the age old Gimbal Lock problem The quick answer to this is to build a quaternion and use that populate the oration matrix
Or the really old nasty trick of limiting rotations to -89.5 thru +89.5 or so ... Gordon __________________________________________________________ Gordon Tomlinson Product Manager 3D Email : gtomlinson @ overwatch.textron.com __________________________________________________________ (C): (+1) 571-265-2612 (W): (+1) 703-437-7651 "Self defence is not a function of learning tricks but is a function of how quickly and intensely one can arouse one's instinct for survival" - Master Tambo Tetsura -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul Melis Sent: Thursday, October 30, 2008 6:10 AM To: OpenSceneGraph Users Subject: Re: [osg-users] Camera rotation on three axes 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/m atrfaq_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.or g _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org