X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FSphere.hh;h=319a3ae24a32b5a36b5d130134fc5bfca5e915aa;hp=b20ca741748f076e648328593ffd8484be57367a;hb=c9e20ac06383b20ceb5404c9237e319c2e90d157;hpb=72d4af22710317acffab861421c4364b1780b6fe diff --git a/src/Moof/Sphere.hh b/src/Moof/Sphere.hh index b20ca74..319a3ae 100644 --- a/src/Moof/Sphere.hh +++ b/src/Moof/Sphere.hh @@ -38,7 +38,7 @@ namespace Mf { /** - * Axis-aligned Bounding Box + * A round object. */ struct Sphere : public Cullable, public Drawable @@ -56,19 +56,32 @@ struct Sphere : public Cullable, public Drawable point(x, y, z), radius(r) {} - inline void init(const Vector3& p, Scalar r) + void init(const Vector3& p, Scalar r) { point = p; radius = r; } + void init(const Vector3& p, const Vector3& o) + { + point = p; + radius = (o - p).length(); + } + void encloseVertices(const Vector3 vertices[], unsigned count); void draw(Scalar alpha = 0.0) const; - bool isVisible(const Camera& cam) const; + bool isVisible(const Frustum& frustum) const; }; +inline bool checkCollision(const Sphere& a, const Sphere& b) +{ + Scalar d = (a.point - b.point).length(); + return d < (a.radius + b.radius); +} + + } // namespace Mf #endif // _MOOF_SPHERE_HH_