Sign in to follow this  

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

This topic is 1582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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]).

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

This topic is 1582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this