Expand the 44 projection matrix to the left, right, lower, upper, near and far boundary values

Can someone help me get the left, right, lower, upper, near and far boundary values ​​from the forecast matrix44?

+4
source share
2 answers

Here are the solutions to Christian Rau's systems of equations:

For spelling matrix:

near = (1+m34)/m33; far = -(1-m34)/m33; bottom = (1-m24)/m22; top = -(1+m24)/m22; left = -(1+m14)/m11; right = (1-m14)/m11; 

For a perspective matrix:

 near = m34/(m33-1); far = m34/(m33+1); bottom = near * (m23-1)/m22; top = near * (m23+1)/m22; left = near * (m13-1)/m11; right = near * (m13+1)/m11; 

You can replace the values ​​of m11, m12, etc. formulas defined in the documentation for glOrtho and glFrustum to verify that it is correct.

+7
source

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.

+1
source

Source: https://habr.com/ru/post/1415315/


All Articles