## mesa3d-users

 [Mesa3d-users] glFrustum matrix problems From: Joe Krahn - 2002-04-08 12:50:06 ```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)/(f-n)*z -(2.0*f*n)/(f-n) ) / (-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)/(f-n)*z +(2.0*f*n)/(f-n) ) / (-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? Thanks, Joe Krahn ```
 Re: [Mesa3d-users] glFrustum matrix problems From: Brian Paul - 2002-04-08 14:25:38 ```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)/(f-n)*z -(2.0*f*n)/(f-n) ) / (-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)/(f-n)*z +(2.0*f*n)/(f-n) ) / (-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 ```