I got that code from one of the pages you had linked to.
Oh right. Sorry, I’m apparently still half-asleep.
What I wanted to say is that your comments about the variable names I have chosen were completely inappropriate and uncalled for. I understood the names well, and from the very simple code they were used in it was quite clear what they were.
What is inappropriate about pointing out that they’re wrong? It doesn’t matter if you understand them today; it’s still wrong.
If you have this code:
vec4 normal = gl_Position;
It is certainly syntactically correct. But it is both misleading and confusing for anyone trying to read it. You may happen to understand it, but it’s still wrong.
You aren’t seriously proposing that I am gonna start to manually do matrix computations to find out which coefficients to use, do you?
Well, that’s the brute force way. The more elegant way is to actually look at the matrix and see from inspection which values are used to compute Zclip and which ones are not. A matrix multiplication is just a linear system of equations for computing the output values.
Or, if you just want someone to give you the answer, assuming you’re using the standard glFrustum/gluPerspective projection matrices, it’s the last two columns of the third row of the matrix (assuming standard mathematical matrix conventions). In OpenGL terms, it’s “Zclip = projmat[2][2] * Zeye + projmat[2][3]”.