diff --git a/glm/glm.hpp b/glm/glm.hpp index 9efabe20..abef269b 100644 --- a/glm/glm.hpp +++ b/glm/glm.hpp @@ -92,14 +92,26 @@ # pragma message("GLM: Core library included") #endif//GLM_MESSAGE -#include "./detail/func_trigonometric.hpp" -#include "./detail/func_exponential.hpp" -#include "./detail/func_common.hpp" -#include "./detail/func_packing.hpp" -#include "./detail/func_geometric.hpp" -#include "./detail/func_matrix.hpp" -#include "./detail/func_vector_relational.hpp" -#include "./detail/func_integer.hpp" -#include "./detail/func_noise.hpp" +#include "vec2.hpp" +#include "vec3.hpp" +#include "vec4.hpp" +#include "mat2x2.hpp" +#include "mat2x3.hpp" +#include "mat2x4.hpp" +#include "mat3x2.hpp" +#include "mat3x3.hpp" +#include "mat3x4.hpp" +#include "mat4x2.hpp" +#include "mat4x3.hpp" +#include "mat4x4.hpp" + +#include "trigonometric.hpp" +#include "exponential.hpp" +#include "common.hpp" +#include "packing.hpp" +#include "geometric.hpp" +#include "matrix.hpp" +#include "vector_relational.hpp" +#include "integer.hpp" #endif//GLM_INCLUDED diff --git a/glm/gtc/matrix_transform.inl b/glm/gtc/matrix_transform.inl index 38745e44..2035e674 100644 --- a/glm/gtc/matrix_transform.inl +++ b/glm/gtc/matrix_transform.inl @@ -384,14 +384,14 @@ namespace glm detail::tvec4 const & viewport ) { - detail::tmat4x4 inverse = glm::inverse(proj * model); + detail::tmat4x4 Inverse = inverse(proj * model); detail::tvec4 tmp = detail::tvec4(win, T(1)); tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]); tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]); tmp = tmp * T(2) - T(1); - detail::tvec4 obj = inverse * tmp; + detail::tvec4 obj = Inverse * tmp; obj /= obj.w; return detail::tvec3(obj); diff --git a/glm/gtx/matrix_query.hpp b/glm/gtx/matrix_query.hpp index f2ddee74..be994381 100644 --- a/glm/gtx/matrix_query.hpp +++ b/glm/gtx/matrix_query.hpp @@ -56,58 +56,42 @@ namespace glm /// Return whether a matrix a null matrix. /// From GLM_GTX_matrix_query extension. template - bool isNull( - detail::tmat2x2 const & m, - T const & epsilon/* = std::numeric_limits::epsilon()*/); + bool isNull(detail::tmat2x2 const & m, T const & epsilon); /// Return whether a matrix a null matrix. /// From GLM_GTX_matrix_query extension. template - bool isNull( - detail::tmat3x3 const & m, - T const & epsilon/* = std::numeric_limits::epsilon()*/); + bool isNull(detail::tmat3x3 const & m, T const & epsilon); /// Return whether a matrix is a null matrix. /// From GLM_GTX_matrix_query extension. template - bool isNull( - detail::tmat4x4 const & m, - T const & epsilon/* = std::numeric_limits::epsilon()*/); + bool isNull(detail::tmat4x4 const & m, T const & epsilon); /// Return whether a matrix is an identity matrix. /// From GLM_GTX_matrix_query extension. - template - bool isIdentity( - genType const & m, - typename genType::value_type const & epsilon/* = std::numeric_limits::epsilon()*/); + template class matType> + bool isIdentity(matType const & m, T const & epsilon); /// Return whether a matrix is a normalized matrix. /// From GLM_GTX_matrix_query extension. template - bool isNormalized( - detail::tmat2x2 const & m, - T const & epsilon/* = std::numeric_limits::epsilon()*/); + bool isNormalized(detail::tmat2x2 const & m, T const & epsilon); /// Return whether a matrix is a normalized matrix. /// From GLM_GTX_matrix_query extension. template - bool isNormalized( - detail::tmat3x3 const & m, - T const & epsilon/* = std::numeric_limits::epsilon()*/); + bool isNormalized(detail::tmat3x3 const & m, T const & epsilon); /// Return whether a matrix is a normalized matrix. /// From GLM_GTX_matrix_query extension. template - bool isNormalized( - detail::tmat4x4 const & m, - T const & epsilon/* = std::numeric_limits::epsilon()*/); + bool isNormalized(detail::tmat4x4 const & m, T const & epsilon); /// Return whether a matrix is an orthonormalized matrix. /// From GLM_GTX_matrix_query extension. template class matType> - bool isOrthogonal( - matType const & m, - T const & epsilon/* = std::numeric_limits::epsilon()*/); + bool isOrthogonal(matType const & m, T const & epsilon); /// @} }//namespace glm diff --git a/glm/gtx/vector_query.hpp b/glm/gtx/vector_query.hpp index b87cf8ef..b4000b5a 100644 --- a/glm/gtx/vector_query.hpp +++ b/glm/gtx/vector_query.hpp @@ -54,55 +54,33 @@ namespace glm //! Check whether two vectors are collinears. /// @see gtx_vector_query extensions. - template - bool areCollinear( - genType const & v0, - genType const & v1, - typename genType::value_type const & epsilon); + template class vecType> + bool areCollinear(vecType const & v0, vecType const & v1, T const & epsilon); //! Check whether two vectors are orthogonals. /// @see gtx_vector_query extensions. - template - bool areOrthogonal( - genType const & v0, - genType const & v1, - typename genType::value_type const & epsilon); + template class vecType> + bool areOrthogonal(vecType const & v0, vecType const & v1, T const & epsilon); //! Check whether a vector is normalized. /// @see gtx_vector_query extensions. - template class vecType> - bool isNormalized( - vecType const & v, - genType const & epsilon); + template class vecType> + bool isNormalized(vecType const & v, T const & epsilon); //! Check whether a vector is null. /// @see gtx_vector_query extensions. - template - bool isNull( - detail::tvec2 const & v, - T const & epsilon); + template class vecType> + bool isNull(vecType const & v, T const & epsilon); - //! Check whether a vector is null. + //! Check whether a each component of a vector is null. /// @see gtx_vector_query extensions. - template - bool isNull( - detail::tvec3 const & v, - T const & epsilon); - - //! Check whether a vector is null. - /// @see gtx_vector_query extensions. - template - bool isNull( - detail::tvec4 const & v, - T const & epsilon); + template class vecType> + vecType isCompNull(vecType const & v, T const & epsilon); //! Check whether two vectors are orthonormal. /// @see gtx_vector_query extensions. - template - bool areOrthonormal( - genType const & v0, - genType const & v1, - typename genType::value_type const & epsilon); + template class vecType> + bool areOrthonormal(vecType const & v0, vecType const & v1, T const & epsilon); /// @} }// namespace glm diff --git a/glm/gtx/vector_query.inl b/glm/gtx/vector_query.inl index 52962afd..db000f6b 100644 --- a/glm/gtx/vector_query.inl +++ b/glm/gtx/vector_query.inl @@ -12,39 +12,91 @@ #include -namespace glm +namespace glm{ +namespace detail { - template - GLM_FUNC_QUALIFIER bool areCollinear - ( - detail::tvec2 const & v0, - detail::tvec2 const & v1, - T const & epsilon - ) - { - return length(cross(detail::tvec3(v0, T(0)), detail::tvec3(v1, T(0)))) < epsilon; - } + template class vecType> + struct compute_areCollinear{}; template - GLM_FUNC_QUALIFIER bool areCollinear - ( - detail::tvec3 const & v0, - detail::tvec3 const & v1, - T const & epsilon - ) + struct compute_areCollinear { - return length(cross(v0, v1)) < epsilon; - } + static bool call(detail::tvec2 const & v0, detail::tvec2 const & v1, T const & epsilon) + { + return length(cross(detail::tvec3(v0, static_cast(0)), detail::tvec3(v1, static_cast(0)))) < epsilon; + } + }; template + struct compute_areCollinear + { + static bool call(detail::tvec3 const & v0, detail::tvec3 const & v1, T const & epsilon) + { + return length(cross(v0, v1)) < epsilon; + } + }; + + template + struct compute_areCollinear + { + static bool call(detail::tvec4 const & v0, detail::tvec4 const & v1, T const & epsilon) + { + return length(cross(detail::tvec3(v0), detail::tvec3(v1))) < epsilon; + } + }; + + template class vecType> + struct compute_isCompNull{}; + + template + struct compute_isCompNull + { + static detail::tvec2 call(detail::tvec2 const & v, T const & epsilon) + { + return detail::tvec2( + (abs(v.x) < epsilon), + (abs(v.y) < epsilon)); + } + }; + + template + struct compute_isCompNull + { + static detail::tvec3 call(detail::tvec3 const & v, T const & epsilon) + { + return detail::tvec3( + (abs(v.x) < epsilon), + (abs(v.y) < epsilon), + (abs(v.z) < epsilon)); + } + }; + + template + struct compute_isCompNull + { + static detail::tvec4 call(detail::tvec4 const & v, T const & epsilon) + { + return detail::tvec4( + (abs(v.x) < epsilon), + (abs(v.y) < epsilon), + (abs(v.z) < epsilon), + (abs(v.w) < epsilon)); + } + }; + +}//namespace detail + + template class vecType> GLM_FUNC_QUALIFIER bool areCollinear ( - detail::tvec4 const & v0, - detail::tvec4 const & v1, + vecType const & v0, + vecType const & v1, T const & epsilon ) { - return length(cross(detail::tvec3(v0), detail::tvec3(v1))) < epsilon; + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'areCollinear' only accept floating-point inputs"); + + return detail::compute_areCollinear::call(v0, v1, epsilon); } template class vecType> @@ -55,11 +107,11 @@ namespace glm T const & epsilon ) { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'areOrthogonal' only accept floating-point inputs"); + return abs(dot(v0, v1)) <= max( - T(1), - length(v0)) * max( - T(1), - length(v1)) * epsilon; + static_cast(1), + length(v0)) * max(static_cast(1), length(v1)) * epsilon; } template class vecType> @@ -69,47 +121,33 @@ namespace glm T const & epsilon ) { - return abs(length(v) - T(1)) <= T(2) * epsilon; + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'isNormalized' only accept floating-point inputs"); + + return abs(length(v) - static_cast(1)) <= static_cast(2) * epsilon; } - template + template class vecType> GLM_FUNC_QUALIFIER bool isNull ( - detail::tvec2 const & v, + vecType const & v, T const & epsilon ) { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'isNull' only accept floating-point inputs"); + return length(v) <= epsilon; } - template - GLM_FUNC_QUALIFIER bool isNull + template class vecType> + GLM_FUNC_QUALIFIER vecType isCompNull ( - detail::tvec3 const & v, + vecType const & v, T const & epsilon ) { - return length(v) <= epsilon; - } + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'isCompNull' only accept floating-point inputs"); - template - GLM_FUNC_QUALIFIER bool isNull - ( - detail::tvec4 const & v, - T const & epsilon - ) - { - return length(v) <= epsilon; - } - - template - GLM_FUNC_QUALIFIER bool isCompNull - ( - T const & s, - T const & epsilon - ) - { - return abs(s) < epsilon; + return detail::compute_isCompNull::call(v, epsilon); } template @@ -118,9 +156,7 @@ namespace glm detail::tvec2 const & v, T const & epsilon) { - return detail::tvec2( - (abs(v.x) < epsilon), - (abs(v.y) < epsilon)); + } template diff --git a/test/core/core_func_matrix.cpp b/test/core/core_func_matrix.cpp index 0b092444..09b18df7 100644 --- a/test/core/core_func_matrix.cpp +++ b/test/core/core_func_matrix.cpp @@ -9,62 +9,64 @@ #include +using namespace glm; + int test_matrixCompMult() { int Error(0); { - glm::mat2 m(0, 1, 2, 3); - glm::mat2 n = glm::matrixCompMult(m, m); - Error += n == glm::mat2(0, 1, 4, 9) ? 0 : 1; + mat2 m(0, 1, 2, 3); + mat2 n = matrixCompMult(m, m); + Error += n == mat2(0, 1, 4, 9) ? 0 : 1; } { - glm::mat2x3 m(0, 1, 2, 3, 4, 5); - glm::mat2x3 n = glm::matrixCompMult(m, m); - Error += n == glm::mat2x3(0, 1, 4, 9, 16, 25) ? 0 : 1; + mat2x3 m(0, 1, 2, 3, 4, 5); + mat2x3 n = matrixCompMult(m, m); + Error += n == mat2x3(0, 1, 4, 9, 16, 25) ? 0 : 1; } { - glm::mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7); - glm::mat2x4 n = glm::matrixCompMult(m, m); - Error += n == glm::mat2x4(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1; + mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7); + mat2x4 n = matrixCompMult(m, m); + Error += n == mat2x4(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1; } { - glm::mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8); - glm::mat3 n = glm::matrixCompMult(m, m); - Error += n == glm::mat3(0, 1, 4, 9, 16, 25, 36, 49, 64) ? 0 : 1; + mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8); + mat3 n = matrixCompMult(m, m); + Error += n == mat3(0, 1, 4, 9, 16, 25, 36, 49, 64) ? 0 : 1; } { - glm::mat3x2 m(0, 1, 2, 3, 4, 5); - glm::mat3x2 n = glm::matrixCompMult(m, m); - Error += n == glm::mat3x2(0, 1, 4, 9, 16, 25) ? 0 : 1; + mat3x2 m(0, 1, 2, 3, 4, 5); + mat3x2 n = matrixCompMult(m, m); + Error += n == mat3x2(0, 1, 4, 9, 16, 25) ? 0 : 1; } { - glm::mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); - glm::mat3x4 n = glm::matrixCompMult(m, m); - Error += n == glm::mat3x4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1; + mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); + mat3x4 n = matrixCompMult(m, m); + Error += n == mat3x4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1; } { - glm::mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); - glm::mat4 n = glm::matrixCompMult(m, m); - Error += n == glm::mat4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225) ? 0 : 1; + mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + mat4 n = matrixCompMult(m, m); + Error += n == mat4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225) ? 0 : 1; } { - glm::mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7); - glm::mat4x2 n = glm::matrixCompMult(m, m); - Error += n == glm::mat4x2(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1; + mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7); + mat4x2 n = matrixCompMult(m, m); + Error += n == mat4x2(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1; } { - glm::mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); - glm::mat4x3 n = glm::matrixCompMult(m, m); - Error += n == glm::mat4x3(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1; + mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); + mat4x3 n = matrixCompMult(m, m); + Error += n == mat4x3(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1; } return Error; @@ -79,62 +81,62 @@ int test_outerProduct() int test_transpose() { - int Error(0); - - { - glm::mat2 m(0, 1, 2, 3); - glm::mat2 t = glm::transpose(m); - Error += t == glm::mat2(0, 2, 1, 3) ? 0 : 1; - } + int Error(0); - { - glm::mat2x3 m(0, 1, 2, 3, 4, 5); - glm::mat3x2 t = glm::transpose(m); - Error += t == glm::mat3x2(0, 3, 1, 4, 2, 5) ? 0 : 1; - } + { + mat2 m(0, 1, 2, 3); + mat2 t = transpose(m); + Error += t == mat2(0, 2, 1, 3) ? 0 : 1; + } + + { + mat2x3 m(0, 1, 2, 3, 4, 5); + mat3x2 t = transpose(m); + Error += t == mat3x2(0, 3, 1, 4, 2, 5) ? 0 : 1; + } + + { + mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7); + mat4x2 t = transpose(m); + Error += t == mat4x2(0, 4, 1, 5, 2, 6, 3, 7) ? 0 : 1; + } + + { + mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8); + mat3 t = transpose(m); + Error += t == mat3(0, 3, 6, 1, 4, 7, 2, 5, 8) ? 0 : 1; + } + + { + mat3x2 m(0, 1, 2, 3, 4, 5); + mat2x3 t = transpose(m); + Error += t == mat2x3(0, 2, 4, 1, 3, 5) ? 0 : 1; + } + + { + mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); + mat4x3 t = transpose(m); + Error += t == mat4x3(0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11) ? 0 : 1; + } + + { + mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); + mat4 t = transpose(m); + Error += t == mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15) ? 0 : 1; + } + + { + mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7); + mat2x4 t = transpose(m); + Error += t == mat2x4(0, 2, 4, 6, 1, 3, 5, 7) ? 0 : 1; + } + + { + mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); + mat3x4 t = transpose(m); + Error += t == mat3x4(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11) ? 0 : 1; + } - { - glm::mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7); - glm::mat4x2 t = glm::transpose(m); - Error += t == glm::mat4x2(0, 4, 1, 5, 2, 6, 3, 7) ? 0 : 1; - } - - { - glm::mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8); - glm::mat3 t = glm::transpose(m); - Error += t == glm::mat3(0, 3, 6, 1, 4, 7, 2, 5, 8) ? 0 : 1; - } - - { - glm::mat3x2 m(0, 1, 2, 3, 4, 5); - glm::mat2x3 t = glm::transpose(m); - Error += t == glm::mat2x3(0, 2, 4, 1, 3, 5) ? 0 : 1; - } - - { - glm::mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); - glm::mat4x3 t = glm::transpose(m); - Error += t == glm::mat4x3(0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11) ? 0 : 1; - } - - { - glm::mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); - glm::mat4 t = glm::transpose(m); - Error += t == glm::mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15) ? 0 : 1; - } - - { - glm::mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7); - glm::mat2x4 t = glm::transpose(m); - Error += t == glm::mat2x4(0, 2, 4, 6, 1, 3, 5, 7) ? 0 : 1; - } - - { - glm::mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); - glm::mat3x4 t = glm::transpose(m); - Error += t == glm::mat3x4(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11) ? 0 : 1; - } - return Error; } @@ -154,7 +156,7 @@ int test_inverse() glm::vec4(0, 1, 0, 0), glm::vec4(0, 0, 1, 0), glm::vec4(0, 0, 0, 1)); - glm::mat4x4 B4x4 = glm::inverse(A4x4); + glm::mat4x4 B4x4 = inverse(A4x4); glm::mat4x4 I4x4 = A4x4 * B4x4; Failed += I4x4 == glm::mat4x4(1) ? 0 : 1; diff --git a/test/gtc/gtc_packing.cpp b/test/gtc/gtc_packing.cpp index a57b887e..15f2562c 100644 --- a/test/gtc/gtc_packing.cpp +++ b/test/gtc/gtc_packing.cpp @@ -184,12 +184,12 @@ int test_Snorm3x10_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) {