]> git.localhorst.tv Git - gong.git/blobdiff - src/geometry/primitive.hpp
sphere/sphere intersection test
[gong.git] / src / geometry / primitive.hpp
index c922506c40fa0e2281de5983bba01b11d36f8d90..e785c635cc1ecf15e7b63225eb12f4b968e7194f 100644 (file)
@@ -31,6 +31,11 @@ struct AABB {
                return glm::length(high);
        }
 
+       void Position(const glm::vec3 &center) noexcept {
+               const glm::vec3 halfsize((max - min) * 0.5f);
+               min = center - halfsize;
+               max = center + halfsize;
+       }
        void Move(const glm::vec3 &delta) noexcept {
                min += delta;
                max += delta;
@@ -170,12 +175,28 @@ bool CullTest(const AABB &box, const glm::mat4 &) noexcept;
 bool CullTest(const AABB &box, const Frustum &) noexcept;
 
 struct Sphere {
+
        glm::vec3 origin;
        float radius;
+
+       void Position(const glm::vec3 &center) noexcept {
+               origin = center;
+       }
+       void Move(const glm::vec3 &delta) noexcept {
+               origin += delta;
+       }
+
 };
 
 std::ostream &operator <<(std::ostream &, const Sphere &);
 
+/// Two spheres intersection test.
+bool Intersection(
+       const Sphere &,
+       const Sphere &,
+       float &dist,
+       glm::vec3 &norm) noexcept;
+
 /// Test for intersection of sphere with double sided infinite plane.
 /// If true, dist will hold the smaller interpenetration depth and norm
 /// the respective contact normal.