Hi,

I went through all the discussions on north compass. 
I have  displayed  the discussed code and the way I m making use of it for my 
osgEarth. But it s not working in my case.I m not sure what is to be done.

osg::Matrixd calculatePositionMatrix( const osg::EllipsoidModel* ellipsoid, 
const osg::Vec3d &newPosition, const osg::Vec3d &oldPosition)

{
osg::Matrixd localToWorld, worldToLocal;

ellipsoid->computeLocalToWorldTransformFromXYZ( 
newPosition[0],newPosition[1],newPosition[2],localToWorld );

worldToLocal = Matrix::inverse( localToWorld );

osg::Vec3d newPosInNewPosLocalCoordSystem = osg::Vec3d( 0,0,0 ); // == 
newPosition * worldToLocal;

osg::Vec3d oldPosInNewPosLocalCoordSystem = oldPosition * worldToLocal;

osg::Vec3d moveInNewPosLocalCoordSystem = newPosInNewPosLocalCoordSystem - 
oldPosInNewPosLocalCoordSystem;

double heading = atan2( 
moveInNewPosLocalCoordSystem[1],moveInNewPosLocalCoordSystem[0] );


// usually pitch in local tangent space can be computed
// like this (radians):
//double pitch = atan2( moveInNewPosLocalCoordSystem[2], hypot( 
moveInNewPosLocalCoordSystem[0], 
//moveInNewPosLocalCoordSystem[1] ));

pitch = 0.0;
double roll = 0.0;

osg::Matrix turnRight90DegreesClockwise = osg::Matrix::rotate( 
osg::DegreesToRadians( -90.0 ), osg::Vec3d( 0,0,1 ) );

osg::Matrix rotateToMatchLocalHeading = osg::Matrix::rotate( heading, 
osg::Vec3d( 0,0,1 ) );

osg::Matrix rotateToMatchLocalPitch = osg::Matrix::rotate( pitch, osg::Vec3d( 
1,0,0 ) );

osg::Matrix rotateToMatchLocalRoll = osg::Matrix::rotate( roll, osg::Vec3d( 
0,1,0 ) );

// So the matrix would be like this:
osg::Matrixd matrix = turnRight90DegreesClockwise * rotateToMatchLocalRoll * 
rotateToMatchLocalPitch * rotateToMatchLocalHeading * localToWorld;

return matrix;
} 

.......
...
...

For every FRAME:
...
..
osg::Vec3d newpos=viewer.getCameraManipulator()->getViewPoint();
osg::Matrixd rot=calculatePositionMatrix(ellip_model, newpos, oldpos);
compassMT->preMult(rot);
oldpos=newpos;
.....
....


Thanks,
A. Akilan

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=32349#32349





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to