dawidjoubert 161 Report post Posted May 22, 2006 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? 0 Share this post Link to post Share on other sites
Extrarius 1412 Report post Posted May 22, 2006 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. 0 Share this post Link to post Share on other sites
dawidjoubert 161 Report post Posted May 22, 2006 Which method would be best, something which doesn't take to long, is fairly accurate and consistant.Linear time would be best... 0 Share this post Link to post Share on other sites
dmatter 4844 Report post Posted May 22, 2006 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. 0 Share this post Link to post Share on other sites
Kalazart 148 Report post Posted May 22, 2006 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. 0 Share this post Link to post Share on other sites
discman1028 212 Report post Posted May 22, 2006 For 4x4, using the adjoint matrix is the simplest, and the efficiency is not too bad.http://home.earthlink.net/~w6rmk/math/matinv.htmI use it, and I've seen many professionals use it. Don't use it for larger matrices though, as it gets expensive. 0 Share this post Link to post Share on other sites
CProgrammer 303 Report post Posted May 23, 2006 Assuming you are using those matrix transformations for graphics you could always undo transform based on how the matrix was created. For instance if its a rotation matrix by 45 degrees, just use a rotation matrix by -45 degrees ... 0 Share this post Link to post Share on other sites