matrix inversion

Started by
4 comments, last by Toudinho 14 years, 10 months ago
Hi guys, im just getting starting in getting deep into this matrix stuff. So, i need the inverse of my objects transform matrix in order to get my lighting shader to work. Now I found an advice that i could inverse it, just by transposing the rotation 3x3 matrix and negating the 3 translation values. It was said that it only works when the matrix is orthogonal. 1st question: What does orthogonal mean? I tried to figure it out myself but had no success :( It was also said that it works when theres only rotation and translation in the matrix. (Does this mean orthogonal?) Well, but my testing resulted in that this method works fine if let my model unrotated, As rotation comes in, the transformation of the lights position gives wrong results (I need it to be transformed in object space, thats why i need the inverse). 2nd question: I found out that the rotation totally messed up the values of the scale components, why? after rotating the model about 180° around y-axis, i find even negativ values in there. This is too the reason, why my computation fails. The lightposition isnt transformed properly because of that. Is this method only working in a few special cases? And if yes, could you give me an advise on how to invert a matrix in a fast manner? Thanks in advance for your help. Greetz
Advertisement
The algorithm you hinted at only works if the upper-left 3x3 matrix gives you an isometric transformation - in other words, only when it's a combination of rotations and mirrors. Scaling and shearing will not work! Also, the components below that submatrix have to be 3, but you probably got that. You cannot just negate the translation part tho - you need to first multiply it with the transposed/inversed rotational part and then negate it!
Even if I'm risking that you stop reading right here:

float viewmatrix[16]={
mat[0], mat[4], mat[8], 0,
mat[1], mat[5], mat[9], 0,
mat[2], mat[6], mat[10], 0,
-(mat[0]*mat[12] + mat[1]*mat[13] + mat[2]*mat[14]),
-(mat[4]*mat[12] + mat[5]*mat[13] + mat[6]*mat[14]),
-(mat[8]*mat[12] + mat[9]*mat[13] + mat[10]*mat[14]), 1};

This assumes mat is the object transformation and it only contains rotation and translation (above it's building the viewmatrix from a cameras transformation). Using the OpenGL layout here, meaning 0-3 is "right", 4-7 is "up", 8-11 is "forward" and 12-15 is "position".

Orthonormal simply means all the vectors need to be at a right angle and unit length. This isn't the case if you have fancy transformations like the mentioned scaling or shearing.

Depending on the shading language you might already have the inverse. GLSL for example has gl_ModelViewMatrixInverse (probably removed like a ton of other things from 1.4).
f@dzhttp://festini.device-zero.de
Thanks for the help,

just as I thought it´s just a special case :(

Ok, next step would be inverting the matrix. Has anyone a suggestion which is the best method. I read a lot about Gaus and all the other methods.
Which one would you consider?
I really dont know where to start with this.

Thanks again.

Greetz
Google for Cramer's Rule. But you'll also find a lot of ready-made implementations if you look into open source projects.
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
Yes i found something.

So my next question would be what to do if the matrix is non invertible?
Is that another special case where i can just transpose the matrix?

This topic is closed to new replies.

Advertisement