]> git.localhorst.tv Git - gong.git/blobdiff - src/geometry/geometry.cpp
simple AABB intersection test
[gong.git] / src / geometry / geometry.cpp
index 1c1bfd61655bf8e2225d681c35984798f400da56..002c68f0d1ba69760b65d41049e069a2ef2d490a 100644 (file)
@@ -46,6 +46,16 @@ std::ostream &operator <<(std::ostream &out, const AABB &box) {
        return out << "AABB(" << box.min << ", " << box.max << ')';
 }
 
+bool Intersection(const AABB &a, const AABB &b) noexcept {
+       if (a.max.x < b.min.x) return false;
+       if (b.max.x < a.min.x) return false;
+       if (a.max.y < b.min.y) return false;
+       if (b.max.y < a.min.y) return false;
+       if (a.max.z < b.min.z) return false;
+       if (b.max.z < a.min.z) return false;
+       return true;
+}
+
 std::ostream &operator <<(std::ostream &out, const Ray &ray) {
        return out << "Ray(" << ray.orig << ", " << ray.dir << ')';
 }