X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=src%2Fgeometry%2Fprimitive.hpp;h=819ef04e77bd03e948b4c18fd051d817e610b69d;hb=9932ee17a767b64cb52c213e133c6b91a90a8dd2;hp=4711306ab1d0492df33736416fc9cba0199dc586;hpb=0e069351615f1315a5c7103fe5c849a242f72683;p=gong.git diff --git a/src/geometry/primitive.hpp b/src/geometry/primitive.hpp index 4711306..819ef04 100644 --- a/src/geometry/primitive.hpp +++ b/src/geometry/primitive.hpp @@ -87,7 +87,8 @@ bool Intersection( float &depth, glm::vec3 &normal) noexcept; - +/// Plane defined by a surface norml and distance to the origin such that +/// the point (normal * dist) lies on the plane. struct Plane { glm::vec3 normal; float dist; @@ -115,6 +116,13 @@ struct Plane { std::ostream &operator <<(std::ostream &, const Plane &); +/// Shortest distance from point to plane. +float Distance(const glm::vec3 &point, const Plane &plane); +/// Shortest distance from point to plane with sign indicating whether +/// it's in front of (positive, in direction of normal) or behind +/// (negative, counter direction of normal) the surface. +float SignedDistance(const glm::vec3 &point, const Plane &plane); + struct Frustum { Plane plane[6]; Plane &Left() noexcept { return plane[0]; } @@ -154,6 +162,31 @@ std::ostream &operator <<(std::ostream &, const Frustum &); bool CullTest(const AABB &box, const glm::mat4 &) noexcept; bool CullTest(const AABB &box, const Frustum &) noexcept; +struct Sphere { + glm::vec3 origin; + float radius; +}; + +std::ostream &operator <<(std::ostream &, const Sphere &); + +/// 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. +bool Intersection( + const Sphere &sphere, + const Plane &plane, + float &dist, + glm::vec3 &norm) noexcept; + +/// Test for intersection of sphere with half space defined by the +/// backface of given plane. +/// In all cases, dist will hold the distance between the near points +/// of plane and sphere. Contact normal will always be the plane's normal. +bool Intersection( + const Sphere &sphere, + const Plane &plane, + float &dist) noexcept; + } }