X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgeometry%2Fprimitive.hpp;h=e785c635cc1ecf15e7b63225eb12f4b968e7194f;hb=HEAD;hp=819ef04e77bd03e948b4c18fd051d817e610b69d;hpb=9932ee17a767b64cb52c213e133c6b91a90a8dd2;p=gong.git diff --git a/src/geometry/primitive.hpp b/src/geometry/primitive.hpp index 819ef04..e785c63 100644 --- a/src/geometry/primitive.hpp +++ b/src/geometry/primitive.hpp @@ -30,10 +30,22 @@ struct AABB { glm::vec3 high(glm::max(glm::abs(min), glm::abs(max))); return glm::length(high); } + + void Position(const glm::vec3 ¢er) 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; + } }; std::ostream &operator <<(std::ostream &, const AABB &); +bool Intersection(const AABB &, const AABB &) noexcept; + // TODO: this should really use setters/getters for dir and inv_dir so // manipulating code doesn't "forget" to call Update() struct Ray { @@ -163,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 ¢er) 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.