Skip to main content
GameDev.net gamedev.net
🔒 Locked

decomposing a 4x4 transformation matrix

Started by Wilhelm van Huyssteen Mar 24, 2009 at 4:09 PM 6 replies 10.1k views
Original Post
Wilhelm van Huyssteen
Wilhelm van Huyssteen
hey. lets say i have a 4x4 transformation matrix which is the result of multiplying a translation matrix, rotation matrix and scale matrix together(in that order) how would i decompose this matrix back into the origanel 3 matrixes? Thnx in Advance!
Hello Kitty
Hello Kitty
I remember seeing this topic in one of the 5 graphics gems books.
-goodbye-
RobTheBloke
RobTheBloke
Quote:
Original post by EternityZA
how would i decompose this matrix back into the origanel 3 matrixes?


You can't get the original matrices back, but you can get equivalents. Given a matrix M:

a b c de f g hi j k lm n o pvec3 translate(m,n,o);float scaleX = length( vec3(a,b,c) )float scaleY = length( vec3(e,f,g) )float scaleZ = length( vec3(i,j,k) )vec3 tempZ = vec3(a,b,c).cross(vec3(e,f,g))if( tempZ.dot( vec3(i,j,k) ) < 0 ){  scaleX = -scaleX;  a = -a;   b = -b;   c = -c;}normalise(a,b,c);normalise(e,f,g);normalise(i,j,k);quat rotation;rotation.fromMatrix( M );


\edit fixed obvious flaw in the code....

[Edited by - RobTheBloke on March 27, 2009 5:45:35 AM]
RobTheBloke
RobTheBloke
Quote:
Original post by EternityZA
EDIT: what does your length() function do?


calculates the length of a vector. The X,Y and Z axes of the matrix (i.e. [a,b,c], [e,f,g] and [i,j,k]) store the rotation and scale components of the matrix. The length of those axes give the scale, but you need to know if it's got a negative scale in an axis or not. That's what the tempZ and dot/cross product are for.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.