Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix4x4f with very large/small scaling is "not invertible" #138

Open
SuuperW opened this issue Jul 7, 2019 · 1 comment
Open

Matrix4x4f with very large/small scaling is "not invertible" #138

SuuperW opened this issue Jul 7, 2019 · 1 comment

Comments

@SuuperW
Copy link

SuuperW commented Jul 7, 2019

When I attempted to get the inverse of a Matrix4x4f I got an exception saying "not invertible", when I know this matrix can be inverted.

The problem is here: https://github.com/luca-piccioni/OpenGL.Net/blob/master/OpenGL.Net/Matrix.cs#L6133
A matrix is considered "not invertible" if it's determinant is between +/- 1e-6. There are no comments in the code or the commit (cc1a535) explaining why this is the case.

System.Numerics can properly compute the inverse of such a matrix.

I see in Matrix.cs that in some situations (which I don't understand) it will actually use System.Numerics' implementation of inverting a matrix. Is there any way I can cause it to do this in my project, in order to solve this problem in my application? (My app is a Windows Forms App, using the .NET Framework, and I do have System.Numerics in my project; the NuGet package manager installed it along with OpenGL.Net.Math.)

@luca-piccioni
Copy link
Owner

The 1e-6f constant magic number is a "somewhat little number" under which the inverse computation becomes unstable. It is a very small number, near to the float.Epsilon value.

If you are able to determine a smaller number that make this unit test pass, you can suggest it here or in a pull request.

System.Numerics are supported only if building with a .NET Framework greater or equal to 4.6. The vector is actually accelerated only in Release/x64 configurations (on Intel). Debug configurations (no accelerated), are much slower than the other code (indeed the Vector.IsHardwareAccelerated test).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants