diff --git a/glm/detail/func_common.hpp b/glm/detail/func_common.hpp index a4c9bfcd..a3e5d633 100644 --- a/glm/detail/func_common.hpp +++ b/glm/detail/func_common.hpp @@ -258,6 +258,18 @@ namespace glm /// glm::dvec3 t = glm::mix(e, f, a); // Types of the third parameter is not required to match with the first and the second. /// glm::vec4 u = glm::mix(g, h, r); // Interpolations can be perform per component with a vector for the last parameter. /// @endcode + template class vecType> + GLM_FUNC_DECL vecType mix( + vecType const & x, + vecType const & y, + vecType const & a); + + template class vecType> + GLM_FUNC_DECL vecType mix( + vecType const & x, + vecType const & y, + U const & a); + template GLM_FUNC_DECL genTypeT mix( genTypeT const & x, diff --git a/glm/detail/func_common.inl b/glm/detail/func_common.inl index b5279795..65304a45 100644 --- a/glm/detail/func_common.inl +++ b/glm/detail/func_common.inl @@ -64,6 +64,63 @@ namespace detail return x; } }; + + template class vecType> + struct compute_mix_vector + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & x, vecType const & y, vecType const & a) + { + return vecType(vecType(x) + a * vecType(y - x)); + } + }; + + template class vecType> + struct compute_mix_vector + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & x, vecType const & y, vecType const & a) + { + vecType Result; + for(length_t i = 0; i < x.length(); ++i) + Result[i] = a[i] ? y[i] : x[i]; + return Result; + } + }; + + template class vecType> + struct compute_mix_scalar + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & x, vecType const & y, U const & a) + { + return vecType(vecType(x) + a * vecType(y - x)); + } + }; + + template class vecType> + struct compute_mix_scalar + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & x, vecType const & y, bool const & a) + { + return a ? y : x; + } + }; + + template + struct compute_mix + { + GLM_FUNC_QUALIFIER static T call(T const & x, T const & y, U const & a) + { + return static_cast(static_cast(x) + a * static_cast(y - x)); + } + }; + + template + struct compute_mix + { + GLM_FUNC_QUALIFIER static T call(T const & x, T const & y, bool const & a) + { + return a ? y : x; + } + }; }//namespace detail // abs @@ -459,250 +516,37 @@ namespace detail clamp(x.w, minVal.w, maxVal.w)); } - // mix - template - GLM_FUNC_QUALIFIER genType mix + template class vecType> + GLM_FUNC_QUALIFIER vecType mix ( - genType const & x, - genType const & y, - genType const & a + vecType const & x, + vecType const & y, + vecType const & a ) { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'mix' only accept floating-point inputs"); - - return x + a * (y - x); + return detail::compute_mix_vector::call(x, y, a); } - template - GLM_FUNC_QUALIFIER detail::tvec2 mix + template class vecType> + GLM_FUNC_QUALIFIER vecType mix ( - detail::tvec2 const & x, - detail::tvec2 const & y, - T const & a + vecType const & x, + vecType const & y, + U const & a ) { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'mix' only accept floating-point inputs"); - - return x + a * (y - x); + return detail::compute_mix_scalar::call(x, y, a); } - template - GLM_FUNC_QUALIFIER detail::tvec3 mix + template + GLM_FUNC_QUALIFIER genTypeT mix ( - detail::tvec3 const & x, - detail::tvec3 const & y, - T const & a - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'mix' only accept floating-point inputs"); - - return x + a * (y - x); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 mix - ( - detail::tvec4 const & x, - detail::tvec4 const & y, - T const & a - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'mix' only accept floating-point inputs"); - - return x + a * (y - x); - } - - template - GLM_FUNC_QUALIFIER detail::tvec2 mix - ( - detail::tvec2 const & x, - detail::tvec2 const & y, - detail::tvec2 const & a - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'mix' only accept floating-point inputs"); - - return x + a * (y - x); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 mix - ( - detail::tvec3 const & x, - detail::tvec3 const & y, - detail::tvec3 const & a + genTypeT const & x, + genTypeT const & y, + genTypeU const & a ) { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'mix' only accept floating-point inputs"); - - return x + a * (y - x); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 mix - ( - detail::tvec4 const & x, - detail::tvec4 const & y, - detail::tvec4 const & a - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'mix' only accept floating-point inputs"); - - return x + a * (y - x); - } - - //template - //GLM_FUNC_QUALIFIER genTypeT mix - //( - // genTypeT const & x, - // genTypeT const & y, - // float const & a - //) - //{ - // // It could be a vector too - // //GLM_STATIC_ASSERT( - // // detail::type::is_float && - // // detail::type::is_float); - - // return x + a * (y - x); - //} - - template <> - GLM_FUNC_QUALIFIER float mix - ( - float const & x, - float const & y, - bool const & a - ) - { - return a ? y : x; - } - - template <> - GLM_FUNC_QUALIFIER double mix - ( - double const & x, - double const & y, - bool const & a - ) - { - return a ? y : x; - } - - template - GLM_FUNC_QUALIFIER detail::tvec2 mix - ( - detail::tvec2 const & x, - detail::tvec2 const & y, - bool a - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'mix' only accept floating-point inputs"); - - return a ? y : x; - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 mix - ( - detail::tvec3 const & x, - detail::tvec3 const & y, - bool a - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'mix' only accept floating-point inputs"); - - return a ? y : x; - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 mix - ( - detail::tvec4 const & x, - detail::tvec4 const & y, - bool a - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'mix' only accept floating-point inputs"); - - return a ? y : x; - } - - template - GLM_FUNC_QUALIFIER detail::tvec2 mix - ( - detail::tvec2 const & x, - detail::tvec2 const & y, - typename detail::tvec2::bool_type a - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'mix' only accept floating-point inputs"); - - detail::tvec2 result; - for(int i = 0; i < x.length(); ++i) - result[i] = a[i] ? y[i] : x[i]; - - return result; - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 mix - ( - detail::tvec3 const & x, - detail::tvec3 const & y, - typename detail::tvec3::bool_type a - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'mix' only accept floating-point inputs"); - - detail::tvec3 result; - for(int i = 0; i < x.length(); ++i) - result[i] = a[i] ? y[i] : x[i]; - - return result; - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 mix - ( - detail::tvec4 const & x, - detail::tvec4 const & y, - typename detail::tvec4::bool_type a - ) - { - GLM_STATIC_ASSERT( - std::numeric_limits::is_iec559, - "'mix' only accept floating-point inputs"); - - detail::tvec4 result; - for(int i = 0; i < x.length(); ++i) - result[i] = a[i] ? y[i] : x[i]; - - return result; + return detail::compute_mix::call(x, y, a); } // step diff --git a/readme.txt b/readme.txt index e55a3272..549c3337 100644 --- a/readme.txt +++ b/readme.txt @@ -41,6 +41,7 @@ GLM 0.9.5.2: 2014-0X-XX -------------------------------------------------------------------------------- - Fixed warnings with the Android NDK 9c - Fixed non power of two matrix products +- Fixed mix function link error ================================================================================ GLM 0.9.5.1: 2014-01-11