• 10
• 10
• 12
• 12
• 14

# Undo-Matrix Transform?

This topic is 4357 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Okay great, so you transform a vector by the matrix. I do it like this
/*For this one i copied source from my old code, not to sure if its correct*/
// Input,matrix & vector
__declspec(dllexport) void mTransform(float *m,float &x,float &y,float &z)
{
float tvx,tvy,tvz;
tvx = x*m[0]+y*m[4]+z*m[8]  + m[12];
tvy = x*m[1]+y*m[5]+z*m[9]  + m[13];
tvz = x*m[2]+y*m[6]+z*m[10] + m[14];
x = tvx;
y = tvy;
z = tvz;
}


Now I wrote this down on paper, tried some algebra and realised.. Hell no, it's not happening that way, atleast not on 2 a4 sides. So according to theory if i Invert the matrix M I can just apply the same transform (backwardly). Anyone has some source code on inversing a matrix 4x4?

##### Share on other sites
You can read about the properties of matrix inverses at Mathworld on "Matrix Inverse". It mentions (and links to) three ways to find the inverse a matrix near the bottom of the article.

##### Share on other sites
Which method would be best, something which doesn't take to long, is fairly accurate and consistant.

Linear time would be best...

##### Share on other sites
Search for something like 'inverse matrix' here on GDNet.

I found this.

Im not absolutely sure but from looking at your transform function there I think you might be able to optimise and get away with simply inverting the translation vector in the matrix then finding the inverse of the 3x3 rotation sub-matrix. Im sure somebody else here can confirm/deny that for you though.

##### Share on other sites
Well, there's a method to invert a matrix. Call A the matrix and B it's inverse.

If you do several operations over A's lines to get the indentity matrix, you can do those same operations on the identity to get to B. The problem is you shouldn't have floats and doubles in the matrix, this way, or you will lose precision. I once created an algorithm to echelon a matrix (or however you call it in english), but it was out of my mind, not using those more efficient stuff out there.

##### Share on other sites
For 4x4, using the adjoint matrix is the simplest, and the efficiency is not too bad.

I use it, and I've seen many professionals use it. Don't use it for larger matrices though, as it gets expensive.