]> git.localhorst.tv Git - blank.git/blobdiff - src/model/geometry.hpp
load models from assets
[blank.git] / src / model / geometry.hpp
index d6e3d2847782e2b1d882e49d7e5cf3fa7e77386a..f9f87c4f9d14462f31af92b16247e5a6aad584e9 100644 (file)
@@ -13,6 +13,31 @@ constexpr float PI_0p5 = PI * 0.5f;
 constexpr float PI_1p5 = PI * 1.5f;
 constexpr float PI_2p0 = PI * 2.0f;
 
+constexpr float DEG_RAD_FACTOR = PI / 180.0f;
+constexpr float RAD_DEG_FACTOR = 180.0f / PI;
+
+constexpr float deg2rad(float d) {
+       return d * DEG_RAD_FACTOR;
+}
+
+constexpr float rad2deg(float r) {
+       return r * RAD_DEG_FACTOR;
+}
+
+
+template<class T>
+T manhattan_distance(const glm::tvec3<T> &a, const glm::tvec3<T> &b) {
+       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) {
+       glm::tvec3<T> a(abs(v));
+       return std::max(a.x, std::max(a.y, a.z));
+}
+
+
 struct AABB {
        glm::vec3 min;
        glm::vec3 max;
@@ -22,6 +47,10 @@ struct AABB {
                if (max.y < min.y) std::swap(max.y, min.y);
                if (max.z < min.z) std::swap(max.z, min.z);
        }
+
+       glm::vec3 Center() const noexcept {
+               return min + (max - min) * 0.5f;
+       }
 };
 
 struct Ray {
@@ -36,6 +65,14 @@ bool Intersection(
        float *dist = nullptr,
        glm::vec3 *normal = nullptr) noexcept;
 
+bool Intersection(
+       const AABB &a_box,
+       const glm::mat4 &a_m,
+       const AABB &b_box,
+       const glm::mat4 &b_m,
+       float &depth,
+       glm::vec3 &normal) noexcept;
+
 bool CullTest(const AABB &box, const glm::mat4 &MVP) noexcept;
 
 }