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/TireForceOperator.h

Go to the documentation of this file.
00001 #ifndef TIRE_FORCE_OPERATOR
00002 #define TIRE_FORCE_OPERATOR
00003 #include <vector>
00004 #include <ani/Dynamics/Operator.h>
00005 #include <ani/Dynamics/DynamicSystem.h>
00006 #include <gator/Collision.h>
00007 #include <gator/PlaneCollisionDetector.h>
00008 
00009 namespace gator
00010 {
00023    class TireForceOperator : public ani::Operator<ani::Body>
00024    {
00025    public:
00026       typedef boost::shared_ptr<ani::Body> EntityTypePtr;
00027 
00028    public:
00030       TireForceOperator( EntityTypePtr& e ) :
00031          ani::Operator<ani::Body>(),
00032          mUseTangentialForceAlways( false ), 
00033          mEnt( e )
00034       {
00035       }
00036 
00038       virtual ~TireForceOperator() 
00039       {
00040       }
00041 
00047       void setAirSteering( bool state )
00048       {
00049          mUseTangentialForceAlways = state;
00050       }   
00051 
00053       virtual void exec( ani::DynamicSystem<ani::Body>& ps, float timeDelta )
00054       {
00055          ani::Body& p = *mEnt;
00056          
00057          // replace this with a more generic polygon intersection
00058          gmtl::Vec3f polygonNormal;
00059          float dist = 0;
00060          bool collision_happened = mCollisionDetector->exec( p, dist, polygonNormal );
00061 
00062          // handle collision         
00063          // compute tangential forces (force from tires to keep car on the road while turning)
00064          if (collision_happened || mUseTangentialForceAlways)
00065          {         
00066             gmtl::Vec3f frictionForce, normalForce;
00067             gmtl::Matrix44f mat;
00068             gmtl::set( mat, p.rotation() );
00069             gmtl::Vec3f side_vec(1,0,0);
00070             side_vec = mat * side_vec;
00071 
00072             computeCollisionForces( side_vec, p.linearVelocity(), 0.1, 0, p.mass(), timeDelta, frictionForce, normalForce );
00073             p.applyForce( normalForce );
00074             p.applyForce( frictionForce );
00075             //std::cout<<normalForce<<" : "<<frictionForce<<"\n"<<std::flush;
00076 //            std::cout<<"collide force: "<<normalForce + frictionForce<<"\n"<<std::flush;
00077          }
00078       }
00079 
00084       virtual void setCollisionDetector( CollisionDetectorPtr detect )
00085       {
00086          mCollisionDetector = detect;
00087       }
00088 
00089    private:
00090       bool mUseTangentialForceAlways; // true == steer in the air
00091       EntityTypePtr mEnt;
00092       CollisionDetectorPtr mCollisionDetector;
00093    };
00094 } // end namespace gator
00095 
00096 #endif

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