There’s clearly a language disconnect here.
I searched for a bit more information. Unfortunately, most explanations seem geared for people who don’t understand mathematics but do understand code. Which is the complete opposite of my situation! I did find the following site: http://www.songho.ca/opengl/gl_projectionmatrix.html which had quite a detailed explanation. In there, is the paragraph:
Note that both xp and yp depend on ze; they are inversely propotional to -ze. It is an important fact to construct GL_PROJECTION matrix. After an eye coordinates are transformed by multiplying GL_PROJECTION matrix, the clip coordinates are still a homogeneous coordinates. It finally becomes normalized device coordinates (NDC) divided by the w-component of the clip coordinates.
which might help to explain my confusion.
To do perspective projection (as that’s the OpenGL name) you have to do three steps:
- Apply a spatial transformation. This is done using the GL_PROJECTION matrix. The fact that it is a 4x4 matrix and acts on so-called homogeneous coordinates are aspects of implementation and nothing special.
- Apply the projection transformation. This is referred to in the final sentence of the quoted segment.
- Apply a view transformation. This is an application of a 2x2 matrix.
Now, when you write something like:
To make this a little bit clearer, here is what Codea does for every vertex on every frame:
Position = ModelView * Vertex
then I interpret that as at most implementing the first and third steps. This is because the middle one cannot be implemented as matrix multiplication. I was therefore assuming that it was not implemented at all. Reading around, I find that it can be implemented. That’s, in effect, what I’m asking: is it?
A-ha! Clicking further on that site I got to http://www.songho.ca/opengl/gl_transform.html and the diagram at the top of that is just what I need. The point is that the “divide by w” step is not a matrix transformation. However, there are no parameters involved in that step so to specify the entire transformation, one only needs to give the two matrices, the so-called perspective matrix and view matrix.
So what I want to know is this: is the “divide by w” step included in what you are going to implement when you put in true 3D support in meshes (for example)?
If yes, brilliant! Then, if you expose the two matrices I have all the pieces I need. Just please, please, please don’t say that you are “applying a matrix”. You are applying a non-linear transformation whose parameters are specified by a matrix. But the relationship between matrices and linear transformations is so strong that if you don’t specify that you aren’t doing this, the implication is that you are.
If no, please do! Otherwise, I still have to loop over my vertices so I may as well apply the transformation myself.
(The OpenGL commands appear to be glFrustrum()
and gluPerspective()
. Are these involved at all?)