[osg-users] getting the world coordinate by screen coordinate in a sky shpere

Qi Liu 748503128 at qq.com
Mon Jan 7 17:58:31 PST 2019


Hi,all

    I am a new to osg and I use the following method to get the world  coordinate by screen corrdiante and it works well: 
osg::Matrix VPW = viewer->getCamera()->getViewMatrix() *
viewer->getCamera()->getProjectionMatrix() *viewer->
getCamera()->getViewport()_>computeWindowMatrix();
osg::Matrix Inm = osg::Matrix::inverse(VPW);
osg::Vec3d world = (osg::Vec3d(pos.x(), pos.y(), 0)) * Inm;

My scene is quite sample,the root has only one child:
root->addchild(osgDB::readNodeFile("cow.osg"));


When i add a big sky shpere that surrounds the cow,scene changing to:
    root->addchild(osgDB::readNodeFile("cow.osg")); 
    osg::ref_ptr<osg::Drawable> drawable = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f, 0.0f, 0.0f), 100));
   osg::ref_ptr<osg::Geode> geode = new osg::Geode;
   geode->addDrawable(drawable.get());
   root->addchild(geode);

I cannot get the right world  coordinate when my camera move inside the sphere by the above method. 

Did I miss something?Is there some way to  ignore the sphere and then to get the world coordinate by screen coordinate?
 
If anyone could point me in the right direction with some simple code,it is very much appreciated. Thanks a lot!

Thank you!

Cheers,
Qi :D

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







More information about the osg-users mailing list