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
00031
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
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 }
00051
00052 #endif