Very recently, I did this in a shader to create a projected texture, generating the texture coordinates by projecting the vertices. The process is essentially the same in OSG as in OpenGL.
Find the lowest Transform that applies to your vertex, and its NodePath (use a NodeVisitor), then call computeLocalToWorldMatrix(). This gives you the accumulated local to world matrix (l2w). Then you multiply by the view matrix, as you have below. But you also need the projection matrix. Get both of these from the Camera. This gets you clip coordinates. So you have something like: // Get clip coordinates from object coordinates. Vec3 cc = oc * l2w * view * proj; Then do the perspective divide (divide by w). Next you need to scale and bias by the viewport and depth range into window space. // Get window coords from clip coords. float wc.x() = (cc.x() / cc.w() + 1.) * (vp.width() * .5) + vp.x; float wc.y() = (cc.y() / cc.w() + 1.) * (vp.height() * .5) + vp.y; float wc.z() = (cc.z() / cc.z() + 1.) ... // something similar here for depth range, if you care about the z value. After this, you'll probably want to invert y to account for the window origin in upper left corner (instead of lower left corner like in OpenGL). To get screen space, you will finally need to offset the xy window coords by the window position on the screen. Off the top of my head, I don't know how to obtain the window offsets from OSG. Paul Martz Skew Matrix Software LLC http://www.skew-matrix.com +1 303 859 9466 -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Hagen Sent: Monday, April 20, 2009 5:00 AM To: [email protected] Subject: [osg-users] 3D Point to ScreenSpace Coordinates Hi, given a 3d Point and i want to know the corresponding screenspace coordinates. given a osg::Vec3 p do i have to do that this way? osg::vec3 result = p * viewer->getViewMatrix(); and then i just ignore z? Thank you. ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=10412#10412 _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

