From e62817b8252974b8a98393275874ee303840bf13 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Fri, 12 May 2017 18:49:50 +0500 Subject: 2017-05-12 --- depedencies/include/glm/gtx/component_wise.inl | 128 +++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 depedencies/include/glm/gtx/component_wise.inl (limited to 'depedencies/include/glm/gtx/component_wise.inl') diff --git a/depedencies/include/glm/gtx/component_wise.inl b/depedencies/include/glm/gtx/component_wise.inl new file mode 100644 index 0000000..add3969 --- /dev/null +++ b/depedencies/include/glm/gtx/component_wise.inl @@ -0,0 +1,128 @@ +/// @ref gtx_component_wise +/// @file glm/gtx/component_wise.inl + +#include + +namespace glm{ +namespace detail +{ + template class vecType, bool isInteger, bool signedType> + struct compute_compNormalize + {}; + + template class vecType> + struct compute_compNormalize + { + 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_compNormalize + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & v) + { + return vecType(v) / static_cast(std::numeric_limits::max()); + } + }; + + template class vecType> + struct compute_compNormalize + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & v) + { + 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 Max = static_cast(std::numeric_limits::max()) + static_cast(0.5); + vecType const Scaled(v * Max); + vecType const Result(Scaled - static_cast(0.5)); + return Result; + } + }; + + 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> + GLM_FUNC_QUALIFIER vecType compNormalize(vecType const & v) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'compNormalize' accepts only floating-point types for 'floatType' template parameter"); + + 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, "'compScale' 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) + { + T Result(0); + for(length_t i = 0, n = v.length(); i < n; ++i) + Result += v[i]; + return Result; + } + + template class vecType> + GLM_FUNC_QUALIFIER T compMul(vecType const & v) + { + T Result(1); + for(length_t i = 0, n = v.length(); i < n; ++i) + Result *= v[i]; + return Result; + } + + template class vecType> + GLM_FUNC_QUALIFIER T compMin(vecType const & v) + { + T Result(v[0]); + for(length_t i = 1, n = v.length(); i < n; ++i) + Result = min(Result, v[i]); + return Result; + } + + template class vecType> + GLM_FUNC_QUALIFIER T compMax(vecType const & v) + { + T Result(v[0]); + for(length_t i = 1, n = v.length(); i < n; ++i) + Result = max(Result, v[i]); + return Result; + } +}//namespace glm -- cgit v1.2.3