]> git.localhorst.tv Git - blobs.git/blobdiff - src/math/glm.hpp
face direction
[blobs.git] / src / math / glm.hpp
index 80126aaa31908e7d309d68ac4fdbeba58da2013a..7bb321f712c20b4018c5b9507d7568627a53f2fd 100644 (file)
@@ -36,6 +36,17 @@ inline bool anynan(const T &v) noexcept {
        return glm::any(glm::isnan(v));
 }
 
+template<class Vec>
+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<class T>
 inline T rgb2hsl(const T &rgb) {
        using Vec4 = glm::tvec4<typename T::value_type>;