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() *
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:
When i add a big sky shpere that surrounds the cow,scene changing to:
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;
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!