From 6492c8593fb0c1c8f189e996fc6955e4cd549145 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 1 Mar 2019 12:33:09 +0100 Subject: [PATCH] - Added mix implementation for matrices in EXT_matrix_common #842 --- glm/ext/matrix_common.hpp | 36 +++++++++++++++++++++ glm/ext/matrix_common.inl | 16 ++++++++++ readme.md | 3 ++ test/ext/CMakeLists.txt | 1 + test/ext/ext_matrix_common.cpp | 53 +++++++++++++++++++++++++++++++ test/gtc/gtc_matrix_transform.cpp | 1 + 6 files changed, 110 insertions(+) create mode 100644 glm/ext/matrix_common.hpp create mode 100644 glm/ext/matrix_common.inl create mode 100644 test/ext/ext_matrix_common.cpp diff --git a/glm/ext/matrix_common.hpp b/glm/ext/matrix_common.hpp new file mode 100644 index 00000000..05c37991 --- /dev/null +++ b/glm/ext/matrix_common.hpp @@ -0,0 +1,36 @@ +/// @ref ext_matrix_common +/// @file glm/ext/matrix_common.hpp +/// +/// @defgroup ext_matrix_common GLM_EXT_matrix_common +/// @ingroup ext +/// +/// Defines functions for common matrix operations. +/// +/// Include to use the features of this extension. +/// +/// @see ext_matrix_common + +#pragma once + +#include "../detail/qualifier.hpp" +#include "../detail/_fixes.hpp" + +#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_EXT_matrix_transform extension included") +#endif + +namespace glm +{ + /// @addtogroup ext_matrix_common + /// @{ + + template + GLM_FUNC_DECL mat mix(mat const& x, mat const& y, mat const& a); + + template + GLM_FUNC_DECL mat mix(mat const& x, mat const& y, U a); + + /// @} +}//namespace glm + +#include "matrix_common.inl" diff --git a/glm/ext/matrix_common.inl b/glm/ext/matrix_common.inl new file mode 100644 index 00000000..9d508485 --- /dev/null +++ b/glm/ext/matrix_common.inl @@ -0,0 +1,16 @@ +#include "../matrix.hpp" + +namespace glm +{ + template + GLM_FUNC_QUALIFIER mat mix(mat const& x, mat const& y, U a) + { + return mat(x) * (static_cast(1) - a) + mat(y) * a; + } + + template + GLM_FUNC_QUALIFIER mat mix(mat const& x, mat const& y, mat const& a) + { + return matrixCompMult(mat(x), static_cast(1) - a) + matrixCompMult(mat(y), a); + } +}//namespace glm diff --git a/readme.md b/readme.md index 209fccbc..7dd4c4b1 100644 --- a/readme.md +++ b/readme.md @@ -53,6 +53,9 @@ glm::mat4 camera(float Translate, glm::vec2 const& Rotate) ## Release notes ### [GLM 0.9.9.4](https://github.com/g-truc/glm/tree/master) - 2018-1X-XX +#### Features: +- Added mix implementation for matrices in EXT_matrix_common #842 + #### Improvements: - Added GLM_FORCE_INTRINSICS to enable SIMD instruction code path. By default, it's disabled allowing constexpr support by default. diff --git a/test/ext/CMakeLists.txt b/test/ext/CMakeLists.txt index f4152e70..9c04a239 100644 --- a/test/ext/CMakeLists.txt +++ b/test/ext/CMakeLists.txt @@ -1,5 +1,6 @@ glmCreateTestGTC(ext_matrix_relational) glmCreateTestGTC(ext_matrix_transform) +glmCreateTestGTC(ext_matrix_common) glmCreateTestGTC(ext_quaternion_common) glmCreateTestGTC(ext_quaternion_exponential) glmCreateTestGTC(ext_quaternion_geometric) diff --git a/test/ext/ext_matrix_common.cpp b/test/ext/ext_matrix_common.cpp new file mode 100644 index 00000000..df0c3fe4 --- /dev/null +++ b/test/ext/ext_matrix_common.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include + +static int test_mix() +{ + int Error = 0; + + { + glm::mat4 A(2); + glm::mat4 B(4); + glm::mat4 C = glm::mix(A, B, 0.5f); + glm::bvec4 const D = glm::equal(C, glm::mat4(3), 1); + Error += glm::all(D) ? 0 : 1; + } + + { + glm::mat4 A(2); + glm::mat4 B(4); + glm::mat4 C = glm::mix(A, B, 0.5); + glm::bvec4 const D = glm::equal(C, glm::mat4(3), 1); + Error += glm::all(D) ? 0 : 1; + } + + { + glm::dmat4 A(2); + glm::dmat4 B(4); + glm::dmat4 C = glm::mix(A, B, 0.5); + glm::bvec4 const D = glm::equal(C, glm::dmat4(3), 1); + Error += glm::all(D) ? 0 : 1; + } + + { + glm::dmat4 A(2); + glm::dmat4 B(4); + glm::dmat4 C = glm::mix(A, B, 0.5f); + glm::bvec4 const D = glm::equal(C, glm::dmat4(3), 1); + Error += glm::all(D) ? 0 : 1; + } + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_mix(); + + return Error; +} diff --git a/test/gtc/gtc_matrix_transform.cpp b/test/gtc/gtc_matrix_transform.cpp index 0fd4d2f8..b50666e7 100644 --- a/test/gtc/gtc_matrix_transform.cpp +++ b/test/gtc/gtc_matrix_transform.cpp @@ -1,5 +1,6 @@ #include #include +#include int test_perspective() {