Hi Guy, Are you sure result is 3 ? Maybe rather -3 ?
OpenGL is by default (view=identity) looking along Z- axis. When you set near N and far F this means near plane contains point(0,0,-N) and far plane contains point(0,0,-F). So if you want ot get z=1 from multiplication by ModelViewProj you should rather use pt = vec3( 0,0,-zw/z) in your example. Please also note that gluProject also takes viewport and converts your result to Window coordinates where depth range is 0..1. After projection (and scaling by w coordinate) resulting range is -1..1. So called Widnow matrix translates point values from postprojective space to window space. Cheers, Wojtek From: Guy Sent: Wednesday, July 28, 2010 11:23 AM To: [email protected] Subject: [osg-users] ModelView and Projection Matrices Hi all, I'm encountering an inconsistency between OpenGL vertex manipulation and OSG. It is almost sure that it's my own misuse of OSG so I will present the issue and be glad to learn. J I'm trying to force a point in orthographic projection to have a specific z value. Suppose z = 0.95 I know the world point is (xw,yw,zw) So I calculate near/far planes in orthographic projection to be [0, zw/z] Then I create the projection matrix to be osg::Matrix new_proj = osg::Matrix::ortho(-(width*0.5),width*0.5,-(height*0.5),height*0.5, 0, zw/z); osg::Matrix new_view = osg::Matrix::identity(); The model view matrix is identity. Now, I create a dummy vertex to check the projection: osg::Vec3 pt(0,0,zw/z); osg::Vec3 s = new_proj.preMult(new_view .preMult(pt)); I would expect s.z() to be 1 or a smaller number but very very close to one. What I get is 3. (width x height are 160x120. zw = 800) When I use the utility function double x,y,z; int success = gluProject(pt.x(), pt.y(), pt.z(),new_view.ptr(), new_proj.ptr(), vp, &x, &y, &z); z is very close to 1 (0.9997.) as was expected. Can anyone explain? Thanks, Guy L. -------------------------------------------------------------------------------- _______________________________________________ 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

