I’ve seen defferent implementations of inverse of a matrix and matrix-vector multiplications on the internet, and I’m not quite sure what is the correct one to use with opengl. I think
“the Matrix and Quaternion FAQ” had differently oriented matrices than what opengl uses.
So… I would be very grateful if someone could post a sample functions for the inverse of a 4x4 matrix and vector-matrix multiplication, that can be used with matrices retrieved from opengl and vice versa.
[This message has been edited by blender (edited 08-24-2003).]
Your function for inverting matrices looks like a special case function only. It will only work for orthonormalized matrices with a translation part. Any other matrix won’t be inverted properly. If that’s all you need then there’s no problem, but for general matrices it won’t work.
I need an invert function for arbitrary matrices. This is what I have at them moment (unfortunetly I can’t tell myself wether it’s ok or not, because I can’t inderstand it at all):
You can easily see for yourself if it’s OK or not. Create a random matrix, invert it, and multiply it by the original matrix. If you know your matrix math, you should know what the result is supposed to be if the matrix is correctly inevrted.
It looks like it works, but to be on the safe side you should fill it with random data to make sure it works with arbitrary matrices, not just a simple rotation and a translation.
Anyways, if I remember correct, a float (I assume that’s what you use) is only guaranteed to give you about 5-6 correct digits, so -0.000004 and 0.000006 could be within that limit and should therefore be treated as correct (equal to zero) as the datatype can’t provide more precision for “better” result.