From ffb940cbdf597bab1057b8fab9291f1f3314eca1 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 31 May 2011 16:15:21 +0100 Subject: [PATCH 01/19] Fixed missing precision matrix types --- glm/core/type_mat2x2.hpp | 30 +++++++++++++++++++++++++----- glm/core/type_mat3x3.hpp | 28 +++++++++++++++++++++++----- glm/core/type_mat4x4.hpp | 30 +++++++++++++++++++++++++----- 3 files changed, 73 insertions(+), 15 deletions(-) diff --git a/glm/core/type_mat2x2.hpp b/glm/core/type_mat2x2.hpp index aade1ef4..8d6a3918 100644 --- a/glm/core/type_mat2x2.hpp +++ b/glm/core/type_mat2x2.hpp @@ -224,17 +224,37 @@ namespace glm { //! 2 columns of 2 components matrix of low precision floating-point numbers. //! There is no guarantee on the actual precision. - //! (From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers) + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers //! \ingroup core_precision - typedef detail::tmat2x2 lowp_mat2x2; + typedef detail::tmat2x2 lowp_mat2; + //! 2 columns of 2 components matrix of medium precision floating-point numbers. //! There is no guarantee on the actual precision. - //! (From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers) + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers //! \ingroup core_precision - typedef detail::tmat2x2 mediump_mat2x2; + typedef detail::tmat2x2 mediump_mat2; + //! 2 columns of 2 components matrix of high precision floating-point numbers. //! There is no guarantee on the actual precision. - //! (From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers) + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers + //! \ingroup core_precision + typedef detail::tmat2x2 highp_mat2; + + //! 2 columns of 2 components matrix of low precision floating-point numbers. + //! There is no guarantee on the actual precision. + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers + //! \ingroup core_precision + typedef detail::tmat2x2 lowp_mat2x2; + + //! 2 columns of 2 components matrix of medium precision floating-point numbers. + //! There is no guarantee on the actual precision. + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers + //! \ingroup core_precision + typedef detail::tmat2x2 mediump_mat2x2; + + //! 2 columns of 2 components matrix of high precision floating-point numbers. + //! There is no guarantee on the actual precision. + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers //! \ingroup core_precision typedef detail::tmat2x2 highp_mat2x2; } diff --git a/glm/core/type_mat3x3.hpp b/glm/core/type_mat3x3.hpp index bf18c167..3f4725dc 100644 --- a/glm/core/type_mat3x3.hpp +++ b/glm/core/type_mat3x3.hpp @@ -223,17 +223,35 @@ namespace glm { //! 3 columns of 3 components matrix of low precision floating-point numbers. //! There is no guarantee on the actual precision. - //! (From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers) + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers //! \ingroup core_precision - typedef detail::tmat3x3 lowp_mat3x3; + typedef detail::tmat3x3 lowp_mat3; //! 3 columns of 3 components matrix of medium precision floating-point numbers. //! There is no guarantee on the actual precision. - //! (From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers) + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers //! \ingroup core_precision - typedef detail::tmat3x3 mediump_mat3x3; + typedef detail::tmat3x3 mediump_mat3; //! 3 columns of 3 components matrix of high precision floating-point numbers. //! There is no guarantee on the actual precision. - //! (From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers) + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers + //! \ingroup core_precision + typedef detail::tmat3x3 highp_mat3; + + //! 3 columns of 3 components matrix of low precision floating-point numbers. + //! There is no guarantee on the actual precision. + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers + //! \ingroup core_precision + typedef detail::tmat3x3 lowp_mat3x3; + + //! 3 columns of 3 components matrix of medium precision floating-point numbers. + //! There is no guarantee on the actual precision. + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers + //! \ingroup core_precision + typedef detail::tmat3x3 mediump_mat3x3; + + //! 3 columns of 3 components matrix of high precision floating-point numbers. + //! There is no guarantee on the actual precision. + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers //! \ingroup core_precision typedef detail::tmat3x3 highp_mat3x3; } diff --git a/glm/core/type_mat4x4.hpp b/glm/core/type_mat4x4.hpp index 6aa1f68a..e992ddaf 100644 --- a/glm/core/type_mat4x4.hpp +++ b/glm/core/type_mat4x4.hpp @@ -223,17 +223,37 @@ namespace glm { //! 4 columns of 4 components matrix of low precision floating-point numbers. //! There is no guarantee on the actual precision. - //! (From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers) + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers //! \ingroup core_precision - typedef detail::tmat4x4 lowp_mat4x4; + typedef detail::tmat4x4 lowp_mat4; + //! 4 columns of 4 components matrix of medium precision floating-point numbers. //! There is no guarantee on the actual precision. - //! (From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers) + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers //! \ingroup core_precision - typedef detail::tmat4x4 mediump_mat4x4; + typedef detail::tmat4x4 mediump_mat4; + //! 4 columns of 4 components matrix of high precision floating-point numbers. //! There is no guarantee on the actual precision. - //! (From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers) + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers + //! \ingroup core_precision + typedef detail::tmat4x4 highp_mat4; + + //! 4 columns of 4 components matrix of low precision floating-point numbers. + //! There is no guarantee on the actual precision. + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers + //! \ingroup core_precision + typedef detail::tmat4x4 lowp_mat4x4; + + //! 4 columns of 4 components matrix of medium precision floating-point numbers. + //! There is no guarantee on the actual precision. + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers + //! \ingroup core_precision + typedef detail::tmat4x4 mediump_mat4x4; + + //! 4 columns of 4 components matrix of high precision floating-point numbers. + //! There is no guarantee on the actual precision. + //! From GLSL 1.30.8 specification, section 4.1.6 Matrices and section 4.5 Precision and Precision Qualifiers //! \ingroup core_precision typedef detail::tmat4x4 highp_mat4x4; } From b3c293f8b4fde0c92b3552f4033ee66f66a67aac Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 31 May 2011 16:18:14 +0100 Subject: [PATCH 02/19] Fixed missing precision quaternion types --- glm/gtc/quaternion.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index 949f08f7..9aea66f4 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -221,6 +221,17 @@ namespace quaternion ///< GLM_GTC_quaternion extension: Quaternion types and fun //! From GLM_GTC_quaternion extension. typedef detail::tquat dquat; + //! Quaternion of low precision floating-point numbers. + //! From GLM_GTC_quaternion extension. + typedef detail::tquat lowp_quat; + + //! Quaternion of medium precision floating-point numbers. + //! From GLM_GTC_quaternion extension. + typedef detail::tquat mediump_quat; + + //! Quaternion of high precision floating-point numbers. + //! From GLM_GTC_quaternion extension. + typedef detail::tquat highp_quat; ///@} } //namespace quaternion From 6ff27ec9f9cf38da7550a889783c8a3f67d9283a Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 31 May 2011 16:45:41 +0100 Subject: [PATCH 03/19] Added half type tests --- test/gtc/gtc_half_float.cpp | 57 +++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/test/gtc/gtc_half_float.cpp b/test/gtc/gtc_half_float.cpp index 38b69d03..adfe1efa 100644 --- a/test/gtc/gtc_half_float.cpp +++ b/test/gtc/gtc_half_float.cpp @@ -1,18 +1,63 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net) /////////////////////////////////////////////////////////////////////////////////////////////////// -// Created : 2010-09-16 -// Updated : 2010-09-16 +// Created : 2011-05-32 +// Updated : 2011-05-32 // Licence : This source is under MIT licence -// File : test/gtc/matrix_transform.cpp +// File : test/gtc/half_float.cpp /////////////////////////////////////////////////////////////////////////////////////////////////// #include -#include +#include + +int test_half_precision_scalar() +{ + int Error = 0; + + Error += sizeof(glm::half) == 2 ? 0 : 1; + + return Error; +} + +int test_half_precision_vec() +{ + int Error = 0; + + Error += sizeof(glm::hvec2) == 4 ? 0 : 1; + Error += sizeof(glm::hvec3) == 6 ? 0 : 1; + Error += sizeof(glm::hvec4) == 8 ? 0 : 1; + + return Error; +} + +int test_half_precision_mat() +{ + int Error = 0; + + Error += sizeof(glm::hmat2) == 8 ? 0 : 1; + Error += sizeof(glm::hmat3) == 18 ? 0 : 1; + Error += sizeof(glm::hmat4) == 32 ? 0 : 1; + + Error += sizeof(glm::hmat2x2) == 8 ? 0 : 1; + Error += sizeof(glm::hmat2x3) == 12 ? 0 : 1; + Error += sizeof(glm::hmat2x4) == 16 ? 0 : 1; + Error += sizeof(glm::hmat3x2) == 12 ? 0 : 1; + Error += sizeof(glm::hmat3x3) == 18 ? 0 : 1; + Error += sizeof(glm::hmat3x4) == 24 ? 0 : 1; + Error += sizeof(glm::hmat4x2) == 16 ? 0 : 1; + Error += sizeof(glm::hmat4x3) == 24 ? 0 : 1; + Error += sizeof(glm::hmat4x4) == 32 ? 0 : 1; + + return Error; +} int main() { - int Failed = 0; + int Error = 0; - return Failed; + Error += test_half_precision_scalar(); + Error += test_half_precision_vec(); + Error += test_half_precision_mat(); + + return Error; } From 9fbf421f13b5f22d4cc025f2a0c60e604b2750bc Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 31 May 2011 16:46:13 +0100 Subject: [PATCH 04/19] Added quaternion test --- test/gtc/gtc_quaternion.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/gtc/gtc_quaternion.cpp b/test/gtc/gtc_quaternion.cpp index 7bd07c07..a84b03be 100644 --- a/test/gtc/gtc_quaternion.cpp +++ b/test/gtc/gtc_quaternion.cpp @@ -11,6 +11,16 @@ #include #include +int test_quat_precision() +{ + int Error = 0; + + Error += sizeof(glm::lowp_quat) <= sizeof(glm::mediump_quat) ? 0 : 1; + Error += sizeof(glm::mediump_quat) <= sizeof(glm::highp_quat) ? 0 : 1; + + return Error; +} + int test_quat_type() { glm::quat A; @@ -75,6 +85,7 @@ int main() { int Error = 0; + Error += test_quat_precision(); Error += test_quat_type(); Error += test_quat_slerp(); Error += test_quat_length(); From 6fab8113d78063cc2f6144239434d7f68e057614 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 31 May 2011 17:25:16 +0100 Subject: [PATCH 05/19] Fixed contructor of mat2 and added tests --- glm/core/type_mat2x2.hpp | 19 +++++++++++++++++ glm/core/type_mat2x2.inl | 42 +++++++++++++++++++++++++++++++++++-- glm/core/type_vec2.hpp | 2 +- test/gtc/gtc_half_float.cpp | 28 +++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/glm/core/type_mat2x2.hpp b/glm/core/type_mat2x2.hpp index 8d6a3918..7f0df2c7 100644 --- a/glm/core/type_mat2x2.hpp +++ b/glm/core/type_mat2x2.hpp @@ -56,10 +56,12 @@ namespace glm GLM_FUNC_DECL tmat2x2 _inverse() const; private: + ////////////////////////////////////// // Data col_type value[2]; public: + ////////////////////////////////////// // Constructors GLM_FUNC_DECL tmat2x2(); GLM_FUNC_DECL tmat2x2( @@ -76,6 +78,23 @@ namespace glm col_type const & v1, col_type const & v2); + ////////////////////////////////////// + // Convertion constructors + template + GLM_FUNC_DECL explicit tmat2x2( + U const & x); + + template + GLM_FUNC_DECL explicit tmat2x2( + U const & x1, V const & y1, + M const & x2, N const & y2); + + //template + //GLM_FUNC_DECL explicit tmat2x2( + // tvec2 const & v1, + // tvec2 const & v2); + + ////////////////////////////////////// // Conversions template GLM_FUNC_DECL explicit tmat2x2(tmat2x2 const & m); diff --git a/glm/core/type_mat2x2.inl b/glm/core/type_mat2x2.inl index 7a53a969..11a3f11c 100644 --- a/glm/core/type_mat2x2.inl +++ b/glm/core/type_mat2x2.inl @@ -107,8 +107,46 @@ namespace detail this->value[1] = v1; } + ////////////////////////////////////// + // Convertion constructors + template + template + GLM_FUNC_DECL tmat2x2::tmat2x2 + ( + U const & s + ) + { + value_type const Zero(0); + this->value[0] = tvec2(value_type(s), Zero); + this->value[1] = tvec2(Zero, value_type(s)); + } + + template + template + GLM_FUNC_DECL tmat2x2::tmat2x2 + ( + U const & x1, V const & y1, + M const & x2, N const & y2 + ) + { + this->value[0] = col_type(value_type(x1), value_type(y1)); + this->value[1] = col_type(value_type(x2), value_type(y2)); + } + + //template + //template + //GLM_FUNC_DECL tmat2x2::tmat2x2 + //( + // tvec2 const & v1, + // tvec2 const & v2 + //) + //{ + // this->value[0] = col_type(v1); + // this->value[1] = col_type(v2); + //} + ////////////////////////////////////////////////////////////// - // mat2 conversions + // mat2x2 conversions template template @@ -215,7 +253,7 @@ namespace detail } ////////////////////////////////////////////////////////////// - // mat3 operators + // mat2x2 operators // This function shouldn't required but it seems that VC7.1 have an optimisation bug if this operator wasn't declared template diff --git a/glm/core/type_vec2.hpp b/glm/core/type_vec2.hpp index 29d641ce..afaf8f8d 100644 --- a/glm/core/type_vec2.hpp +++ b/glm/core/type_vec2.hpp @@ -93,7 +93,7 @@ namespace glm tvec2(tref2 const & r); ////////////////////////////////////// - // Convertion scalar constructors + // Convertion constructors //! Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) template diff --git a/test/gtc/gtc_half_float.cpp b/test/gtc/gtc_half_float.cpp index adfe1efa..92b968b0 100644 --- a/test/gtc/gtc_half_float.cpp +++ b/test/gtc/gtc_half_float.cpp @@ -51,10 +51,38 @@ int test_half_precision_mat() return Error; } +int test_half_ctor_mat2x2() +{ + int Error = 0; + + { + glm::hvec2 A(1, 2); + glm::hvec2 B(3, 4); + glm::hmat2 C(A, B);//, 2.0f, 3.0f, 4.0f); + glm::hmat2 D(1, 2, 3, 4); + + Error += C[0] == D[0] ? 0 : 1; + Error += C[1] == D[1] ? 0 : 1; + } + + { + glm::hvec2 A(1, 2.0); + glm::hvec2 B(3, 4.0); + glm::hmat2 C(A, B);//, 2.0f, 3.0f, 4.0f); + glm::hmat2 D(1, 2.0, 3u, 4.0f); + + Error += C[0] == D[0] ? 0 : 1; + Error += C[1] == D[1] ? 0 : 1; + } + + return Error; +} + int main() { int Error = 0; + Error += test_half_ctor_mat2x2(); Error += test_half_precision_scalar(); Error += test_half_precision_vec(); Error += test_half_precision_mat(); From 69c6bdd7a8d19a2b0bb716ea850acac1e46378cb Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 31 May 2011 17:41:21 +0100 Subject: [PATCH 06/19] Fixed warnings on Visual C++ --- CMakeLists.txt | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85ae87a4..4115667c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,15 +5,18 @@ project(glm) enable_testing() add_definitions(-D_CRT_SECURE_NO_WARNINGS) -#add_definitions(/Za) -#add_definitions(-pedantic) -#add_definitions(-S) -#add_definitions(-s) -add_definitions(-msse2) -#add_definitions(-m32) -#add_definitions(-mfpmath=387) -#add_definitions(-ffast-math) -#add_definitions(-O3) + +if(CMAKE_COMPILER_IS_GNUCXX) + #add_definitions(/Za) + #add_definitions(-pedantic) + #add_definitions(-S) + #add_definitions(-s) + add_definitions(-msse2) + #add_definitions(-m32) + #add_definitions(-mfpmath=387) + #add_definitions(-ffast-math) + #add_definitions(-O3) +endif() include_directories(".") From d082ecf8a37bc5f4845c03fc78c50843a9bd63ea Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 31 May 2011 19:11:34 +0100 Subject: [PATCH 07/19] Added vec2 tests --- test/core/core_type_vec2.cpp | 91 ++++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 9 deletions(-) diff --git a/test/core/core_type_vec2.cpp b/test/core/core_type_vec2.cpp index 00c48a99..5f3fa735 100644 --- a/test/core/core_type_vec2.cpp +++ b/test/core/core_type_vec2.cpp @@ -2,28 +2,101 @@ // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net) /////////////////////////////////////////////////////////////////////////////////////////////////// // Created : 2008-08-31 -// Updated : 2008-08-31 +// Updated : 2011-05-31 // Licence : This source is under MIT License // File : test/core/type_vec2.cpp /////////////////////////////////////////////////////////////////////////////////////////////////// #include -static int test_operators() +int test_vec2_operators() { - glm::vec2 A(1.0f); - glm::vec2 B(1.0f); - bool R = A != B; - bool S = A == B; - - return (S && !R) ? 0 : 1; + int Error = 0; + + { + glm::vec2 A(1.0f); + glm::vec2 B(1.0f); + Error += A != B ? 1 : 0; + Error += A == B ? 0 : 1; + } + + { + glm::vec2 A(1.0f); + glm::vec2 C = A + 1.0f; + A += 1.0f; + Error += A.x == 2.0f && A.y == 2.0f ? 0 : 1; + Error += A.x == C.x && A.y == C.y ? 0 : 1; + } + + { + glm::vec2 A(1.0f); + glm::vec2 B(2.0f,-1.0f); + glm::vec2 C = A + B; + A += B; + Error += A.x == 3.0f && A.y == 0.0f ? 0 : 1; + Error += A.x == C.x && A.y == C.y ? 0 : 1; + } + + { + glm::vec2 A(1.0f); + glm::vec2 C = A - 1.0f; + A -= 1.0f; + Error += A.x == 0.0f && A.y == 0.0f ? 0 : 1; + Error += A.x == C.x && A.y == C.y ? 0 : 1; + } + + { + glm::vec2 A(1.0f); + glm::vec2 B(2.0f,-1.0f); + glm::vec2 C = A - B; + A -= B; + Error += A.x == -1.0f && A.y == 2.0f ? 0 : 1; + Error += A.x == C.x && A.y == C.y ? 0 : 1; + } + + { + glm::vec2 A(1.0f); + glm::vec2 C = A * 2.0f; + A *= 2.0f; + Error += A.x == 2.0f && A.y == 2.0f ? 0 : 1; + Error += A.x == C.x && A.y == C.y ? 0 : 1; + } + + { + glm::vec2 A(2.0f); + glm::vec2 B(2.0f); + glm::vec2 C = A / B; + A /= B; + Error += A.x == 1.0f && A.y == 1.0f ? 0 : 1; + Error += A.x == C.x && A.y == C.y ? 0 : 1; + } + + return Error; } +int test_vec2_ctor() +{ + int Error = 0; + + { + glm::vec2 A = glm::vec2(2.0f); + glm::vec2 B = glm::vec2(2.0f, 3.0f); + glm::vec2 C = glm::vec2(2.0f, 3.0); + glm::vec2 D = glm::dvec2(2.0); + glm::vec2 E(glm::dvec2(2.0)); + glm::vec2 F(glm::ivec2(2)); + + } + + return Error; +} + int main() { int Error = 0; - Error += test_operators(); + Error += test_vec2_ctor(); + Error += test_vec2_operators(); return Error; } From 9b8783d3c38f147b4746ae5521798b8b3c6f1cbc Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 31 May 2011 19:18:49 +0100 Subject: [PATCH 08/19] Added short and fast slerp tests --- test/gtx/gtx_quaternion.cpp | 38 ++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/test/gtx/gtx_quaternion.cpp b/test/gtx/gtx_quaternion.cpp index c498a0fb..5fb5ebd2 100644 --- a/test/gtx/gtx_quaternion.cpp +++ b/test/gtx/gtx_quaternion.cpp @@ -2,7 +2,7 @@ // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net) /////////////////////////////////////////////////////////////////////////////////////////////////// // Created : 2011-05-25 -// Updated : 2011-05-25 +// Updated : 2011-05-31 // Licence : This source is under MIT licence // File : test/gtx/quaternion.cpp /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -11,6 +11,40 @@ #include #include +int test_quat_fastMix() +{ + int Error = 0; + + glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1)); + glm::quat B = glm::angleAxis(90.0f, glm::vec3(0, 0, 1)); + glm::quat C = glm::fastMix(A, B, 0.5f); + glm::quat D = glm::angleAxis(45.0f, glm::vec3(0, 0, 1)); + + Error += glm::equalEpsilon(C.x, D.x, 0.01f) ? 0 : 1; + Error += glm::equalEpsilon(C.y, D.y, 0.01f) ? 0 : 1; + Error += glm::equalEpsilon(C.z, D.z, 0.01f) ? 0 : 1; + Error += glm::equalEpsilon(C.w, D.w, 0.01f) ? 0 : 1; + + return Error; +} + +int test_quat_shortMix() +{ + int Error = 0; + + glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1)); + glm::quat B = glm::angleAxis(90.0f, glm::vec3(0, 0, 1)); + glm::quat C = glm::shortMix(A, B, 0.5f); + glm::quat D = glm::angleAxis(45.0f, glm::vec3(0, 0, 1)); + + Error += glm::equalEpsilon(C.x, D.x, 0.01f) ? 0 : 1; + Error += glm::equalEpsilon(C.y, D.y, 0.01f) ? 0 : 1; + Error += glm::equalEpsilon(C.z, D.z, 0.01f) ? 0 : 1; + Error += glm::equalEpsilon(C.w, D.w, 0.01f) ? 0 : 1; + + return Error; +} + int test_quat_angleAxis() { int Error = 0; @@ -66,6 +100,8 @@ int main() Error += test_quat_angle(); Error += test_quat_angleAxis(); + Error += test_quat_fastMix(); + Error += test_quat_shortMix(); return Error; } From 87f1e507f3c69486a9a5fda0ff0f3f990f23b971 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 31 May 2011 19:28:30 +0100 Subject: [PATCH 09/19] Fixed mix build on MacOSX --- glm/gtc/quaternion.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index e262c663..a5ab33e0 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -430,7 +430,7 @@ namespace quaternion{ ) { T angle = acos(dot(x, y)); - return (sin((T(1) - a) * angle) * x + sin(a * angle) * y) / sin(angle); + return (glm::sin((T(1) - a) * angle) * x + glm::sin(a * angle) * y) / glm::sin(angle); } template From a849404eef541f0aaf0a2d2eb0a217fd1d4dde35 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 31 May 2011 19:29:54 +0100 Subject: [PATCH 10/19] Removed test that fails build... probably correct behaviour, to check tough. --- test/core/core_type_vec2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/core_type_vec2.cpp b/test/core/core_type_vec2.cpp index 5f3fa735..570d5437 100644 --- a/test/core/core_type_vec2.cpp +++ b/test/core/core_type_vec2.cpp @@ -82,7 +82,7 @@ int test_vec2_ctor() glm::vec2 A = glm::vec2(2.0f); glm::vec2 B = glm::vec2(2.0f, 3.0f); glm::vec2 C = glm::vec2(2.0f, 3.0); - glm::vec2 D = glm::dvec2(2.0); + //glm::vec2 D = glm::dvec2(2.0); // Build error TODO: What does the specification says? glm::vec2 E(glm::dvec2(2.0)); glm::vec2 F(glm::ivec2(2)); From 2b79365bafc3b02cc198f26e2352de3f3ee372e3 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 31 May 2011 19:34:19 +0100 Subject: [PATCH 11/19] Removed many warnings with GCC/LLVM --- glm/core/intrinsic_common.inl | 3 ++- glm/core/intrinsic_matrix.inl | 26 +------------------------- 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/glm/core/intrinsic_common.inl b/glm/core/intrinsic_common.inl index 82c940a8..5905b3b5 100644 --- a/glm/core/intrinsic_common.inl +++ b/glm/core/intrinsic_common.inl @@ -204,9 +204,10 @@ GLM_FUNC_QUALIFIER __m128 sse_mod_ps(__m128 x, __m128 y) return sub0; } +/// TODO GLM_FUNC_QUALIFIER __m128 sse_modf_ps(__m128 x, __m128i & i) { - + return __m128(); } //GLM_FUNC_QUALIFIER __m128 _mm_min_ps(__m128 x, __m128 y) diff --git a/glm/core/intrinsic_matrix.inl b/glm/core/intrinsic_matrix.inl index 326b65ba..1246a744 100644 --- a/glm/core/intrinsic_matrix.inl +++ b/glm/core/intrinsic_matrix.inl @@ -548,8 +548,6 @@ GLM_FUNC_QUALIFIER void sse_inverse_ps(__m128 const in[4], __m128 out[4]) __m128 Mul00 = _mm_mul_ps(Swp00, Swp01); __m128 Mul01 = _mm_mul_ps(Swp02, Swp03); Fac0 = _mm_sub_ps(Mul00, Mul01); - - bool stop = true; } __m128 Fac1; @@ -570,8 +568,6 @@ GLM_FUNC_QUALIFIER void sse_inverse_ps(__m128 const in[4], __m128 out[4]) __m128 Mul00 = _mm_mul_ps(Swp00, Swp01); __m128 Mul01 = _mm_mul_ps(Swp02, Swp03); Fac1 = _mm_sub_ps(Mul00, Mul01); - - bool stop = true; } @@ -593,9 +589,7 @@ GLM_FUNC_QUALIFIER void sse_inverse_ps(__m128 const in[4], __m128 out[4]) __m128 Mul00 = _mm_mul_ps(Swp00, Swp01); __m128 Mul01 = _mm_mul_ps(Swp02, Swp03); Fac2 = _mm_sub_ps(Mul00, Mul01); - - bool stop = true; - } + } __m128 Fac3; { @@ -615,8 +609,6 @@ GLM_FUNC_QUALIFIER void sse_inverse_ps(__m128 const in[4], __m128 out[4]) __m128 Mul00 = _mm_mul_ps(Swp00, Swp01); __m128 Mul01 = _mm_mul_ps(Swp02, Swp03); Fac3 = _mm_sub_ps(Mul00, Mul01); - - bool stop = true; } __m128 Fac4; @@ -637,8 +629,6 @@ GLM_FUNC_QUALIFIER void sse_inverse_ps(__m128 const in[4], __m128 out[4]) __m128 Mul00 = _mm_mul_ps(Swp00, Swp01); __m128 Mul01 = _mm_mul_ps(Swp02, Swp03); Fac4 = _mm_sub_ps(Mul00, Mul01); - - bool stop = true; } __m128 Fac5; @@ -659,8 +649,6 @@ GLM_FUNC_QUALIFIER void sse_inverse_ps(__m128 const in[4], __m128 out[4]) __m128 Mul00 = _mm_mul_ps(Swp00, Swp01); __m128 Mul01 = _mm_mul_ps(Swp02, Swp03); Fac5 = _mm_sub_ps(Mul00, Mul01); - - bool stop = true; } __m128 SignA = _mm_set_ps( 1.0f,-1.0f, 1.0f,-1.0f); @@ -781,8 +769,6 @@ GLM_FUNC_QUALIFIER void sse_inverse_fast_ps(__m128 const in[4], __m128 out[4]) __m128 Mul00 = _mm_mul_ps(Swp00, Swp01); __m128 Mul01 = _mm_mul_ps(Swp02, Swp03); Fac0 = _mm_sub_ps(Mul00, Mul01); - - bool stop = true; } __m128 Fac1; @@ -803,8 +789,6 @@ GLM_FUNC_QUALIFIER void sse_inverse_fast_ps(__m128 const in[4], __m128 out[4]) __m128 Mul00 = _mm_mul_ps(Swp00, Swp01); __m128 Mul01 = _mm_mul_ps(Swp02, Swp03); Fac1 = _mm_sub_ps(Mul00, Mul01); - - bool stop = true; } @@ -826,8 +810,6 @@ GLM_FUNC_QUALIFIER void sse_inverse_fast_ps(__m128 const in[4], __m128 out[4]) __m128 Mul00 = _mm_mul_ps(Swp00, Swp01); __m128 Mul01 = _mm_mul_ps(Swp02, Swp03); Fac2 = _mm_sub_ps(Mul00, Mul01); - - bool stop = true; } __m128 Fac3; @@ -848,8 +830,6 @@ GLM_FUNC_QUALIFIER void sse_inverse_fast_ps(__m128 const in[4], __m128 out[4]) __m128 Mul00 = _mm_mul_ps(Swp00, Swp01); __m128 Mul01 = _mm_mul_ps(Swp02, Swp03); Fac3 = _mm_sub_ps(Mul00, Mul01); - - bool stop = true; } __m128 Fac4; @@ -870,8 +850,6 @@ GLM_FUNC_QUALIFIER void sse_inverse_fast_ps(__m128 const in[4], __m128 out[4]) __m128 Mul00 = _mm_mul_ps(Swp00, Swp01); __m128 Mul01 = _mm_mul_ps(Swp02, Swp03); Fac4 = _mm_sub_ps(Mul00, Mul01); - - bool stop = true; } __m128 Fac5; @@ -892,8 +870,6 @@ GLM_FUNC_QUALIFIER void sse_inverse_fast_ps(__m128 const in[4], __m128 out[4]) __m128 Mul00 = _mm_mul_ps(Swp00, Swp01); __m128 Mul01 = _mm_mul_ps(Swp02, Swp03); Fac5 = _mm_sub_ps(Mul00, Mul01); - - bool stop = true; } __m128 SignA = _mm_set_ps( 1.0f,-1.0f, 1.0f,-1.0f); From 93e45a52d5deffc42f57531d630e2ff5e59b89f5 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 31 May 2011 21:30:52 +0100 Subject: [PATCH 12/19] Fixed warnings --- glm/core/type_mat3x4.inl | 2 -- 1 file changed, 2 deletions(-) diff --git a/glm/core/type_mat3x4.inl b/glm/core/type_mat3x4.inl index 3d322718..1a0b8499 100644 --- a/glm/core/type_mat3x4.inl +++ b/glm/core/type_mat3x4.inl @@ -53,8 +53,6 @@ namespace detail template GLM_FUNC_QUALIFIER tmat3x4::tmat3x4() { - value_type const Zero(0); - value_type const One(1); this->value[0] = col_type(1, 0, 0, 0); this->value[1] = col_type(0, 1, 0, 0); this->value[2] = col_type(0, 0, 1, 0); From b049cae5f28a17bb5da6ea067b0b2da3dc185004 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 1 Jun 2011 10:45:24 +0100 Subject: [PATCH 13/19] Updated random tests --- glm/gtx/random.inl | 2 +- test/gtx/CMakeLists.txt | 1 + test/gtx/gtx_noise.cpp | 25 +++++++++++++++++++++++- test/gtx/gtx_random.cpp | 42 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 test/gtx/gtx_random.cpp diff --git a/glm/gtx/random.inl b/glm/gtx/random.inl index f325d61d..77edea44 100644 --- a/glm/gtx/random.inl +++ b/glm/gtx/random.inl @@ -17,7 +17,7 @@ namespace random template <> GLM_FUNC_QUALIFIER float signedRand1() { - #if(GLM_COMPILER & GLM_COMPILER_VC) + #if(GLM_COMPILER & GLM_COMPILER_VC)// && (GLM_COMPILER < GLM_COMPILER_VC2010) #define RAND_SHIFT_NUM 5 #else #define RAND_SHIFT_NUM 0 diff --git a/test/gtx/CMakeLists.txt b/test/gtx/CMakeLists.txt index 48258987..38387f78 100644 --- a/test/gtx/CMakeLists.txt +++ b/test/gtx/CMakeLists.txt @@ -1,6 +1,7 @@ glmCreateTestGTC(gtx_bit) glmCreateTestGTC(gtx_noise) glmCreateTestGTC(gtx_quaternion) +glmCreateTestGTC(gtx_random) glmCreateTestGTC(gtx_rotate_vector) glmCreateTestGTC(gtx_simd_vec4) glmCreateTestGTC(gtx_simd_mat4) diff --git a/test/gtx/gtx_noise.cpp b/test/gtx/gtx_noise.cpp index 624ca022..8acaaaf4 100644 --- a/test/gtx/gtx_noise.cpp +++ b/test/gtx/gtx_noise.cpp @@ -11,17 +11,40 @@ #include #include -int main() +int test_simplex() { float ValueSNoise2D = glm::simplex(glm::vec2(0.5f)); float ValueSNoise3D = glm::simplex(glm::vec3(0.5f)); float ValueSNoise4D = glm::simplex(glm::vec4(0.5f)); + return 0; +} + +int test_perlin() +{ float ValueCNoise2D = glm::perlin(glm::vec2(0.5f)); float ValueCNoise3D = glm::perlin(glm::vec3(0.5f)); float ValueCNoise4D = glm::perlin(glm::vec4(0.5f)); + return 0; +} + +int test_perlin_pedioric() +{ float ValuePNoise2D = glm::perlin(glm::vec2(0.5f), glm::vec2(0.5f)); float ValuePNoise3D = glm::perlin(glm::vec3(0.5f), glm::vec3(0.5f)); float ValuePNoise4D = glm::perlin(glm::vec4(0.5f), glm::vec4(0.5f)); + + return 0; +} + +int main() +{ + int Error = 0; + + Error += test_simplex(); + Error += test_perlin(); + Error += test_perlin_pedioric(); + + return Error; } diff --git a/test/gtx/gtx_random.cpp b/test/gtx/gtx_random.cpp new file mode 100644 index 00000000..00ef2614 --- /dev/null +++ b/test/gtx/gtx_random.cpp @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////// +// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net) +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Created : 2011-05-31 +// Updated : 2011-05-31 +// Licence : This source is under MIT licence +// File : test/gtx/random.cpp +/////////////////////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + +int test_signedRand1() +{ + int Error = 0; + + { + float ResultFloat = 0.0f; + double ResultDouble = 0.0f; + for(std::size_t i = 0; i < 100000; ++i) + { + ResultFloat += glm::signedRand1(); + ResultDouble += glm::signedRand1(); + } + + Error += glm::equalEpsilon(ResultFloat, 0.0f, 0.0001f); + Error += glm::equalEpsilon(ResultDouble, 0.0, 0.0001); + } + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_signedRand1(); + + return Error; +} From 5375fbbc9777c3fe8c6eda18848524ba66cb4f1b Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 1 Jun 2011 11:57:43 +0100 Subject: [PATCH 14/19] Added random tests --- test/gtx/gtx_random.cpp | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/gtx/gtx_random.cpp b/test/gtx/gtx_random.cpp index 00ef2614..859faa52 100644 --- a/test/gtx/gtx_random.cpp +++ b/test/gtx/gtx_random.cpp @@ -32,11 +32,67 @@ int test_signedRand1() return Error; } +int test_normalizedRand2() +{ + int Error = 0; + + { + std::size_t Max = 100000; + float ResultFloat = 0.0f; + double ResultDouble = 0.0f; + for(std::size_t i = 0; i < Max; ++i) + { + ResultFloat += glm::length(glm::normalizedRand2()); + ResultDouble += glm::length(glm::normalizedRand2()); + } + + Error += glm::equalEpsilon(ResultFloat, float(Max), 0.0001f); + Error += glm::equalEpsilon(ResultDouble, double(Max), 0.0001); + } + + return Error; +} + +int test_normalizedRand3() +{ + int Error = 0; + + { + std::size_t Max = 100000; + float ResultFloatA = 0.0f; + float ResultFloatB = 0.0f; + float ResultFloatC = 0.0f; + double ResultDoubleA = 0.0f; + double ResultDoubleB = 0.0f; + double ResultDoubleC = 0.0f; + for(std::size_t i = 0; i < Max; ++i) + { + ResultFloatA += glm::length(glm::normalizedRand3()); + ResultDoubleA += glm::length(glm::normalizedRand3()); + ResultFloatB += glm::length(glm::normalizedRand3(2.0f, 2.0f)); + ResultDoubleB += glm::length(glm::normalizedRand3(2.0, 2.0)); + ResultFloatC += glm::length(glm::normalizedRand3(1.0f, 3.0f)); + ResultDoubleC += glm::length(glm::normalizedRand3(1.0, 3.0)); + } + + Error += glm::equalEpsilon(ResultFloatA, float(Max), 0.0001f) ? 0 : 1; + Error += glm::equalEpsilon(ResultDoubleA, double(Max), 0.0001) ? 0 : 1; + Error += glm::equalEpsilon(ResultFloatB, float(Max * 2), 0.0001f) ? 0 : 1; + Error += glm::equalEpsilon(ResultDoubleB, double(Max * 2), 0.0001) ? 0 : 1; + Error += (ResultFloatC >= float(Max) && ResultFloatC <= float(Max * 3)) ? 0 : 1; + Error += (ResultDoubleC >= double(Max) && ResultDoubleC <= double(Max * 3)) ? 0 : 1; + } + + return Error; +} + int main() { int Error = 0; Error += test_signedRand1(); + Error += test_normalizedRand2(); + Error += test_normalizedRand3(); return Error; } From 54e8df2ff374518d408548d4913287bd396aaea6 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 1 Jun 2011 16:09:20 +0100 Subject: [PATCH 15/19] Fixed compiler detection between GCC, LLVM and Clang; fixed MinGW build --- glm/core/intrinsic_common.inl | 8 ++++---- glm/core/setup.hpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/glm/core/intrinsic_common.inl b/glm/core/intrinsic_common.inl index 5905b3b5..fdaac0c8 100644 --- a/glm/core/intrinsic_common.inl +++ b/glm/core/intrinsic_common.inl @@ -205,10 +205,10 @@ GLM_FUNC_QUALIFIER __m128 sse_mod_ps(__m128 x, __m128 y) } /// TODO -GLM_FUNC_QUALIFIER __m128 sse_modf_ps(__m128 x, __m128i & i) -{ - return __m128(); -} +//GLM_FUNC_QUALIFIER __m128 sse_modf_ps(__m128 x, __m128i & i) +//{ +// return __m128(); +//} //GLM_FUNC_QUALIFIER __m128 _mm_min_ps(__m128 x, __m128 y) diff --git a/glm/core/setup.hpp b/glm/core/setup.hpp index 01075f3c..70ad1576 100644 --- a/glm/core/setup.hpp +++ b/glm/core/setup.hpp @@ -43,8 +43,8 @@ // GCC defines #define GLM_COMPILER_GCC 0x02000000 -#define GLM_COMPILER_GCC_LLVM 0x02000000 -#define GLM_COMPILER_GCC_CLANG 0x02000000 +#define GLM_COMPILER_GCC_LLVM 0x02000001 +#define GLM_COMPILER_GCC_CLANG 0x02000002 #define GLM_COMPILER_GCC30 0x02000010 #define GLM_COMPILER_GCC31 0x02000020 #define GLM_COMPILER_GCC32 0x02000030 @@ -214,9 +214,9 @@ # elif(GLM_COMPILER & GLM_COMPILER_LLVM_GCC) # pragma message("GLM: LLVM GCC compiler detected") # elif(GLM_COMPILER & GLM_COMPILER_GCC) -# if(GLM_COMPILER & GLM_COMPILER_GCC_LLVM) +# if(GLM_COMPILER == GLM_COMPILER_GCC_LLVM) # pragma message("GLM: LLVM GCC compiler detected") -# elif(GLM_COMPILER & GLM_COMPILER_GCC_CLANG) +# elif(GLM_COMPILER == GLM_COMPILER_GCC_CLANG) # pragma message("GLM: CLANG compiler detected") # else # pragma message("GLM: GCC compiler detected") From 6c9364c2e847876caaba06d95434aaef61630c4d Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 1 Jun 2011 16:17:45 +0100 Subject: [PATCH 16/19] Fixed ticket #104, dependence between GTX_epsilon and GTC_quaternion --- glm/gtx/epsilon.hpp | 4 +++- glm/gtx/epsilon.inl | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/glm/gtx/epsilon.hpp b/glm/gtx/epsilon.hpp index 7df2cb7d..3ee7f418 100644 --- a/glm/gtx/epsilon.hpp +++ b/glm/gtx/epsilon.hpp @@ -8,7 +8,8 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// // Dependency: // - GLM core -// - GLM_GTX_half +// - GLM_GTC_half_float +// - GLM_GTC_quaternion /////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef glm_gtx_epsilon @@ -17,6 +18,7 @@ // Dependency: #include "../glm.hpp" #include "../gtc/half_float.hpp" +#include "../gtc/quaternion.hpp" #if(defined(GLM_MESSAGES) && !defined(glm_ext)) # pragma message("GLM: GLM_GTX_epsilon extension included") diff --git a/glm/gtx/epsilon.inl b/glm/gtx/epsilon.inl index 1e424127..4eab9103 100644 --- a/glm/gtx/epsilon.inl +++ b/glm/gtx/epsilon.inl @@ -157,6 +157,21 @@ GLM_FUNC_QUALIFIER detail::tvec4 equalEpsilon abs(x.w - y.w) < epsilon.w); } +template +GLM_FUNC_QUALIFIER detail::tvec4 equalEpsilon +( + detail::tquat const & x, + detail::tquat const & y, + detail::tquat const & epsilon +) +{ + return detail::tvec4( + abs(x.x - y.x) < epsilon.x, + abs(x.y - y.y) < epsilon.y, + abs(x.z - y.z) < epsilon.z, + abs(x.w - y.w) < epsilon.w); +} + template GLM_FUNC_QUALIFIER detail::tvec2 notEqualEpsilon ( @@ -199,6 +214,21 @@ GLM_FUNC_QUALIFIER detail::tvec4 notEqualEpsilon abs(x.w - y.w) >= epsilon.w); } +template +GLM_FUNC_QUALIFIER detail::tvec4 notEqualEpsilon +( + detail::tquat const & x, + detail::tquat const & y, + detail::tquat const & epsilon +) +{ + return detail::tvec4( + abs(x.x - y.x) >= epsilon.x, + abs(x.y - y.y) >= epsilon.y, + abs(x.z - y.z) >= epsilon.z, + abs(x.w - y.w) >= epsilon.w); +} + }//namespace epsilon }//namespace gtx }//namespace glm From 2500be6bcba7d606f3f14df61a52eb0c56574bc4 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 1 Jun 2011 16:27:50 +0100 Subject: [PATCH 17/19] Fixed #95, shortMix implementation --- glm/gtx/quaternion.inl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/glm/gtx/quaternion.inl b/glm/gtx/quaternion.inl index ec713c8d..b63e6c0f 100644 --- a/glm/gtx/quaternion.inl +++ b/glm/gtx/quaternion.inl @@ -256,7 +256,7 @@ namespace quaternion if(a <= typename detail::tquat::value_type(0)) return x; if(a >= typename detail::tquat::value_type(1)) return y; - float fCos = dot(x, y); + detail::tquat::value_type fCos = dot(x, y); detail::tquat y2(y); //BUG!!! tquat y2; if(fCos < typename detail::tquat::value_type(0)) { @@ -265,7 +265,7 @@ namespace quaternion } //if(fCos > 1.0f) // problem - float k0, k1; + detail::tquat::value_type k0, k1; if(fCos > typename detail::tquat::value_type(0.9999)) { k0 = typename detail::tquat::value_type(1) - a; @@ -295,7 +295,7 @@ namespace quaternion T const & a ) { - return glm::normalize(x * (1 - a) + (y * a)); + return glm::normalize(x * (detail::tquat::value_type(1) - a) + (y * a)); } }//namespace quaternion From 39580d05f001eb9646cab2b6d6ecd4d99e55723f Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 1 Jun 2011 16:46:04 +0100 Subject: [PATCH 18/19] Fixed quaternion tests --- test/gtx/gtx_quaternion.cpp | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/gtx/gtx_quaternion.cpp b/test/gtx/gtx_quaternion.cpp index 5fb5ebd2..287dc1df 100644 --- a/test/gtx/gtx_quaternion.cpp +++ b/test/gtx/gtx_quaternion.cpp @@ -11,6 +11,23 @@ #include #include +int test_quat_mix() +{ + int Error = 0; + + glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1)); + glm::quat B = glm::angleAxis(90.0f, glm::vec3(0, 0, 1)); + glm::quat C = glm::mix(A, B, 0.5f); + glm::quat D = glm::angleAxis(45.0f, glm::vec3(0, 0, 1)); + + Error += glm::equalEpsilon(C.x, D.x, 0.01f) ? 0 : 1; + Error += glm::equalEpsilon(C.y, D.y, 0.01f) ? 0 : 1; + Error += glm::equalEpsilon(C.z, D.z, 0.01f) ? 0 : 1; + Error += glm::equalEpsilon(C.w, D.w, 0.01f) ? 0 : 1; + + return Error; +} + int test_quat_fastMix() { int Error = 0; @@ -94,14 +111,42 @@ int test_quat_angle() return Error; } +int test_quat_normalize() +{ + int Error = 0; + + { + glm::quat Q = glm::angleAxis(45.0f, glm::vec3(0, 0, 1)); + glm::quat N = glm::normalize(Q); + float L = glm::length(N); + Error += glm::equalEpsilon(L, 1.0f, 0.000001f) ? 0 : 1; + } + { + glm::quat Q = glm::angleAxis(45.0f, glm::vec3(0, 0, 2)); + glm::quat N = glm::normalize(Q); + float L = glm::length(N); + Error += glm::equalEpsilon(L, 1.0f, 0.000001f) ? 0 : 1; + } + { + glm::quat Q = glm::angleAxis(45.0f, glm::vec3(1, 2, 3)); + glm::quat N = glm::normalize(Q); + float L = glm::length(N); + Error += glm::equalEpsilon(L, 1.0f, 0.000001f) ? 0 : 1; + } + + return Error; +} + int main() { int Error = 0; Error += test_quat_angle(); Error += test_quat_angleAxis(); + Error += test_quat_mix(); Error += test_quat_fastMix(); Error += test_quat_shortMix(); + Error += test_quat_normalize(); return Error; } From e43633dbe6084b912fbcf1b640bdd5ed0a43f622 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 1 Jun 2011 17:00:20 +0100 Subject: [PATCH 19/19] Moved test to GTX tests --- glm/virtrev/xstream.hpp | 6 ++-- test/gtc/gtc_quaternion.cpp | 55 ------------------------------------- 2 files changed, 3 insertions(+), 58 deletions(-) diff --git a/glm/virtrev/xstream.hpp b/glm/virtrev/xstream.hpp index 1f19dae2..cf13ffbe 100644 --- a/glm/virtrev/xstream.hpp +++ b/glm/virtrev/xstream.hpp @@ -1,6 +1,3 @@ -#ifndef GLM_EXT_VIRTREV_XSTREAM_HPP -#define GLM_EXT_VIRTREV_XSTREAM_HPP - /////////////////////////////////////////////////////////////////////////////////////////////////// // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net) // Virtrev SDK copyright matrem (matrem84.free.fr) @@ -15,6 +12,9 @@ // - GLM_GTX_matrix_selection /////////////////////////////////////////////////////////////////////////////////////////////////// +#ifndef GLM_EXT_VIRTREV_XSTREAM_HPP +#define GLM_EXT_VIRTREV_XSTREAM_HPP + #include "../glm.hpp" #include "../gtc/matrix_access.hpp" #include diff --git a/test/gtc/gtc_quaternion.cpp b/test/gtc/gtc_quaternion.cpp index a84b03be..d59fb1a3 100644 --- a/test/gtc/gtc_quaternion.cpp +++ b/test/gtc/gtc_quaternion.cpp @@ -29,67 +29,12 @@ int test_quat_type() return 0; } -int test_quat_slerp() -{ - int Error = 0; - - glm::quat A(glm::vec3(0, 0, 1)); - glm::quat B(glm::vec3(0, 1, 0)); - glm::quat C = glm::mix(A, B, 0.5f); - glm::quat D(glm::normalize(glm::vec3(0, 1, 1))); - - Error += C == D ? 0 : 1; - - return Error; -} - -int test_quat_length() -{ - int Error = 0; - - float A = glm::length(glm::quat(45.0f, glm::vec3(0, 0, 1))); - Error += A == 1.0f ? 0 : 1; - float B = glm::length(glm::quat(90.0f, glm::vec3(0, 0, 2))); - Error += B == 2.0f ? 0 : 1; - - return Error; -} - -int test_quat_normalize() -{ - int Error = 0; - - { - glm::quat Q(45.0f, glm::vec3(0, 0, 1)); - glm::quat N = glm::normalize(Q); - float L = glm::length(N); - Error += L == 1.0f ? 0 : 1; - } - { - glm::quat Q(45.0f, glm::vec3(0, 0, 2)); - glm::quat N = glm::normalize(Q); - float L = glm::length(N); - Error += L == 1.0f ? 0 : 1; - } - { - glm::quat Q(45.0f, glm::vec3(1, 2, 3)); - glm::quat N = glm::normalize(Q); - float L = glm::length(N); - Error += L == 1.0f ? 0 : 1; - } - - return Error; -} - int main() { int Error = 0; Error += test_quat_precision(); Error += test_quat_type(); - Error += test_quat_slerp(); - Error += test_quat_length(); - Error += test_quat_normalize(); return Error; }