Skip to content
Snippets Groups Projects
Commit 9bfb1f78 authored by Anders Syvertsen's avatar Anders Syvertsen
Browse files

Added a matrix decomposition utility function

parent 289bc515
No related branches found
No related tags found
No related merge requests found
......@@ -452,3 +452,22 @@ void Viewer::mainMenu()
ImGui::EndMenu();
}
}
namespace minity
{
void matrixDecompose(const glm::mat4& matrix, glm::vec3& translation, glm::mat4& rotation, glm::vec3& scale)
{
translation = glm::vec3{matrix[3]};
glm::mat3 inner = glm::mat3{matrix};
scale.x = glm::length(inner[0]);
scale.y = glm::length(inner[1]);
scale.z = glm::length(inner[2]);
inner[0] /= scale.x;
inner[1] /= scale.y;
inner[2] /= scale.z;
rotation = glm::mat4{inner};
}
}
......@@ -14,7 +14,6 @@
namespace minity
{
class Viewer
{
public:
......@@ -78,5 +77,14 @@ namespace minity
bool m_saveScreenshot = false;
};
/**
* @brief Performs standard decomposition of a transformation matrix into translation, rotation and scale parts respectively.
* Note: The out rotation is an affine space rotation matrix, meaning only the inner 3x3 part affects rotation and the rest is the identity matrix.
* @see https://math.stackexchange.com/questions/237369/given-this-transformation-matrix-how-do-i-decompose-it-into-translation-rotati
* @param matrix The matrix to decompose
* @param translation Out parameter for translation
* @param rotation Out parameter for rotation
* @param scale Out parameter for scale
*/
void matrixDecompose(const glm::mat4& matrix, glm::vec3& translation, glm::mat4& rotation, glm::vec3& scale);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment