X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FPlane.hh;h=248a3128161afe0cadbdde10fa781d6b3e89c405;hp=797edc05c39fe13283c4a52088502fcb6e2f132c;hb=72d4af22710317acffab861421c4364b1780b6fe;hpb=493ddb59a8620b49dfa0ff62ce93395ebfd02e86 diff --git a/src/Moof/Plane.hh b/src/Moof/Plane.hh index 797edc0..248a312 100644 --- a/src/Moof/Plane.hh +++ b/src/Moof/Plane.hh @@ -35,11 +35,55 @@ namespace Mf { -class Plane +class Aabb; +class Sphere; + + +struct Plane { - Vector4 components; + Vector3 normal; + Scalar d; + + typedef enum + { + NEGATIVE = -1, + INTERSECT = 0, + POSITIVE = 1 + } Halfspace; + + Plane() {} + Plane(const Vector3& vector, Scalar scalar) : + normal(vector), + d(scalar) {} + Plane(Scalar a, Scalar b, Scalar c, Scalar scalar) : + normal(a, b, c), + d(scalar) {} + + + void normalize() + { + Scalar mag = normal.length(); + + normal /= mag; + d /= mag; + } + + inline Scalar getDistanceToPoint(const Vector3& point) const + { + return cml::dot(point, normal) + d; + } + + inline Halfspace intersectsPoint(const Vector3& point) const + { + Scalar distance = getDistanceToPoint(point); + + if (isEqual(distance, 0.0)) return INTERSECT; + else if (distance < 0.0) return NEGATIVE; + else return POSITIVE; + } -public: + Halfspace intersectsAabb(const Aabb& aabb) const; + Halfspace intersectsSphere(const Sphere& sphere) const; };