X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FPlane.hh;h=06e4abdce63f59398f961a531942d7b63ec667ea;hp=797edc05c39fe13283c4a52088502fcb6e2f132c;hb=7e898e8ec0ff716e2fc722b883a626a6c346f107;hpb=29e3d45f7bbbf31eadf793c41ff2b3d9c47b7539 diff --git a/src/Moof/Plane.hh b/src/Moof/Plane.hh index 797edc0..06e4abd 100644 --- a/src/Moof/Plane.hh +++ b/src/Moof/Plane.hh @@ -35,11 +35,65 @@ namespace Mf { -class Plane +class Aabb; +class Sphere; + + +/* + * A plane in 3-space defined by the equation Ax + By + Cz = D, where [A, B, C] + * is normal to the plane. + */ + +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) {} + + + /* Causes the normal of the plane to become normalized. The scalar may also + * be changed to keep the equation true. */ + void normalize() + { + Scalar mag = normal.length(); + + normal /= mag; + d /= mag; + } + + /** + * Determine the shortest distance between a point and the plane. */ + + Scalar getDistanceToPoint(const Vector3& point) const + { + return cml::dot(point, normal) + d; + } + + Halfspace intersects(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 intersects(const Aabb& aabb) const; + Halfspace intersects(const Sphere& sphere) const; };