I’m trying to get a simple 3D app working which will run on software wireframe when opengl is not present. Everything is working except one thing; the projection matrix. I’ve never been able to get a projection matrix working outside of opengl; instead I simply fudged it with something like this:
screen.x = (x / (z / Dist)) + screen.centerX
screen.y = (y / (z / Dist)) + screen.centerY
The mesh vertices are transformed first by the modelling/world matrices (translate, scale etc) and then by the UVN camera matrix. This does the job of a proper projection matrix but it just does’nt cut it. I’ve tried simple z-axis one-point projection matrices such as this:
when dist is derived from simple trig. It’s usually around 300. Everything I try always seems to produce a orthographic view with no depth foreshortening. The graphics books I have don’t account for this behaviour. What am I missing? Do I have to do something with these point after they are projected before they can be displayed?
Please note; I’m not a graphics newbie. I’ve programmed distributed raytracers, z-buffer renderers, filters and more. But this has always stumped me, and I want to solve it once and for all!
Perspective division is where OpenGL divides the components of each point by the w component. In my edition of the Red Book, it is page 674 that shows exactly what matrix glFrustum creates (It is the last page of Appendix F on homogeneous coordinates & transformation matrices.)
Not quite. x /= w, y /= w, z /= w, w /= w. Remember, you are multiplying a four-dimentional vector by a four-by-four matrix. The last row of the matrix isn’t necessarily 0,0,0,1; it only is if you have an orthographic projection.
Sections 2.11 (“Coordinate Transformations”) and 2.12 (“Clipping”) of the OpenGL spec offer a very thorough explanation of the whole transformation from object coordinates to window coordinates.