From aa26672da1c6272ba71ff6e9b90434113a1edbb1 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 4 Jan 2014 16:34:11 +0100 Subject: [PATCH] Fixed inverse link error when using namespace glm; (#147) --- glm/detail/_noise.hpp | 10 ++-- glm/detail/type_mat2x2.hpp | 8 +-- glm/detail/type_mat2x2.inl | 31 +++++----- glm/detail/type_mat3x3.hpp | 7 +-- glm/detail/type_mat3x3.inl | 33 ++++++----- glm/detail/type_mat4x4.hpp | 8 +-- glm/detail/type_mat4x4.inl | 116 ++++++++++++++----------------------- readme.txt | 1 + test/gtc/gtc_packing.cpp | 12 ++-- 9 files changed, 97 insertions(+), 129 deletions(-) diff --git a/glm/detail/_noise.hpp b/glm/detail/_noise.hpp index f678a3db..313530e8 100644 --- a/glm/detail/_noise.hpp +++ b/glm/detail/_noise.hpp @@ -35,31 +35,31 @@ namespace detail template GLM_FUNC_QUALIFIER T mod289(T const & x) { - return x - floor(x * T(1.0 / 289.0)) * T(289.0); + return x - floor(x * static_cast(1.0) / static_cast(289.0)) * static_cast(289.0); } template GLM_FUNC_QUALIFIER T permute(T const & x) { - return mod289(((x * T(34)) + T(1)) * x); + return mod289(((x * static_cast(34)) + static_cast(1)) * x); } template GLM_FUNC_QUALIFIER tvec2 permute(tvec2 const & x) { - return mod289(((x * T(34)) + T(1)) * x); + return mod289(((x * static_cast(34)) + static_cast(1)) * x); } template GLM_FUNC_QUALIFIER tvec3 permute(tvec3 const & x) { - return mod289(((x * T(34)) + T(1)) * x); + return mod289(((x * static_cast(34)) + static_cast(1)) * x); } template GLM_FUNC_QUALIFIER tvec4 permute(tvec4 const & x) { - return mod289(((x * T(34)) + T(1)) * x); + return mod289(((x * static_cast(34)) + static_cast(1)) * x); } /* template class vecType> diff --git a/glm/detail/type_mat2x2.hpp b/glm/detail/type_mat2x2.hpp index 91351880..dba18622 100644 --- a/glm/detail/type_mat2x2.hpp +++ b/glm/detail/type_mat2x2.hpp @@ -50,8 +50,6 @@ namespace detail GLM_FUNC_DECL GLM_CONSTEXPR length_t length() const; - template - friend tmat2x2 inverse(tmat2x2 const & m); template friend tvec2 operator/(tmat2x2 const & m, tvec2 const & v); template @@ -60,8 +58,6 @@ namespace detail private: /// @cond DETAIL col_type value[2]; - - GLM_FUNC_DECL tmat2x2 _inverse() const; /// @endcond public: @@ -152,8 +148,10 @@ namespace detail GLM_FUNC_DECL tmat2x2 operator--(int); }; - // Binary operators + template + GLM_FUNC_DECL tmat2x2 compute_inverse_mat2(tmat2x2 const & m); + // Binary operators template GLM_FUNC_DECL tmat2x2 operator+ ( tmat2x2 const & m, diff --git a/glm/detail/type_mat2x2.inl b/glm/detail/type_mat2x2.inl index f949ac92..93289596 100644 --- a/glm/detail/type_mat2x2.inl +++ b/glm/detail/type_mat2x2.inl @@ -272,19 +272,6 @@ namespace detail this->value[1] = col_type(m[1]); } - template - GLM_FUNC_QUALIFIER tmat2x2 tmat2x2::_inverse() const - { - T Determinant = this->value[0][0] * this->value[1][1] - this->value[1][0] * this->value[0][1]; - - tmat2x2 Inverse( - + this->value[1][1] / Determinant, - - this->value[0][1] / Determinant, - - this->value[1][0] / Determinant, - + this->value[0][0] / Determinant); - return Inverse; - } - ////////////////////////////////////////////////////////////// // mat2x2 operators @@ -371,7 +358,7 @@ namespace detail template GLM_FUNC_QUALIFIER tmat2x2& tmat2x2::operator/= (tmat2x2 const & m) { - return (*this = *this * m._inverse()); + return (*this = *this * compute_inverse_mat2(m)); } template @@ -406,6 +393,18 @@ namespace detail return Result; } + template + GLM_FUNC_QUALIFIER tmat2x2 compute_inverse_mat2(tmat2x2 const & m) + { + T Determinant = m[0][0] * m[1][1] - m[1][0] * m[0][1]; + + tmat2x2 Inverse( + + m[1][1] / Determinant, - m[0][1] / Determinant, + - m[1][0] / Determinant, + m[0][0] / Determinant); + + return Inverse; + } + ////////////////////////////////////////////////////////////// // Binary operators @@ -608,7 +607,7 @@ namespace detail typename tmat2x2::row_type & v ) { - return m._inverse() * v; + return detail::compute_inverse_mat2(m) * v; } template @@ -618,7 +617,7 @@ namespace detail tmat2x2 const & m ) { - return v * m._inverse(); + return v * detail::compute_inverse_mat2(m); } template diff --git a/glm/detail/type_mat3x3.hpp b/glm/detail/type_mat3x3.hpp index 07112d7c..a786ab33 100644 --- a/glm/detail/type_mat3x3.hpp +++ b/glm/detail/type_mat3x3.hpp @@ -50,8 +50,6 @@ namespace detail GLM_FUNC_DECL GLM_CONSTEXPR length_t length() const; - template - friend tmat3x3 inverse(tmat3x3 const & m); template friend tvec3 operator/(tmat3x3 const & m, tvec3 const & v); template @@ -60,8 +58,6 @@ namespace detail private: /// @cond DETAIL col_type value[3]; - - GLM_FUNC_DECL tmat3x3 _inverse() const; /// @endcond public: @@ -155,6 +151,9 @@ namespace detail GLM_FUNC_DECL tmat3x3 operator--(int); }; + template + GLM_FUNC_DECL tmat3x3 compute_inverse_mat3(tmat3x3 const & m); + // Binary operators template GLM_FUNC_DECL tmat3x3 operator+ ( diff --git a/glm/detail/type_mat3x3.inl b/glm/detail/type_mat3x3.inl index 16c3fba7..217ca793 100644 --- a/glm/detail/type_mat3x3.inl +++ b/glm/detail/type_mat3x3.inl @@ -393,7 +393,7 @@ namespace detail template GLM_FUNC_QUALIFIER tmat3x3 & tmat3x3::operator/= (tmat3x3 const & m) { - return (*this = *this * m._inverse()); + return (*this = *this * detail::compute_inverse_mat3(m)); } template @@ -431,19 +431,19 @@ namespace detail } template - GLM_FUNC_QUALIFIER tmat3x3 tmat3x3::_inverse() const + GLM_FUNC_QUALIFIER tmat3x3 compute_inverse_mat3(tmat3x3 const & m) { - T S00 = value[0][0]; - T S01 = value[0][1]; - T S02 = value[0][2]; + T S00 = m[0][0]; + T S01 = m[0][1]; + T S02 = m[0][2]; - T S10 = value[1][0]; - T S11 = value[1][1]; - T S12 = value[1][2]; + T S10 = m[1][0]; + T S11 = m[1][1]; + T S12 = m[1][2]; - T S20 = value[2][0]; - T S21 = value[2][1]; - T S22 = value[2][2]; + T S20 = m[2][0]; + T S21 = m[2][1]; + T S22 = m[2][2]; /* tmat3x3 Inverse( + (S11 * S22 - S21 * S12), @@ -467,9 +467,10 @@ namespace detail S10 * S02 - S12 * S00, S11 * S00 - S10 * S01); - T Determinant = S00 * (S11 * S22 - S21 * S12) - - S10 * (S01 * S22 - S21 * S02) - + S20 * (S01 * S12 - S11 * S02); + T Determinant = + + S00 * (S11 * S22 - S21 * S12) + - S10 * (S01 * S22 - S21 * S02) + + S20 * (S01 * S12 - S11 * S02); Inverse /= Determinant; return Inverse; @@ -719,7 +720,7 @@ namespace detail typename tmat3x3::row_type const & v ) { - return m._inverse() * v; + return detail::compute_inverse_mat3(m) * v; } template @@ -729,7 +730,7 @@ namespace detail tmat3x3 const & m ) { - return v * m._inverse(); + return v * detail::compute_inverse_mat3(m); } template diff --git a/glm/detail/type_mat4x4.hpp b/glm/detail/type_mat4x4.hpp index 9082f65c..764df400 100644 --- a/glm/detail/type_mat4x4.hpp +++ b/glm/detail/type_mat4x4.hpp @@ -54,8 +54,6 @@ namespace detail GLM_FUNC_DECL GLM_CONSTEXPR length_t length() const; - template - friend tmat4x4 inverse(tmat4x4 const & m); template friend tvec4 operator/(tmat4x4 const & m, tvec4 const & v); template @@ -64,9 +62,6 @@ namespace detail private: /// @cond DETAIL col_type value[4]; - - GLM_FUNC_DECL tmat4x4 _inverse() const; - /// @endcond public: // Constructors @@ -165,6 +160,9 @@ namespace detail GLM_FUNC_DECL tmat4x4 operator--(int); }; + template + GLM_FUNC_DECL tmat4x4 compute_inverse_mat4(tmat4x4 const & m); + // Binary operators template GLM_FUNC_DECL tmat4x4 operator+ ( diff --git a/glm/detail/type_mat4x4.inl b/glm/detail/type_mat4x4.inl index cde326cc..3d06bbcf 100644 --- a/glm/detail/type_mat4x4.inl +++ b/glm/detail/type_mat4x4.inl @@ -66,8 +66,8 @@ namespace detail template GLM_FUNC_QUALIFIER tmat4x4::tmat4x4() { - value_type Zero(0); - value_type One(1); + T Zero(0); + T One(1); this->value[0] = col_type(One, Zero, Zero, Zero); this->value[1] = col_type(Zero, One, Zero, Zero); this->value[2] = col_type(Zero, Zero, One, Zero); @@ -461,7 +461,7 @@ namespace detail template GLM_FUNC_QUALIFIER tmat4x4 & tmat4x4::operator/= (tmat4x4 const & m) { - return (*this = *this * m._inverse()); + return (*this = *this * detail::compute_inverse_mat4(m)); } template @@ -501,76 +501,48 @@ namespace detail } template - GLM_FUNC_QUALIFIER tmat4x4 tmat4x4::_inverse() const + GLM_FUNC_QUALIFIER tmat4x4 compute_inverse_mat4(tmat4x4 const & m) { // Calculate all mat2 determinants - value_type SubFactor00 = this->value[2][2] * this->value[3][3] - this->value[3][2] * this->value[2][3]; - value_type SubFactor01 = this->value[2][1] * this->value[3][3] - this->value[3][1] * this->value[2][3]; - value_type SubFactor02 = this->value[2][1] * this->value[3][2] - this->value[3][1] * this->value[2][2]; - value_type SubFactor03 = this->value[2][0] * this->value[3][3] - this->value[3][0] * this->value[2][3]; - value_type SubFactor04 = this->value[2][0] * this->value[3][2] - this->value[3][0] * this->value[2][2]; - value_type SubFactor05 = this->value[2][0] * this->value[3][1] - this->value[3][0] * this->value[2][1]; - value_type SubFactor06 = this->value[1][2] * this->value[3][3] - this->value[3][2] * this->value[1][3]; - value_type SubFactor07 = this->value[1][1] * this->value[3][3] - this->value[3][1] * this->value[1][3]; - value_type SubFactor08 = this->value[1][1] * this->value[3][2] - this->value[3][1] * this->value[1][2]; - value_type SubFactor09 = this->value[1][0] * this->value[3][3] - this->value[3][0] * this->value[1][3]; - value_type SubFactor10 = this->value[1][0] * this->value[3][2] - this->value[3][0] * this->value[1][2]; - value_type SubFactor11 = this->value[1][1] * this->value[3][3] - this->value[3][1] * this->value[1][3]; - value_type SubFactor12 = this->value[1][0] * this->value[3][1] - this->value[3][0] * this->value[1][1]; - value_type SubFactor13 = this->value[1][2] * this->value[2][3] - this->value[2][2] * this->value[1][3]; - value_type SubFactor14 = this->value[1][1] * this->value[2][3] - this->value[2][1] * this->value[1][3]; - value_type SubFactor15 = this->value[1][1] * this->value[2][2] - this->value[2][1] * this->value[1][2]; - value_type SubFactor16 = this->value[1][0] * this->value[2][3] - this->value[2][0] * this->value[1][3]; - value_type SubFactor17 = this->value[1][0] * this->value[2][2] - this->value[2][0] * this->value[1][2]; - value_type SubFactor18 = this->value[1][0] * this->value[2][1] - this->value[2][0] * this->value[1][1]; -/* - tmat4x4 Inverse( - + (this->value[1][1] * SubFactor00 - this->value[1][2] * SubFactor01 + this->value[1][3] * SubFactor02), - - (this->value[1][0] * SubFactor00 - this->value[1][2] * SubFactor03 + this->value[1][3] * SubFactor04), - + (this->value[1][0] * SubFactor01 - this->value[1][1] * SubFactor03 + this->value[1][3] * SubFactor05), - - (this->value[1][0] * SubFactor02 - this->value[1][1] * SubFactor04 + this->value[1][2] * SubFactor05), - - - (this->value[0][1] * SubFactor00 - this->value[0][2] * SubFactor01 + this->value[0][3] * SubFactor02), - + (this->value[0][0] * SubFactor00 - this->value[0][2] * SubFactor03 + this->value[0][3] * SubFactor04), - - (this->value[0][0] * SubFactor01 - this->value[0][1] * SubFactor03 + this->value[0][3] * SubFactor05), - + (this->value[0][0] * SubFactor02 - this->value[0][1] * SubFactor04 + this->value[0][2] * SubFactor05), - - + (this->value[0][1] * SubFactor06 - this->value[0][2] * SubFactor07 + this->value[0][3] * SubFactor08), - - (this->value[0][0] * SubFactor06 - this->value[0][2] * SubFactor09 + this->value[0][3] * SubFactor10), - + (this->value[0][0] * SubFactor11 - this->value[0][1] * SubFactor09 + this->value[0][3] * SubFactor12), - - (this->value[0][0] * SubFactor08 - this->value[0][1] * SubFactor10 + this->value[0][2] * SubFactor12), - - - (this->value[0][1] * SubFactor13 - this->value[0][2] * SubFactor14 + this->value[0][3] * SubFactor15), - + (this->value[0][0] * SubFactor13 - this->value[0][2] * SubFactor16 + this->value[0][3] * SubFactor17), - - (this->value[0][0] * SubFactor14 - this->value[0][1] * SubFactor16 + this->value[0][3] * SubFactor18), - + (this->value[0][0] * SubFactor15 - this->value[0][1] * SubFactor17 + this->value[0][2] * SubFactor18)); -*/ + T const SubFactor00 = m[2][2] * m[3][3] - m[3][2] * m[2][3]; + T const SubFactor01 = m[2][1] * m[3][3] - m[3][1] * m[2][3]; + T const SubFactor02 = m[2][1] * m[3][2] - m[3][1] * m[2][2]; + T const SubFactor03 = m[2][0] * m[3][3] - m[3][0] * m[2][3]; + T const SubFactor04 = m[2][0] * m[3][2] - m[3][0] * m[2][2]; + T const SubFactor05 = m[2][0] * m[3][1] - m[3][0] * m[2][1]; + T const SubFactor06 = m[1][2] * m[3][3] - m[3][2] * m[1][3]; + T const SubFactor07 = m[1][1] * m[3][3] - m[3][1] * m[1][3]; + T const SubFactor08 = m[1][1] * m[3][2] - m[3][1] * m[1][2]; + T const SubFactor09 = m[1][0] * m[3][3] - m[3][0] * m[1][3]; + T const SubFactor10 = m[1][0] * m[3][2] - m[3][0] * m[1][2]; + T const SubFactor11 = m[1][1] * m[3][3] - m[3][1] * m[1][3]; + T const SubFactor12 = m[1][0] * m[3][1] - m[3][0] * m[1][1]; + T const SubFactor13 = m[1][2] * m[2][3] - m[2][2] * m[1][3]; + T const SubFactor14 = m[1][1] * m[2][3] - m[2][1] * m[1][3]; + T const SubFactor15 = m[1][1] * m[2][2] - m[2][1] * m[1][2]; + T const SubFactor16 = m[1][0] * m[2][3] - m[2][0] * m[1][3]; + T const SubFactor17 = m[1][0] * m[2][2] - m[2][0] * m[1][2]; + T const SubFactor18 = m[1][0] * m[2][1] - m[2][0] * m[1][1]; + tmat4x4 Inverse( - + this->value[1][1] * SubFactor00 - this->value[1][2] * SubFactor01 + this->value[1][3] * SubFactor02, - - this->value[1][0] * SubFactor00 + this->value[1][2] * SubFactor03 - this->value[1][3] * SubFactor04, - + this->value[1][0] * SubFactor01 - this->value[1][1] * SubFactor03 + this->value[1][3] * SubFactor05, - - this->value[1][0] * SubFactor02 + this->value[1][1] * SubFactor04 - this->value[1][2] * SubFactor05, - - - this->value[0][1] * SubFactor00 + this->value[0][2] * SubFactor01 - this->value[0][3] * SubFactor02, - + this->value[0][0] * SubFactor00 - this->value[0][2] * SubFactor03 + this->value[0][3] * SubFactor04, - - this->value[0][0] * SubFactor01 + this->value[0][1] * SubFactor03 - this->value[0][3] * SubFactor05, - + this->value[0][0] * SubFactor02 - this->value[0][1] * SubFactor04 + this->value[0][2] * SubFactor05, - - + this->value[0][1] * SubFactor06 - this->value[0][2] * SubFactor07 + this->value[0][3] * SubFactor08, - - this->value[0][0] * SubFactor06 + this->value[0][2] * SubFactor09 - this->value[0][3] * SubFactor10, - + this->value[0][0] * SubFactor11 - this->value[0][1] * SubFactor09 + this->value[0][3] * SubFactor12, - - this->value[0][0] * SubFactor08 + this->value[0][1] * SubFactor10 - this->value[0][2] * SubFactor12, - - - this->value[0][1] * SubFactor13 + this->value[0][2] * SubFactor14 - this->value[0][3] * SubFactor15, - + this->value[0][0] * SubFactor13 - this->value[0][2] * SubFactor16 + this->value[0][3] * SubFactor17, - - this->value[0][0] * SubFactor14 + this->value[0][1] * SubFactor16 - this->value[0][3] * SubFactor18, - + this->value[0][0] * SubFactor15 - this->value[0][1] * SubFactor17 + this->value[0][2] * SubFactor18); - - T Determinant = static_cast( - + this->value[0][0] * Inverse[0][0] - + this->value[0][1] * Inverse[1][0] - + this->value[0][2] * Inverse[2][0] - + this->value[0][3] * Inverse[3][0]); + + m[1][1] * SubFactor00 - m[1][2] * SubFactor01 + m[1][3] * SubFactor02, + - m[1][0] * SubFactor00 + m[1][2] * SubFactor03 - m[1][3] * SubFactor04, + + m[1][0] * SubFactor01 - m[1][1] * SubFactor03 + m[1][3] * SubFactor05, + - m[1][0] * SubFactor02 + m[1][1] * SubFactor04 - m[1][2] * SubFactor05, + - m[0][1] * SubFactor00 + m[0][2] * SubFactor01 - m[0][3] * SubFactor02, + + m[0][0] * SubFactor00 - m[0][2] * SubFactor03 + m[0][3] * SubFactor04, + - m[0][0] * SubFactor01 + m[0][1] * SubFactor03 - m[0][3] * SubFactor05, + + m[0][0] * SubFactor02 - m[0][1] * SubFactor04 + m[0][2] * SubFactor05, + + m[0][1] * SubFactor06 - m[0][2] * SubFactor07 + m[0][3] * SubFactor08, + - m[0][0] * SubFactor06 + m[0][2] * SubFactor09 - m[0][3] * SubFactor10, + + m[0][0] * SubFactor11 - m[0][1] * SubFactor09 + m[0][3] * SubFactor12, + - m[0][0] * SubFactor08 + m[0][1] * SubFactor10 - m[0][2] * SubFactor12, + - m[0][1] * SubFactor13 + m[0][2] * SubFactor14 - m[0][3] * SubFactor15, + + m[0][0] * SubFactor13 - m[0][2] * SubFactor16 + m[0][3] * SubFactor17, + - m[0][0] * SubFactor14 + m[0][1] * SubFactor16 - m[0][3] * SubFactor18, + + m[0][0] * SubFactor15 - m[0][1] * SubFactor17 + m[0][2] * SubFactor18); + + T Determinant = static_cast(+ m[0][0] * Inverse[0][0] + m[0][1] * Inverse[1][0] + m[0][2] * Inverse[2][0] + m[0][3] * Inverse[3][0]); Inverse /= Determinant; return Inverse; @@ -851,7 +823,7 @@ namespace detail typename tmat4x4::row_type const & v ) { - return m._inverse() * v; + return detail::compute_inverse_mat4(m) * v; } template @@ -861,7 +833,7 @@ namespace detail tmat4x4 const & m ) { - return v * m._inverse(); + return v * detail::compute_inverse_mat4(m); } template diff --git a/readme.txt b/readme.txt index db80575d..5fb9f79a 100644 --- a/readme.txt +++ b/readme.txt @@ -44,6 +44,7 @@ GLM 0.9.5.1: 2014-XX-XX - Added possible static_cast conversion of GLM types (#72) - Fixed error 'inverse' is not a member of 'glm' from glm::unProject (#146) - Fixed mismatch between some declarations and definitions +- Fixed inverse link error when using namespace glm; (#147) ================================================================================ GLM 0.9.5.0: 2013-12-25 diff --git a/test/gtc/gtc_packing.cpp b/test/gtc/gtc_packing.cpp index 15f2562c..0eb38d60 100644 --- a/test/gtc/gtc_packing.cpp +++ b/test/gtc/gtc_packing.cpp @@ -208,12 +208,12 @@ int test_Unorm3x10_1x2() int Error = 0; std::vector Tests; - Tests.push_back(glm::vec4(1.0)); - Tests.push_back(glm::vec4(0.0)); - Tests.push_back(glm::vec4(2.0)); - Tests.push_back(glm::vec4(0.1)); - Tests.push_back(glm::vec4(0.5)); - Tests.push_back(glm::vec4(0.9)); + Tests.push_back(glm::vec4(1.0f)); + Tests.push_back(glm::vec4(0.0f)); + Tests.push_back(glm::vec4(2.0f)); + Tests.push_back(glm::vec4(0.1f)); + Tests.push_back(glm::vec4(0.5f)); + Tests.push_back(glm::vec4(0.9f)); for(std::size_t i = 0; i < Tests.size(); ++i) {