neurolabusc / OpenGLCoreTutorials

Cross-platform (Linux, Mac and Windows) OpenGL projects using Core specification
BSD 2-Clause "Simplified" License
19 stars 1 forks source link

gl_core_matrix.pas.InverseMat return erroneous value #4

Closed Lulu04 closed 2 months ago

Lulu04 commented 2 months ago

Hi neurolabusc, Thank you very much to share your work. It help me a lot to write my open source opengl projects and in my understanding of matrix usage in modern GL.

Testing with matrices, I found InverseMat in unit gl_core_matrix.pas return wrong value. My test was

Using the code from your repository Metal-Demos/common/VectorMath.pas/function Inverse:TMat4 the function return the right value. My knowledge in matrices are not enough to explain more than that, sorry.

neurolabusc commented 2 months ago

@Lulu04 the equation in this repository is optimized for 3D spatial transformations porting this code. As noted, this assumes a bordered 4x4 matrix such that the final row must be 0 0 0 1. It will not work if this is not the case. Note that this form of matrix encodes 12 degrees of freedom: with the first 3 values of the final column encoding translations, while the 3x3 matrix encodes zooms, rotations, shears. This explains why formats like the NIfTI only store 12 values, not 16 (as the final row is known).

The VectorMath library includes a more generalized but slower solution.

Lulu04 commented 2 months ago

Thank you for your explanation. I didn't notice that the final row must be 0 0 0 1.

I'm on the other side, a patient, not with neural lesions but viceral. I thank you for the work you do and I admire people like you who study to move things forward. Good luck in your work!

Regard