DevMaster.net Forums
[[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]]

Go Back   DevMaster.net Forums > Site Discussions > Code & Snapshot Discussion
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
Old 09-08-2004, 11:05 AM   #1
anubis
DevMaster Staff
 
anubis's Avatar
 
Join Date: Apr 2003
Location: Germany
Posts: 2,328
Default

matrix inversion in general is a slow and tedious process. however in computer graphics we mostly deal with special kinds of matrices that allow for much faster inversion. one such type of matrix is the standard 4 by 4 transformation matrix that contains a rotation and a translation. conveniantly we can invert the rotation and the translation seperatly. the 3x3 rotation matrix is easily inverted by taking the dot product between each pair of row vectors, since it is orthogonal (the vector dot itself is 1 and and 0 for all the others). taking the dot product of the row vectors is equivalent to multiplying the matrix with it's transpose. so the inversion of the rotation part is simply it's transpose

Code:
void Matrix4x4::FastInvert() { swap(m[0][1], m[1][0]); swap(m[0][2], m[2][0]); swap(m[1][2], m[2][1]);

the translation part is then equally easy inverted (by taking the negative translation and multiplying it with the inverted rotation matrix, which is the transpose we just calculated).

Code:
float m30 = -(m[0][0] * m[3][0] + m[1][0] * m[3][1] + m[2][0] * m[3][2]); float m31 = -(m[0][1] * m[3][0] + m[1][1] * m[3][1] + m[2][1] * m[3][2]); m[3][2] = -(m[0][2] * m[3][0] + m[1][2] * m[3][1] + m[2][2] * m[3][2]); m[3][1] = m31; m[3][0] = m30; }

it should be noted that this only works if the matrix is unscaled because the row vectors of the rotation matrix are required to have unit length. the calculation should be extendable though if the matrix is scaled equally in all directions.
___________________________________________
If Prolog is the answer, what is the question ?
anubis is offline   Reply With Quote
Old 09-08-2004, 11:33 AM   #2
anubis
DevMaster Staff
 
anubis's Avatar
 
Join Date: Apr 2003
Location: Germany
Posts: 2,328
Default

i eddited the smileys out because they only showed up as "smiley.gif" when i accessed the code from the front page
___________________________________________
If Prolog is the answer, what is the question ?
anubis is offline   Reply With Quote
Old 09-08-2004, 11:44 AM   #3
z80
Member
 
Join Date: Sep 2004
Location: Copenhagen, Denmark
Posts: 99
Default

Quote:
Originally Posted by anubis
Code:
* m[3][0] = -(m[0][0] * m[3][0] + m[1][0] * m[3][1] + m[2][0] * m[3][2]); * m[3][1] = -(m[0][1] * m[3][0] + m[1][1] * m[3][1] + m[2][1] * m[3][2]); * m[3][2] = -(m[0][2] * m[3][0] + m[1][2] * m[3][1] + m[2][2] * m[3][2]); }
[snapback]10974[/snapback]

Hmm... dont you need some temp variables for m[3][0] and m[3][1] so you dont use their new updated values when m[3][1] and m[3][2] is computed?
z80 is offline   Reply With Quote
Old 09-08-2004, 12:06 PM   #4
anubis
DevMaster Staff
 
anubis's Avatar
 
Join Date: Apr 2003
Location: Germany
Posts: 2,328
Default

right...
i converted the code from my own, which just returns a new matrix so that's how the erorr sneaked in... i will edit it right away. thanks anyway
___________________________________________
If Prolog is the answer, what is the question ?
anubis is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump


All times are GMT -7. The time now is 04:38 AM.


Powered by vBulletin
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.