[osg-users] [vpb] geographic to geocentric coordinate transformation
Elias Tarasov
elias.tarasov at gmail.com
Thu Jun 18 11:23:13 PDT 2015
Hello, Christian!
Again, your comments helped me:)
And again, i can't understand it from the first time.
The root of the problem here is how to move and rotate camera.
And the root of it is how to calculate needed matrices.
So, i looked for it:
1. Looked into general OSG forum.
2. Looked into vpb forum.
3. Stackoverflow.
There are a lot of info but to indicate what kind of problem i have, here is the pattern of what i found:
Vec3d eye( 1000.0, 1000.0, 0.0 );
Vec3d center( 0.0, 0.0, 0.0 );
Vec3d up( 0.0, 0.0, 1.0 );
viewer.getCamera()->setViewMatrixAsLookAt( eye, center, up );
Assumption:
Vectors must be defined with respect to some choosen coordinate frame.
So, with respect to what frame eye, center, up are defined?
How can i calculate them?
I presume, that without knowing in what frame vectors are expressed, and how to move to that frame from already defined frame (for instance from ECEF),
variables like Vec3d eye( 1000.0, 1000.0, 0.0 ) are useless.
Here is the code i changed according to your recomendations.
In the comments, there are at least three issues:
1. How to correctly define rotation?
2. How to define Up vector.
3. How to correctly add moved camera.
int main( int argc, char** argv ) {
osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Node> cessna = osgDB::readNodeFile("c:/OpenSceneGraph/data/cessnafire.osg");
osg::ref_ptr<osg::Node> map = osgDB::readNodeFile("c:/Terrain/FromUSGS/output/out.osgb");
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
//Getting XYZ position for cessna
//-85.4877762 is terrain's center lat
//30.5292506 is terrain's center lon
//100 m - height above terrain we want to place the cessna.
osg::Matrix cessnaLocation;
osg::EllipsoidModel ellipsoid;
ellipsoid.computeLocalToWorldTransformFromLatLongHeight(osg::DegreesToRadians(-85.4877762), osg::DegreesToRadians(30.5292506), 100, cessnaLocation);
osg::Vec3 positionForCessna = cessnaLocation.getTrans();
//Placing cessna
osg::ref_ptr<osg::PositionAttitudeTransform> moveCessna = new osg::PositionAttitudeTransform;
moveCessna->setPosition(positionForCessna);
moveCessna->addChild(cessna.get());
//Getting XYZ position for camera
//Lat Lon are the same, height is 150
osg::Matrix cameraLocation;
ellipsoid.computeLocalToWorldTransformFromLatLongHeight(osg::DegreesToRadians(-85.4877762), osg::DegreesToRadians(30.5292506), 150, cameraLocation);
osg::Vec3 positionForCamera = cameraLocation.getTrans();
//Placing camera
osg::ref_ptr<osg::PositionAttitudeTransform> moveCamera = new osg::PositionAttitudeTransform;
moveCamera->setPosition(positionForCamera);
moveCamera->addChild(camera.get());
//rotation and Y up
//How to setup rotation matrix? with respect to what coordinate frame? I presume View frame with respect to ECEF?
osg::Matrix rotation;
rotation.makeRotate(osg::PI_2, osg::Vec3f(1.0, 0.0, 0.0)); //Here we rotate around X on the angle pi/2. But rotate around what?
//How to define that matrix and why does it need?
osg::Matrix ToYUP; //Maybe here we can define a direction around of which we make our rotation?
//View = translation * YUP * rotation;
osg::Matrix viewMatrix;
viewMatrix = cameraLocation * ToYUP * rotation;
camera->setViewMatrix(viewMatrix);
//How to add moved camera?
root->addChild(camera.get() );
//Or maybe even camera->addChild( root.get() ); ?
root->addChild( moveCessna.get() );
root->addChild( map.get() );
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
viewer->setCamera( camera.get() );
viewer->setSceneData( root.get() );
return viewer->run();
}
Thank you!
Cheers,
Elias
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64123#64123
More information about the osg-users
mailing list