]> git.localhorst.tv Git - blank.git/blobdiff - src/model/geometry.hpp
make AI entities avoid world collisions
[blank.git] / src / model / geometry.hpp
index df45fff2f2a2797d789b06b9bd2ad71feb3c6464..5065124dad69a9974738a12035b8d4e1c18f4182 100644 (file)
@@ -2,6 +2,7 @@
 #define BLANK_MODEL_GEOMETRY_H_
 
 #include <algorithm>
+#include <limits>
 #include <glm/glm.hpp>
 
 
@@ -13,6 +14,52 @@ constexpr float PI_0p5 = PI * 0.5f;
 constexpr float PI_1p5 = PI * 1.5f;
 constexpr float PI_2p0 = PI * 2.0f;
 
+constexpr float PI_inv = 1.0f / PI;
+constexpr float PI_0p5_inv = 1.0f / PI_0p5;
+
+constexpr float DEG_RAD_FACTOR = PI / 180.0f;
+constexpr float RAD_DEG_FACTOR = 180.0f / PI;
+
+constexpr float deg2rad(float d) noexcept {
+       return d * DEG_RAD_FACTOR;
+}
+
+constexpr float rad2deg(float r) noexcept {
+       return r * RAD_DEG_FACTOR;
+}
+
+
+inline float length_squared(const glm::vec3 &v) noexcept {
+       return dot(v, v);
+}
+
+inline float distance_squared(const glm::vec3 &a, const glm::vec3 &b) noexcept {
+       return length_squared(a - b);
+}
+
+
+template <class T>
+inline bool iszero(const T &v) noexcept {
+       return length_squared(v) < std::numeric_limits<typename T::value_type>::epsilon();
+}
+
+
+template<class T>
+T manhattan_distance(const glm::tvec3<T> &a, const glm::tvec3<T> &b) noexcept {
+       glm::tvec3<T> diff(abs(a - b));
+       return diff.x + diff.y + diff.z;
+}
+
+template<class T>
+T manhattan_radius(const glm::tvec3<T> &v) noexcept {
+       glm::tvec3<T> a(abs(v));
+       return std::max(a.x, std::max(a.y, a.z));
+}
+
+
+glm::mat3 find_rotation(const glm::vec3 &a, const glm::vec3 &b) noexcept;
+
+
 struct AABB {
        glm::vec3 min;
        glm::vec3 max;