I have a 4x4 matrix that i would like to decompose in 5 matrices.
The four matrices that compose it are these:
Translation matrix:
tx, ty and tz represent our translation values.
Code:
[ 1, 0, 0, 0]
[ 0, 1, 0, 0]
[ 0, 0, 1, 0]
[tx, ty, tz, 1]
The Rotation Matrix:
Rotation on X Axis.
Code:
[ 1, 0, 0, 0]
[ 0, cos(xrot), -sin(xrot), 0]
[ 0, sin(xrot), cos(xrot), 0]
[ 0, 0, 0, 1]
Rotation on Y Axis.
Code:
[ cos(yrot), 0, sin(yrot), 0]
[ 0, 1, 0, 0]
[-sin(yrot), 0, cos(yrot), 0]
[ 0, 0, 0, 1]
Rotation on Z Axis.
Code:
[ cos(zrot), -sin(zrot), 0, 0]
[ sin(zrot), cos(zrot), 0, 0]
[ 0, 0, 1, 0]
[ 0, 0, 0, 1]
The Scale Matrix:
sx, sy and sz represent our scale values.
Code:
[ sx, 0, 0, 0]
[ 0, sy, 0, 0]
[ 0, 0, sz, 0]
[ 0, 0, 0, 1]
As some told me in this thread, there is no problem to get the Translation matrix, just multiplying the original matrix by
Code:
[0]
[0]
[0]
[1]
But how can i get the other 4 matrices??
etc...
The book Graphics Gems 2 has an algorithm to do this, in section VII.1
Decomposing a matrix into simple transformations. There is code here
that is supposed to implement it (I haven't checked it personally):
http://www.acm.org/pubs/tog/GraphicsGems/gemsii/
The files you'll need are unmatrix.c, unmatrix.h and GraphicsGems.h