X-Git-Url: http://git.localhorst.tv/?p=blobs.git;a=blobdiff_plain;f=src%2Fmath%2Fglm.hpp;h=7bb321f712c20b4018c5b9507d7568627a53f2fd;hp=80126aaa31908e7d309d68ac4fdbeba58da2013a;hb=b9af958c3f80a966bd31c622a45d0f3375bf2c3a;hpb=dd8b3145a03ed676b0ae6311c29fc3d68f666b15 diff --git a/src/math/glm.hpp b/src/math/glm.hpp index 80126aa..7bb321f 100644 --- a/src/math/glm.hpp +++ b/src/math/glm.hpp @@ -36,6 +36,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;