First, you can see how these matrices are defined for the corresponding calls to glOrtho
and glFrustum
(or similar functions from your structure). The next steps depend on the type of projection, which is either spelling (for example, from glOrtho
) or perspective (for example, from glFrustum
or gluPerspective
), which can be solved by looking at the third column.
Now for an orthographic matrix, itβs pretty easy to move on to two equations:
right - left = 2 / m11 right + left = -2 * m14 / m11
Of these, you can easily calculate right = (1-m14) / m11
and left = right - 2/m11
(you can double-check any errors made during my mental arithmetic). And similarly for the other two pairs of parameters (note the sign m33
).
For perspective projection, you must first calculate near
and far
with m33
and m34
. Then you can calculate right/left
and bottom/top
same way as above, but using the calculated near
value.
So, in general, as soon as you know the formulas for the matrices based on the parameters, it really comes down to a simple set of simple 2x2 equations that are easy to solve. A more interesting question is why you really need to calculate these parameters from the projection matrix. If you really need them, you should just save them (since you are the one who constructs the matrix, one way or another). Otherwise, it sounds like another example of using OpenGL for more things (like scene control) than it actually intended, just a simple drawing API.
source share