diff --git a/doc/glm.docx b/doc/glm.docx index 7d4dcd91..bcfce5f4 100644 Binary files a/doc/glm.docx and b/doc/glm.docx differ diff --git a/glm/gtx/component_wise.hpp b/glm/gtx/component_wise.hpp index 4c19f85b..acc2adc6 100644 --- a/glm/gtx/component_wise.hpp +++ b/glm/gtx/component_wise.hpp @@ -60,6 +60,9 @@ namespace glm template class vecType> GLM_FUNC_DECL vecType compNormalize(vecType const & v); + template class vecType> + GLM_FUNC_DECL vecType compScale(vecType const & v); + /// Add all vector components together. /// @see gtx_component_wise template diff --git a/glm/gtx/component_wise.inl b/glm/gtx/component_wise.inl index 99936e37..b091c9e1 100644 --- a/glm/gtx/component_wise.inl +++ b/glm/gtx/component_wise.inl @@ -67,6 +67,39 @@ namespace detail return v; } }; + + template class vecType, bool isInteger, bool signedType> + struct compute_compScale + {}; + + template class vecType> + struct compute_compScale + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & v) + { + floatType const Min = static_cast(std::numeric_limits::min()); + floatType const Max = static_cast(std::numeric_limits::max()); + return (vecType(v) + Min) * (Max - Min) * static_cast(2) - static_cast(1); + } + }; + + template class vecType> + struct compute_compScale + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & v) + { + return vecType(vecType(v) * static_cast(std::numeric_limits::max())); + } + }; + + template class vecType> + struct compute_compScale + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & v) + { + return v; + } + }; }//namespace detail template class vecType> @@ -77,6 +110,14 @@ namespace detail return detail::compute_compNormalize::is_integer, std::numeric_limits::is_signed>::call(v); } + template class vecType> + GLM_FUNC_QUALIFIER vecType compScale(vecType const & v) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'compNormalize' accepts only floating-point types for 'floatType' template parameter"); + + return detail::compute_compScale::is_integer, std::numeric_limits::is_signed>::call(v); + } + template class vecType> GLM_FUNC_QUALIFIER T compAdd(vecType const & v) { diff --git a/test/gtx/gtx_component_wise.cpp b/test/gtx/gtx_component_wise.cpp index 2556a717..4eed3293 100644 --- a/test/gtx/gtx_component_wise.cpp +++ b/test/gtx/gtx_component_wise.cpp @@ -35,7 +35,7 @@ #include #include -namespace integer_8bit_test +namespace compNormalize { int run() { @@ -59,16 +59,6 @@ namespace integer_8bit_test Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon()) ? 0 : 1; } - return Error; - } -}//namespace integer_8bit_test - -namespace integer_16bit_test -{ - int run() - { - int Error(0); - { glm::vec4 const A = glm::compNormalize(glm::u16vec4( std::numeric_limits::min(), @@ -97,14 +87,42 @@ namespace integer_16bit_test return Error; } -}//namespace integer_16bit_test +}//namespace compNormalize + +namespace compScale +{ + int run() + { + int Error(0); + + { + glm::u8vec4 const A = glm::compScale(glm::vec4(0.0f, 0.2f, 0.5f, 1.0f)); + + Error += A.x == std::numeric_limits::min() ? 0 : 1; + Error += A.y > (std::numeric_limits::max() >> 1) ? 0 : 1; + Error += A.z < (std::numeric_limits::max() >> 2) ? 0 : 1; + Error += A.x == std::numeric_limits::max() ? 0 : 1; + } + + { + glm::u16vec4 const A = glm::compScale(glm::vec4(0.0f, 0.2f, 0.5f, 1.0f)); + + Error += A.x == std::numeric_limits::min() ? 0 : 1; + Error += A.y > (std::numeric_limits::max() >> 1) ? 0 : 1; + Error += A.z < (std::numeric_limits::max() >> 2) ? 0 : 1; + Error += A.x == std::numeric_limits::max() ? 0 : 1; + } + + return Error; + } +}// compScale int main() { int Error(0); - Error += integer_8bit_test::run(); - Error += integer_16bit_test::run(); + Error += compNormalize::run(); + Error += compScale::run(); return Error; }