X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmath%2Fglm.hpp;h=0d344e6e7879bbb4786aecb64266060854154f7a;hb=d921cba26f21e4a75b22f5e9d9be988707bf6a8f;hp=80126aaa31908e7d309d68ac4fdbeba58da2013a;hpb=2ab70a92ae39cebc6166ef15545ebcbd31a31c38;p=blobs.git diff --git a/src/math/glm.hpp b/src/math/glm.hpp index 80126aa..0d344e6 100644 --- a/src/math/glm.hpp +++ b/src/math/glm.hpp @@ -16,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 @@ -36,6 +40,17 @@ 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; + } +} + template inline T rgb2hsl(const T &rgb) { using Vec4 = glm::tvec4;