This topic has been covered before in various forms. Please see the following discussions for enlightenment...
http://forum.openscenegraph.org/viewtopic.php?t=4991&highlight= http://forum.openscenegraph.org/viewtopic.php?t=103&highlight= http://forum.openscenegraph.org/viewtopic.php?t=1786&highlight= -Shayne -----Original Message----- From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Aurelien Albert Sent: Sunday, September 25, 2011 6:26 AM To: osg-users@lists.openscenegraph.org Subject: [osg-users] Draw a line from world to screen Hi, I've made an Segment object which draw a segement from a point (x, y, z) to another (x, y, z) and working well. Now, I want to draw a "Connector line" from a point in space (x, y, z) to a point on screen (x, y). How can I transform my (x, y) screen point to find a equivalent (x, y, z) world point ? To convert from world to screen, this works well : Code: double width = pCamera->getViewport()->width(); double height = pCamera->getViewport()->height(); osg::Matrixd mv = pCamera->getViewMatrix(); osg::Matrixd mp = pCamera->getProjectionMatrix(); osg::Matrixd mw = pCamera->getViewport()->computeWindowMatrix(); osg::Matrixd worldToScreen = mv * mp * mw; osg::Vec4d position = osg::Vec4d(p_object->position(), 1.0) * worldToScreen; position = position / position.w(); double screenX = position.x(); double screenY = height - position.y(); But to convert from screen to world coordinate,I try this and it doesn't work : Code: osg::Vec4d screenPosition = osg::Vec4d(screenX, height - screenY, 0.5, 1.0); osg::Vec4d worldPosition = osg::Matrixd::inverse(worldToScreen) * screenPosition ; ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=42995#42995 _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or g _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org