how do I extract the rotation out of a 4x4 matrix?

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 103 Jun 13, 2013 at 14:21

matrix normat=i.mTransform;
normat._14=0;
normat._24=0;
normat._34=0;
normat._41=0;
normat._42=0;
normat._43=0;
normat._44=1;

Out.nor=mul(i.nor,normat);

this doesnt seem to be working, its just nulling off the normal… whats wrong with it?

2 Replies

Please log in or register to post a reply.

B20d81438814b6ba7da7ff8eb502d039
0
Vilem_Otte 117 Jun 13, 2013 at 14:56

4x4 matrix is as following:

m00 m01 m02 m03
m10 m11 m12 m13
m20 m21 m22 m23
m30 m31 m32 m33

Where m03, m13 and m23 are translation part of the matrix in case you’re using column-major order. Respectively m30 m31 and m32 in case you’re using row-major order. The rest (except of m33), e.g. the upper-left 3x3 sub-matrix is rotational part of the matrix.

So first of all, check whether your matrix is okay (and actually has valid numbers in rotational part of matrix - try it with identity, that is valid all day long). Also check that normal is valid before the transformation (it must have length equal to 1).

Also check that your multiplication function is alright, e.g. that it multiplies matrix-column vector in case of column-major order, or row vector-matrix in case of row-major order. Try to multiply some common vertex with common matrix, that should result in known result (F.e. x axis with 90 degree rotation around Z), to confirm the function is okay.

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 103 Jun 14, 2013 at 04:19

Ok cool, my problem was I was scaling my z vector by 0 nulling off my vector. It wasnt getting rid of scale for some reason.

Thanks Vilem!