glm - Decompose mat4 into translation and rotation?
At version glm-0.9.8.1 you have to include:
#include <glm/gtx/matrix_decompose.hpp>
To use it:
glm::mat4 transformation; // your transformation matrix.
glm::vec3 scale;
glm::quat rotation;
glm::vec3 translation;
glm::vec3 skew;
glm::vec4 perspective;
glm::decompose(transformation, scale, rotation, translation, skew,perspective);
Keep in mind that the resulting quaternion in not correct. It returns its conjugate!
To fix this add this to your code:
rotation=glm::conjugate(rotation);
It looks like glm 0.9.6 supports matrix decomposition http://glm.g-truc.net/0.9.6/api/a00204.html
#include <glm/gtx/matrix_decompose.hpp>
glm::mat4 transformation; // your transformation matrix.
glm::vec3 scale;
glm::quat rotation;
glm::vec3 translation;
glm::vec3 skew;
glm::vec4 perspective;
glm::decompose(transformation, scale, rotation, translation, skew, perspective);
glm::vec3(m[3])
is the position vector(assuming m
is glm::mat4
)