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.org

Reply via email to