]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Sphere.hh
removed logging from script to fix compile error
[chaz/yoink] / src / Moof / Sphere.hh
index d42bfd8a98fa8e643494c7b242f8e659c1893da9..f5285545b17a3faa66ba3f4fdd0a250b1bf50a99 100644 (file)
@@ -12,6 +12,7 @@
 #ifndef _MOOF_SPHERE_HH_
 #define _MOOF_SPHERE_HH_
 
+#include <Moof/Contact.hh>
 #include <Moof/Cullable.hh>
 #include <Moof/Drawable.hh>
 #include <Moof/Frustum.hh>
@@ -28,24 +29,22 @@ namespace Mf {
  * A round object.
  */
 
+
 template <int D = 3>
 struct Sphere : public Cullable, public Drawable, public Shape<D>
 {
        typedef cml::vector< Scalar, cml::fixed<D> >    Vector;
 
-       // (solution - point)^2 - radius^2 = 0
        Vector  point;
        Scalar  radius;
 
+
        Sphere() {}
 
        Sphere(const Vector& p, Scalar r) :
                point(p),
                radius(r) {}
 
-       //Sphere(Scalar x, Scalar y, Scalar z, Scalar r) :
-               //point(x, y, z),
-               //radius(r) {}
 
        void init(const Vector& p, Scalar r)
        {
@@ -59,9 +58,55 @@ struct Sphere : public Cullable, public Drawable, public Shape<D>
                radius = (o - p).length();
        }
 
+       //void encloseVertices(const Vector vertices[], unsigned count);
+
+       //void draw(Scalar alpha = 0.0) const;
+       //bool isVisible(const Frustum& frustum) const;
+
+       void encloseVertices(const Vector vertices[], unsigned count)
+       {
+               // TODO
+       }
+
+       void draw(Scalar alpha = 0.0) const;
+
+       bool isVisible(const Frustum& frustum) const
+       {
+               return true;
+       }
+
+
+       bool intersect(const Sphere<D>& sphere, Contact<D>& hit) const
+       {
+               Vector n = sphere.point - point;
+               Scalar distance = n.length();
+               Scalar limit = radius + sphere.radius;
+
+               if (distance > limit) return false;
+
+               hit.normal = n.normalize();
+               hit.distance = limit - distance;
+               hit.point = hit.normal * radius;
+
+               return true;
+       }
+
+       bool intersect(const Vector& point2, Contact<D>& hit) const
+       {
+               Vector n = point2 - point;
+               Scalar distance = n.length();
+
+               if (distance > radius) return false;
+
+               hit.normal = n.normalize();
+               hit.distance = radius - distance;
+               hit.point = point2;
+
+               return true;
+       }
 
        // a ray inside the sphere will not intersect on its way out
-       bool intersectRay(const Ray<D>& ray, typename Ray<D>::Contact& hit)
+       bool intersect(const Ray<D>& ray, typename Ray<D>::Contact& hit) const
        {
                Vector b = point - ray.point;
                Scalar z = cml::dot(b, ray.direction);
@@ -83,37 +128,6 @@ struct Sphere : public Cullable, public Drawable, public Shape<D>
                hit.normal = surfacePoint - point;
                return true;
        }
-
-
-       //void encloseVertices(const Vector vertices[], unsigned count);
-
-       //void draw(Scalar alpha = 0.0) const;
-       //bool isVisible(const Frustum& frustum) const;
-
-       void encloseVertices(const Vector vertices[], unsigned count)
-       {
-               // TODO
-       }
-
-       void draw(Scalar alpha = 0.0) const;
-       //{
-               //GLUquadricObj* sphereObj = gluNewQuadric();
-               //gluQuadricDrawStyle(sphereObj, GLU_LINE);
-
-               //glPushMatrix();
-
-               //glTranslate(point);
-               //gluSphere(sphereObj, GLdouble(radius), 16, 16);
-
-               //glPopMatrix();
-
-               //gluDeleteQuadric(sphereObj);
-       //}
-
-       bool isVisible(const Frustum& frustum) const
-       {
-               return true;
-       }
 };
 
 
This page took 0.020616 seconds and 4 git commands to generate.