Convert transformation matrix to position, size, and rotation?

Hey everyone.

I’m currently writing a collada parser of sorts, and I’m a bit lost at the moment. I have relatively little linear algebra experience so I don’t know exactly what the transformation matrix means in the file.

If I have a source in an animation that looks like this:


<float_array id="pelvis-Matrix-animation-output-transform-array" count="496">

1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 48.628288 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
0.999992 0.004042 0.000000 -0.000000 -0.004042 0.999992 -0.000000 47.746246 -0.000000 -0.000000 1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000
0.999889 0.014871 0.000000 -0.000000 -0.014871 0.999889 -0.000000 45.541759 -0.000000 -0.000000 1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000
0.999533 0.030542 0.000000 -0.000000 -0.030542 0.999533 -0.000000 42.676380 -0.000000 -0.000000 1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000
0.998793 0.049110 0.000000 -0.000000 -0.049110 0.998793 -0.000000 39.810997 -0.000000 -0.000000 1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000
0.997642 0.068628 0.000000 -0.000000 -0.068628 0.997642 -0.000000 37.606514 -0.000000 -0.000000 1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000
0.996195 0.087156 0.000000 -0.000000 -0.087156 0.996195 -0.000000 36.724472 -0.000000 -0.000000 1.000000 -0.000001 0.000000 0.000000 0.000000 1.000000
0.993877 0.110493 0.000000 -0.000000 -0.110493 0.993877 -0.000000 44.013634 -0.000000 -0.000000 1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000
0.990268 0.139171 0.000000 0.000000 -0.139171 0.990268 -0.000000 58.109203 -0.000000 -0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
0.986555 0.163430 0.000000 0.000000 -0.163430 0.986555 -0.000000 67.364952 -0.000000 -0.000000 1.000000 0.000001 0.000000 0.000000 0.000000 1.000000
0.984808 0.173648 0.000000 0.000000 -0.173648 0.984808 -0.000000 69.155594 -0.000000 -0.000000 1.000000 0.000001 0.000000 0.000000 0.000000 1.000000
0.991086 0.133221 0.000000 0.000000 -0.133221 0.991086 -0.000000 69.471336 -0.000000 -0.000000 1.000000 0.000001 0.000000 0.000000 0.000000 1.000000
0.999048 0.043619 0.000000 0.000000 -0.043619 0.999048 -0.000000 69.392975 -0.000000 -0.000000 1.000000 0.000001 0.000000 0.000000 0.000000 1.000000
0.998926 -0.046335 0.000000 0.000000 0.046335 0.998926 -0.000000 69.017708 -0.000000 0.000000 1.000000 0.000001 0.000000 0.000000 0.000000 1.000000
0.996195 -0.087156 0.000000 0.000000 0.087156 0.996195 -0.000000 68.134964 -0.000000 0.000000 1.000000 0.000001 0.000000 0.000000 0.000000 1.000000
0.997291 -0.073562 0.000000 0.000000 0.073562 0.997291 -0.000000 62.673626 -0.000000 0.000000 1.000000 0.000001 0.000000 0.000000 0.000000 1.000000
0.999048 -0.043619 0.000000 0.000000 0.043619 0.999048 -0.000000 53.797279 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
0.999907 -0.013638 0.000000 0.000000 0.013638 0.999907 -0.000000 49.140327 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 50.852619 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 54.031849 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 55.744141 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 55.003895 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 53.239212 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 51.133217 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 49.368534 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 48.628288 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 48.628288 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 48.628288 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 48.628288 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 48.628288 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000
1.000000 -0.000000 0.000000 0.000000 0.000000 1.000000 -0.000000 48.628288 -0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000</float_array>

I want to figure out how to pull position, size, and rotation out of that for each frame. As far as I understand, each line above is a separate transformation matrix. I have found some instructions on how to get that information out of a 2D (9 element) transformation array, but not a 3D one. The collada file is in fact 3D, but it has no changes on the Z dimension, and is a bunch of flat billboards. It looks like the 4th row elements above aren’t all 0, which I was hoping they would be.

Can anyone point me in the right direction, or even tell me what to do here? For convenience, the topmost matrix listed would be:


1 0 0 0
0 1 0 48
0 0 1 0
0 0 0 1

I found a thing, it says that:


a b c
d e f
g h i

converts to


a b 0 c
d e 0 f
0 0 1 0
g h 0 i

If this is correct, that means my values make sense, as the rows that are in 3D space remain the same across the entire animation. I found another thing, for affine transforms, which explains what each element is, although I’m unsure how to extrapolate rotation out of skews (there is no way for a skewed transformation to retain its shape).

It is a 4x4 transformation matrix. Given the matrix


abcd
efgh
ijkl
mnop

dhl is the position.
abc is the direction and scale of the x axis.
efg is the direction and scale of the y axis.
ijk is the direction and scale of the z axis.

If the length of the 3 axis is the same then the object is scaled uniformely, or not scaled if all their lengths are 1. Otherwise there is a skew.

mnop can be ignored. They are used later in the pipeline when transforming from “viewcone” coordinates into a unit cube, or something like that.

You could have a look at the vecmath api for code to extract this for you. It is part of the Java3D source code and is open source.

Generally, the upper 3x3 is the rotation matrix, although when you start mixing scales and other transform effects (such as shears), this no longer holds true. But that’s the exact same case for 2D with its 2x2 upper rotation matrix.

Also, usually mnop should be 0001 when dealing with affine transforms for world and camera transforms. When you do projection matrix building, then you’ll see different values for mnop.

Thanks for the responses, guys. That should get me in the right direction.

This also might help you: http://tog.acm.org/resources/GraphicsGems/gemsii/unmatrix.c