Sign in to follow this  
Silverlan

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

Recommended Posts

Silverlan    662

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
alvaro    21246

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

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