In "OpenGL superbible" 4th Edition by RICHARD S.WRIGHT JR page 60, there's this piece of code that confuses me:
// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity()
aspectRatio = (GLfloat)w / (GLfloat)h;
if (w <= h)
glOrtho (-100.0, 100.0, -100 / aspectRatio, 100.0 / aspectRatio,
1.0, -1.0);
else
glOrtho (-100.0 * aspectRatio, 100.0 * aspectRatio,
-100.0, 100.0, 1.0, -1.0);
The glOrtho function multiplies the current matrix by an orthographic matrix, according to Microsoft document. In the above circumstance, the author chooses the projection matrix stack, which contains a matrix for the projection transformation, which describes the viewing volume(boundary of Viewport in my understanding).
The book just throws in my face those formulas without any explicit mathematical explanation. I did research what an orthographic matrix is but still confused about what do all these lines mean. Could you give me some idea about these lines?
These lines guarantee to keep a square a square when we resize the window.
I did try some mathematics. The given orthographic matrix with first six parameters would be:
\begin{matrix} \frac{1}{100} & 0 & 0 & 0\\ 0 & ratio*\frac{1}{100} & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1 \end{matrix}.
I computed the orthographic matrix according to Wikipedia definition of "orthographic matrix" based on six parameters(left, right, top, bottom, near, far), which matches the six parameters of glOrtho.
My first question is: What is the point of multiplying this matrix to the projection matrix?
My second question is: What is the significance of the condition $w \leq h$