Hi Steven,
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:
...
// Compute eye point in world coordiantes
osg::Vec3d eye;
csn->getEllipsoidModel()->convertLatLongHeightToXYZ(lat, lon, alt,
eye.x(), eye.y(), eye.z());
// Build matrix for computing target vector
osg::Matrixd target_matrix = osg::Matrixd::rotate(-heading,
osg::Vec3d(1,0,0),
-lat,
osg::Vec3d(0,1,0),
lon,
osg::Vec3d(0,0,1));
// Compute tangent vector ...
osg::Vec3d tangent = target_matrix.preMult(osg::Vec3d(0, 0, 1));
// Compute non-inclined, non-rolled up vector ...
osg::Vec3d up(eye);
up.normalize();
// Incline by rotating the target- and up vector around the
tangent/up-vector
// cross-product ...
osg::Vec3d up_cross_tangent = up ^ tangent;
osg::Matrixd incline_matrix = osg::Matrixd::rotate(incline,
up_cross_tangent);
osg::Vec3d target = incline_matrix.preMult(tangent);
// Roll by rotating the up vector around the target vector ...
osg::Matrixd roll_matrix = incline_matrix * osg::Matrixd::rotate(roll,
target);
up = roll_matrix.preMult(up);
viewerWindow->getCamera()->setViewMatrixAsLookAt(eye, eye+target, up);
...
Best regards,
John
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 ?
Thanks,
Steven
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
--
Best regards,
John
WeatherOne
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org