From: Daniel Karbach Date: Tue, 23 Jun 2015 15:41:55 +0000 (+0200) Subject: plug box intersection into shapes X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=bc1cefd505bf1f34639b8839cb337b08310ceb8e;p=blank.git plug box intersection into shapes --- diff --git a/src/model/Shape.hpp b/src/model/Shape.hpp index 5d4036b..39dd50f 100644 --- a/src/model/Shape.hpp +++ b/src/model/Shape.hpp @@ -11,6 +11,7 @@ namespace blank { +class AABB; class Ray; struct Shape { @@ -73,6 +74,14 @@ struct Shape { glm::vec3 &normal ) const noexcept = 0; + /// Check for intersection with given OBB. + /// The OBB is defined by box and box_M, M is applied to the shape. + virtual bool Intersects( + const glm::mat4 &M, + const AABB &box, + const glm::mat4 &box_M + ) const noexcept = 0; + protected: void SetShape(const Model::Positions &pos, const Model::Normals &nrm, const Model::Indices &idx) { vtx_pos = pos; diff --git a/src/model/shape.cpp b/src/model/shape.cpp index 1c83149..8265943 100644 --- a/src/model/shape.cpp +++ b/src/model/shape.cpp @@ -80,6 +80,14 @@ bool NullShape::Intersects( return false; } +bool NullShape::Intersects( + const glm::mat4 &, + const AABB &, + const glm::mat4 & +) const noexcept { + return false; +} + CuboidShape::CuboidShape(const AABB &b) : Shape() @@ -167,6 +175,14 @@ bool CuboidShape::Intersects( return Intersection(ray, bb, M, &dist, &normal); } +bool CuboidShape::Intersects( + const glm::mat4 &M, + const AABB &box, + const glm::mat4 &box_M +) const noexcept { + return Intersection(bb, M, box, box_M); +} + StairShape::StairShape(const AABB &bb, const glm::vec2 &clip) : Shape() @@ -326,4 +342,12 @@ bool StairShape::Intersects( } } +bool StairShape::Intersects( + const glm::mat4 &M, + const AABB &box, + const glm::mat4 &box_M +) const noexcept { + return Intersection(bot, M, box, box_M) || Intersection(top, M, box, box_M); +} + } diff --git a/src/model/shapes.hpp b/src/model/shapes.hpp index b5e965a..8ead23d 100644 --- a/src/model/shapes.hpp +++ b/src/model/shapes.hpp @@ -17,6 +17,7 @@ public: NullShape(); bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override; + bool Intersects(const glm::mat4 &, const AABB &, const glm::mat4 &) const noexcept override; }; @@ -28,6 +29,7 @@ public: CuboidShape(const AABB &bounds); bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override; + bool Intersects(const glm::mat4 &, const AABB &, const glm::mat4 &) const noexcept override; private: AABB bb; @@ -42,6 +44,7 @@ public: StairShape(const AABB &bounds, const glm::vec2 &clip); bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override; + bool Intersects(const glm::mat4 &, const AABB &, const glm::mat4 &) const noexcept override; private: AABB top, bot;