From 34dc3a6ef67d7a246eb61d5187aac73bef77c6ff Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 2 May 2012 13:06:00 +0100 Subject: [PATCH 1/3] Fixed matrixCompMult function for none square matrix --- glm/core/func_matrix.inl | 2 +- test/core/core_func_matrix.cpp | 60 ++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/glm/core/func_matrix.inl b/glm/core/func_matrix.inl index 78f26cf8..3d8ab4f8 100644 --- a/glm/core/func_matrix.inl +++ b/glm/core/func_matrix.inl @@ -41,7 +41,7 @@ namespace glm GLM_STATIC_ASSERT(detail::type::is_float, "'matrixCompMult' only accept floating-point inputs"); matType result(matType::null); - for(typename matType::size_type i = 0; i < matType::col_size(); ++i) + for(typename matType::size_type i = 0; i < matType::row_size(); ++i) result[i] = x[i] * y[i]; return result; } diff --git a/test/core/core_func_matrix.cpp b/test/core/core_func_matrix.cpp index cbdb6d0e..608e54f3 100644 --- a/test/core/core_func_matrix.cpp +++ b/test/core/core_func_matrix.cpp @@ -11,9 +11,63 @@ int test_matrixCompMult() { - - - return 0; + 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; + } + + { + 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; + } + + { + 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; + } + + { + 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; + } + + { + 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; + } + + { + 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; + } + + { + 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; + } + + { + 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; + } + + { + 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; + } + + return Error; } int test_outerProduct() From 45f82ab8846a3f300550cf3ceeadc028f5a35923 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 2 May 2012 12:25:15 +0100 Subject: [PATCH 2/3] Added transpose test --- test/core/core_func_matrix.cpp | 58 ++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/test/core/core_func_matrix.cpp b/test/core/core_func_matrix.cpp index 608e54f3..990d2cd3 100644 --- a/test/core/core_func_matrix.cpp +++ b/test/core/core_func_matrix.cpp @@ -2,7 +2,7 @@ // OpenGL Mathematics Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net) /////////////////////////////////////////////////////////////////////////////////////////////////// // Created : 2011-01-15 -// Updated : 2011-01-15 +// Updated : 2012-05-02 // Licence : This source is under MIT licence // File : test/core/func_matrix.cpp /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -79,9 +79,63 @@ 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; + } + { + 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; + } - return 0; + { + 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, 3, 1, 4, 2, 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, 4, 1, 5, 2, 6, 3, 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, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11) ? 0 : 1; + } + + return Error; } int test_determinant() From ade527271eec16de8c6469041a47b7b5e442a4ae Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 2 May 2012 12:34:07 +0100 Subject: [PATCH 3/3] Fixed transpose test --- test/core/core_func_matrix.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/core/core_func_matrix.cpp b/test/core/core_func_matrix.cpp index 990d2cd3..ad804ab7 100644 --- a/test/core/core_func_matrix.cpp +++ b/test/core/core_func_matrix.cpp @@ -108,7 +108,7 @@ int test_transpose() { glm::mat3x2 m(0, 1, 2, 3, 4, 5); glm::mat2x3 t = glm::transpose(m); - Error += t == glm::mat2x3(0, 3, 1, 4, 2, 5) ? 0 : 1; + Error += t == glm::mat2x3(0, 2, 4, 1, 3, 5) ? 0 : 1; } { @@ -126,13 +126,13 @@ int test_transpose() { glm::mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7); glm::mat2x4 t = glm::transpose(m); - Error += t == glm::mat2x4(0, 4, 1, 5, 2, 6, 3, 7) ? 0 : 1; + 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, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11) ? 0 : 1; + Error += t == glm::mat3x4(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11) ? 0 : 1; } return Error;