]> git.localhorst.tv Git - blobs.git/blobdiff - src/math/glm.hpp
old glm?
[blobs.git] / src / math / glm.hpp
index 80126aaa31908e7d309d68ac4fdbeba58da2013a..0d344e6e7879bbb4786aecb64266060854154f7a 100644 (file)
 #if GLM_VERSION < 96
 
 namespace glm {
-       using tvec1 = detail::tvec1;
-       using tvec2 = detail::tvec2;
-       using tvec3 = detail::tvec3;
-       using tvec4 = detail::tvec4;
+       template<class T, precision P = defaultp>
+       using tvec1 = detail::tvec1<T, P>;
+       template<class T, precision P = defaultp>
+       using tvec2 = detail::tvec2<T, P>;
+       template<class T, precision P = defaultp>
+       using tvec3 = detail::tvec3<T, P>;
+       template<class T, precision P = defaultp>
+       using tvec4 = detail::tvec4<T, P>;
 }
 
 #endif
@@ -36,6 +40,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>;