(GLM) Decompose 4x4 matrix into rotation and translation?

Started by
1 comment, last by nonoptimalrobot 10 years, 8 months ago

I need to lerp between two 4x4 matrices, however matrix lerping can have some odd effects on the rotation, so I need to decompose them first.

I'm using the glm (OpenGL mathematics) library. Grabbing the rotation as quaternion is easy enough, but I'm stumped on how to get the translation. Any lead in the right direction would be appreciated.

Advertisement

I haven't used GLM before, but you can always transform the origin and see what you get back, as a first implementation.

glm::mat4 matrix;
float *f = glm::value_ptr(matrix);

Your translation is probably (f[3], f[7], f[11]). If that doesn't work, try (f[12], f[13], f[14]).

Transformation matrices are arranged like so


|ux vx nx tx|
|uy vy ny ty|
|uz vz nz tz|
| 0  0  0  1|

The rotation is stored in the upper 3x3 sub matrix and the translation is stored in the 4th column: (tx ty tz).

No need to translate the origin, just grab the 1st three elements in the 4th column of your matrix.

This topic is closed to new replies.

Advertisement