Joe Krahn wrote:
>
> I'm looking at how Z values are transformed by glFrustum
> and am having problems. The following gnuplot matches the
> manual for glFrustum:
>
> n=10.0;f=50.0; plot [z=n:f] ( (f+n)/(fn)*z (2.0*f*n)/(fn) ) / (z)
>
> That gives me a curve with Z' ranging from 4 to 2 over
> the near to far range, which is wrong.
>
> If I change the sign of the second part of the equation:
> plot [z=n:f] ( (f+n)/(fn)*z +(2.0*f*n)/(fn) ) / (z)
> ^
> Now Z' goes from 1 to 1, like it is supposed to. I wonder
> if the man page is wrong (I've seen some glFrustum man pages
> drop the minus sign). SO, I look at the Mesa source in
> math/m_matrix.c. Mesa agrees with the first equation which
> looks wrong, but includes the comment /* error? */ after
> the second parameter which I am wondering about. Maybe
> someone else had the same question here.
>
> Surely the equation in Mesa is right, or there would
> be many rendering errors, and it would have been fixed
> by now. Does anybody have an idea of why the equation
> seems wrong for Z?
Try looking at the domain [50, 10] instead. Recall that you need
to use the modelview matrix to transform your coordinates from
object space to eye space before applying the projection matrix.
With perspective projection the modelview matrix is typically loaded
with a negative Z translation in order to move objects at (0,0,0) down
the negative Z axis.
Brian
