Problem with gfm.math.matrix (some gamedevs out there ?)
earthwormjimmy at gmx.at
Thu Sep 3 12:36:35 UTC 2020
I am following some examples in C++ about how OpenGL is working.
There are great tutorials out there and most of it works also
For my code I am using gfm.math.matrix (Version 8.0.3) to be able
to calculate the mouse position in a 3d world.
Now I have some problems with the projection matrix by inverting
My example code:
const int width = 800;
const int height = 600;
auto projectionMatrix = mat4!(float).identity();
auto ratio = cast(float)width / cast(float)height;
projectionMatrix = mat4!(float).perspective( 45.0f, ratio,
0.0f, 100.0f );
writeln("projectionMatrix: ", projectionMatrix );
auto inversedMatrix = mat4!(float).identity();
inversedMatrix = projectionMatrix.inverse(); // <-- why this
does not work ?
writeln("inversedMatrix: ", inversedMatrix );
The projection matrix will be calculated correctly with
[1.34444, 0, 0, 0, 0, 1.79259, 0, 0, 0, 0, -1, -0, 0, 0, -1, 0]
assuming that the screen size is 800x600.
But using the .inverse() function in gfm returns only a matrix
with following values:
[-nan, -nan, -nan, -nan, -nan, -nan, -nan, -nan, -nan, -nan,
-nan, -nan, -nan, -nan, inf, -inf]
I don't know what I am doing wrong here:
- do I call the function wrong way ? (but there is no other way)
- is there a bug in the function ? (I do not believe that
because the library is battle proved)
So I looked a couple of hours for an answer, but did not find
Is somebody out there who could help me out ? Maybe one developer
of the d gfm library ?
Thank you for you time!
More information about the Digitalmars-d-learn