X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmath%2Fglm.hpp;h=76472e8baa2b166d90243b4e3ce11811ce331222;hb=01cc65097f27ad657130fb58a10813e8d5c09fe7;hp=4b1bf336fc5cdf76b91d099f2d0d773c0ea9f762;hpb=8f6530c75730f901efd6708e4fde7e68a178adf1;p=blobs.git diff --git a/src/math/glm.hpp b/src/math/glm.hpp index 4b1bf33..76472e8 100644 --- a/src/math/glm.hpp +++ b/src/math/glm.hpp @@ -5,6 +5,7 @@ # define GLM_FORCE_RADIANS 1 #endif +#include #include #include #include @@ -15,10 +16,14 @@ #if GLM_VERSION < 96 namespace glm { - using tvec1 = detail::tvec1; - using tvec2 = detail::tvec2; - using tvec3 = detail::tvec3; - using tvec4 = detail::tvec4; + template + using tvec1 = detail::tvec1; + template + using tvec2 = detail::tvec2; + template + using tvec3 = detail::tvec3; + template + using tvec4 = detail::tvec4; } #endif @@ -35,5 +40,15 @@ inline bool anynan(const T &v) noexcept { return glm::any(glm::isnan(v)); } +template +inline Vec limit(const Vec &v, typename Vec::value_type max) noexcept { + typename Vec::value_type len2 = glm::length2(v); + typename Vec::value_type max2 = max * max; + if (len2 > max2) { + return glm::normalize(v) * max; + } else { + return v; + } +} #endif