Jump to content
  • Advertisement
Sign in to follow this  
Silverlan

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

This topic is 1802 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
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]).

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!