]> git.localhorst.tv Git - blobs.git/blob - src/math/glm.hpp
new glm version
[blobs.git] / src / math / glm.hpp
1 #ifndef BLOBS_MATH_GLM_HPP_
2 #define BLOBS_MATH_GLM_HPP_
3
4 #ifndef GLM_FORCE_RADIANS
5 #  define GLM_FORCE_RADIANS 1
6 #endif
7
8 // wait what? quaternions are experimental -.-
9 #define GLM_ENABLE_EXPERIMENTAL
10
11 #include <algorithm>
12 #include <limits>
13 #include <glm/glm.hpp>
14 #include <glm/gtx/norm.hpp>
15 #include <glm/gtx/component_wise.hpp>
16
17 // GLM moved tvec[1234] from glm::detail to glm in 0.9.6
18
19 #if GLM_VERSION < 96
20
21 namespace glm {
22         template<class T, precision P = defaultp>
23         using tvec1 = detail::tvec1<T, P>;
24         template<class T, precision P = defaultp>
25         using tvec2 = detail::tvec2<T, P>;
26         template<class T, precision P = defaultp>
27         using tvec3 = detail::tvec3<T, P>;
28         template<class T, precision P = defaultp>
29         using tvec4 = detail::tvec4<T, P>;
30 }
31
32 #endif
33
34 template <class T>
35 inline bool allzero(const T &v) noexcept {
36         return glm::length2(v) <
37                 std::numeric_limits<typename T::value_type>::epsilon()
38                 * std::numeric_limits<typename T::value_type>::epsilon();
39 }
40
41 template <class T>
42 inline bool anynan(const T &v) noexcept {
43         return glm::any(glm::isnan(v));
44 }
45
46 template<class Vec>
47 inline Vec limit(const Vec &v, typename Vec::value_type max) noexcept {
48         typename Vec::value_type len2 = glm::length2(v);
49         typename Vec::value_type max2 = max * max;
50         if (len2 > max2) {
51                 return glm::normalize(v) * max;
52         } else {
53                 return v;
54         }
55 }
56
57 #endif