diff --git a/glm/gtx/matrix_decompose.hpp b/glm/gtx/matrix_decompose.hpp index e7fc83e2..e68ab498 100644 --- a/glm/gtx/matrix_decompose.hpp +++ b/glm/gtx/matrix_decompose.hpp @@ -45,6 +45,7 @@ #include "../mat4x4.hpp" #include "../vec3.hpp" #include "../vec4.hpp" +#include "../geometric.hpp" #include "../gtc/quaternion.hpp" #include "../gtc/matrix_transform.hpp" diff --git a/glm/gtx/matrix_decompose.inl b/glm/gtx/matrix_decompose.inl index dec79572..47986660 100644 --- a/glm/gtx/matrix_decompose.inl +++ b/glm/gtx/matrix_decompose.inl @@ -30,7 +30,8 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// -namespace glm +namespace glm{ +namespace detail { /// Make a linear combination of two vectors and return the result. // result = (a * ascl) + (b * bscl) @@ -44,24 +45,15 @@ namespace glm } template - GLM_FUNC_QUALIFIER void v3Scale(tvec3 & v, T desiredLength) + GLM_FUNC_QUALIFIER tvec3 scale(tvec3 const& v, T desiredLength) { - T len = glm::length(v); - if(len != 0) - { - T l = desiredLength / len; - v[0] *= l; - v[1] *= l; - v[2] *= l; - } + return v * desiredLength / length(v); } +}//namespace detail - /** - * Matrix decompose - * http://www.opensource.apple.com/source/WebCore/WebCore-514/platform/graphics/transforms/TransformationMatrix.cpp - * Decomposes the mode matrix to translations,rotation scale components - * - */ + // Matrix decompose + // http://www.opensource.apple.com/source/WebCore/WebCore-514/platform/graphics/transforms/TransformationMatrix.cpp + // Decomposes the mode matrix to translations,rotation scale components template GLM_FUNC_QUALIFIER bool decompose(tmat4x4 const & ModelMatrix, tvec3 & Scale, tquat & Orientation, tvec3 & Translation, tvec3 & Skew, tvec4 & Perspective) @@ -131,26 +123,26 @@ namespace glm // Compute X scale factor and normalize first row. Scale.x = length(Row[0]);// v3Length(Row[0]); - v3Scale(Row[0], static_cast(1)); + Row[0] = detail::scale(Row[0], static_cast(1)); // Compute XY shear factor and make 2nd row orthogonal to 1st. Skew.z = dot(Row[0], Row[1]); - Row[1] = combine(Row[1], Row[0], static_cast(1), -Skew.z); + Row[1] = detail::combine(Row[1], Row[0], static_cast(1), -Skew.z); // Now, compute Y scale and normalize 2nd row. Scale.y = length(Row[1]); - v3Scale(Row[1], static_cast(1)); + Row[1] = detail::scale(Row[1], static_cast(1)); Skew.z /= Scale.y; // Compute XZ and YZ shears, orthogonalize 3rd row. Skew.y = glm::dot(Row[0], Row[2]); - Row[2] = combine(Row[2], Row[0], static_cast(1), -Skew.y); + Row[2] = detail::combine(Row[2], Row[0], static_cast(1), -Skew.y); Skew.x = glm::dot(Row[1], Row[2]); - Row[2] = combine(Row[2], Row[1], static_cast(1), -Skew.x); + Row[2] = detail::combine(Row[2], Row[1], static_cast(1), -Skew.x); // Next, get Z scale and normalize 3rd row. Scale.z = length(Row[2]); - v3Scale(Row[2], static_cast(1)); + Row[2] = detail::scale(Row[2], static_cast(1)); Skew.y /= Scale.z; Skew.x /= Scale.z;