]> git.localhorst.tv Git - blobs.git/blobdiff - src/math/glm.hpp
new glm version
[blobs.git] / src / math / glm.hpp
index 4b1bf336fc5cdf76b91d099f2d0d773c0ea9f762..ab79405597646718958dce26c64d934829ea682c 100644 (file)
@@ -5,6 +5,10 @@
 #  define GLM_FORCE_RADIANS 1
 #endif
 
+// wait what? quaternions are experimental -.-
+#define GLM_ENABLE_EXPERIMENTAL
+
+#include <algorithm>
 #include <limits>
 #include <glm/glm.hpp>
 #include <glm/gtx/norm.hpp>
 #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
@@ -35,5 +43,15 @@ 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;
+       }
+}
 
 #endif