Why is the matrix created by Android frustumM different from the Redbook matrix?

Something funny about how Android FrustumM works. If I check the OpenGL red book, the generated matrix will look like this:

(source: glprogramming.com )

Songho.ca seems to agree with this:

(source: songho.ca )

However, one component is multiplied by 2 with Android FrustumM, and not in other matrix examples. Here is what he does:

Everything seems to coincide functionally, with the exception of the first row, third column. Why is this multiplied by two? Here are the lines of code from the android.opengl.Matrix frustumM method that generate the first three elements of the third column:

final float A = 2.0f * ((right + left) * r_width); final float B = (top + bottom) * r_height; final float C = (far + near) * r_depth; 

With r_width, r_height, r_depth defined as:

 final float r_width = 1.0f / (right - left); final float r_height = 1.0f / (top - bottom); final float r_depth = 1.0f / (near - far); 

A line starting with "final float A" is mistakenly multiplied by 2.

Is this an error in the Android code, or am I missing something? I know that the term is canceled if truncated symmetrically. When executing code with asymmetric truncation, the generated matrices are actually different, as are the resulting vectors, when the same vector is multiplied by these different matrices.

+6
source share
3 answers
+3
source

((I would rather just comment, but I'm not allowed to.))

Thanks guys for your understanding. I just had to add

 mMyMatrix[8] /= 2f; 

after

Matrix.frustrumM(mMyMatrix, ...)

To solve the aspect ratio problems :)

+1
source

yes, if you call a function with parameters (-ratio, ratio, -1, 1, 1, 10), this does not cause a jam, but if you call (from the right! = -1 * to the left), this is the difference.

I find this problem when I check the source code. Sigh.

+1
source

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


All Articles