Hi Kees,

I would expect (0,0,-zNear,1) to transform to (0,0,-1,1).

zFar and zNear are positive in the direction you're looking and negative
behind you.  I didn't see anything in the osg code that defines zFar and
zNear as being the actual Z values.  Perhaps having the variables begin
with "z" is misleading you.  They really don't have anything to do with
the Z axis.  Dropping the "z" is a problem since some compilers use near
and far as keywords.  Less confusing names might be nearClip and
farClip.

-----Original Message-----
From: Kees van Kooten [mailto:kvankoo...@virtualproteins.com] 
Sent: Wednesday, April 15, 2009 5:49 AM
To: osg-users@lists.openscenegraph.org
Subject: [osg-users] The orthographic projection near/far plane

Hi,

I don't know whether this has been brought up before (I couldn't find
any posts regarding this matter in the user forum), but when using the
orthographic projection matrix's setProjectionMatrixAsOrtho(), the
near/far plane z values supplied as arguments are not set as according
to the OpenGL spec. Specifically, the third column of the projection
matrix as applied by osg is:

0.0,
0.0,
-2.0/(zFar-zNear),
-(zFar+zNear)/(zFar-zNear)

with zFar and zNear being the actual Z values of the far and near plane 
- as opposed to the distance to the far and near plane mentioned in the 
spec, which in practice turns out to be the negated z value of the far 
and near plane.

If this has been a conscious choice, it seems highly confusing to me. 
For example, the vector (0,0,zNear,1) now transforms to 
(0,0,-(3zN+zF)/(zF-zN),1) in clip space, while the expected 
transformation would yield (0,0,-1,1). In practice, it gave me a few 
problems integrating an orthographic projection with depth to a 
partially rendered scene.

Of course, the workaround is easy, as one should just supply the negated

zNear and zFar to setProjectionMatrixAsOrtho(), and in a certain way 
this is all just a matter of interpretation of the function arguments. 
In my opinion, supplying the actual z values for the near and far plane 
is the more intuitive choice, as this is what the names of the function 
arguments imply.

Best regards,
Kees van Kooten




_______________________________________________
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

Reply via email to