Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

c:/home/kevn/src/animaniac/gator/PlaneCollisionDetector.h

Go to the documentation of this file.
00001 #ifndef PLANE_COLLISION_DETECTOR
00002 #define PLANE_COLLISION_DETECTOR
00003 
00004 #include <gator/CollisionDetector.h>
00005 #include <gmtl/Plane.h>
00006 #include <gmtl/PlaneOps.h>
00007 
00008 namespace gator
00009 {
00013    class PlaneCollisionDetector : public CollisionDetector
00014    {
00015    public:
00016       PlaneCollisionDetector() : 
00017          mPlane( gmtl::Vec3f( 0,1,0 ), gmtl::Point3f( 0,0,0 ) )
00018       {
00019       }
00020 
00023       void setPlane( gmtl::Planef& plane )
00024       {
00025          mPlane = plane;
00026       }
00027 
00028       virtual bool exec( const ani::Body& body, float& dist, gmtl::Vec3f& normal )
00029       {
00030          // attempt a cheezy box collision.  works for axis aligned planes.
00031          // to generalize, you'll want to extend to all the box points.
00032          dist = gmtl::Math::Min( 
00033                   gmtl::distance( mPlane, (gmtl::Point3f)(body.position() + body.volume()) ),
00034                   gmtl::distance( mPlane, (gmtl::Point3f)(body.position() - body.volume()) ) 
00035                );
00036          normal = mPlane.getNormal();
00037          gmtl::Vec3f vel_normalized = body.linearVelocity();
00038          gmtl::normalize( vel_normalized );
00039          
00040          // if under the plane, and only when traveling towards it
00041          if ( dist <= 0.0f && gmtl::dot( vel_normalized, normal ) < 0)
00042             return true;
00043          else
00044             return false;
00045       }
00046 
00047    private:
00048       gmtl::Planef mPlane;
00049    };
00050 } // end namespace gator
00051 
00052 #endif

Generated on Wed Jun 12 01:54:03 2002 for Animaniac by doxygen1.2.15