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

Go to the documentation of this file.
00001 #ifndef CAR_METHOD
00002 #define CAR_DRIVE_METHOD
00003 
00004 #include <gator/TravelMethod.h>
00005 #include "ani/Dynamics/Body.h"
00006 #include "ani/Dynamics/Operator.h"
00007 #include "ani/Dynamics/solvers/EulerODEsolver.h"
00008 #include "ani/Dynamics/solvers/RungeKuttaODEsolver.h"
00009 #include "ani/Dynamics/DynamicSystem.h"
00010 
00011 #include "gator/TireForceOperator.h"
00012 #include "gator/AccelerateOperator.h"
00013 #include "gator/GravityOperator.h"
00014 #include "gator/DriveOperator.h"
00015 #include "gator/CollisionResponseOperator.h"
00016 #include "gator/TetherOperator.h"
00017 #include "gator/GlueOperator.h"
00018 
00019 namespace gator
00020 {
00024    class Car4WheelsMethod : public TravelMethod
00025    {
00026    public:
00027       Car4WheelsMethod() : TravelMethod(),
00028         mTireForce( new TireForceOperator(mAvatar) ),
00029         mNavigator( new DriveNavigationOperator(mAvatar) ),
00030         mCollider( new CollisionResponseOperator )
00031       {
00032          // @todo should use 4 wheels not 1...  
00033          mAvatar->setVolume( gmtl::Vec3f( 0.25,0.5,0.5 ) );
00034          ani::BodyPtr mWheel1( new ani::Body );
00035          mWheel1->setMass( 100 );
00036          mWheel1->setVolume( gmtl::Vec3f( 1,1,1 ) );
00037          GlueOperator* bok;
00038          boost::shared_ptr<ani::Operator<ani::Body> > gravity( new Acceleration( 0,-9.8f * 4.0f, 0 ) );
00039          boost::shared_ptr<ani::Operator<ani::Body> > tether( new TetherOperator( mCamera, mAvatar ) );
00040          boost::shared_ptr<ani::Operator<ani::Body> > glue( bok=new
00041          GlueOperator( 
00042                        mWheel1, gmtl::Vec3f( 0,0,0 ), 
00043                        mAvatar, gmtl::Vec3f( 0, -1, 0 ) 
00044          ));
00045 
00046                   // Pounds to Kilograms, multiply Pounds by 0.45
00047          // Kilograms to Pounds, multiply Kilograms by 2.2
00048          //mAvatar->setMass( 170.0f * 0.45f );
00049          mAvatar->setMass( 100.0f );
00050          mAvatar->setPosition( gmtl::Vec3f( 0, 20, -20 ));
00051          mCollider->setElastic( 0.2f );
00052          mTireForce->setCollisionDetector( mCollisionDetector );
00053          mCollider->setCollisionDetector( mCollisionDetector );
00054          
00055          this->push_back( gravity );
00056          this->push_back( boost::shared_dynamic_cast<ani::Operator<ani::Body> >( mNavigator ) );
00057 
00058          // goes last
00059          this->push_back( boost::shared_dynamic_cast<ani::Operator<ani::Body> >( mCollider ) );
00060          this->push_back( boost::shared_dynamic_cast<ani::Operator<ani::Body> >( mTireForce ) );
00061          this->push_back( tether );
00062          this->push_back( mAvatar );
00063          this->push_back( mCamera );
00064 
00065          this->push_back( mWheel1 );
00066          this->push_back( glue );
00067       }
00068 
00070       virtual void digitalInput( unsigned int id, EdgeState value )
00071       {
00072          float t = 1.0f;
00073 
00074          switch (id)
00075          {
00076          case 0: // accel
00077             if (value == DOWN)
00078             {
00079                gmtl::Matrix44f pointerMat;
00080                gmtl::Vec3f dir;
00081                dir = pointerMat * gmtl::Vec3f( 0.0f, 0.0f, -3000.0f );
00082                //std::cout<<"accel "<<dir<<"\n"<<std::flush;
00083 
00084                mNavigator->force( dir );
00085             }
00086             else if (value== EDGE_DOWN)
00087             {
00088                gmtl::Matrix44f pointerMat;
00089                gmtl::Vec3f dir;
00090                dir = pointerMat * gmtl::Vec3f( 0.0f, 0.0f, -6000.0f );
00091                mNavigator->force( dir );
00092             }
00093             break;
00094          case 1: // stop
00095             if (value == DOWN)
00096                mNavigator->stop();
00097             break;
00098          case 2: // turn left
00099             if (value == DOWN)
00100             {
00101                gmtl::Vec3f q;
00102                q.set( 0.0f, t, 0.0f );
00103                mNavigator->torque( q );
00104             }
00105             break;
00106          case 3: // turn right
00107             if (value == DOWN)
00108             {
00109                gmtl::Vec3f q;
00110                q.set( 0.0f, -t, 0.0f );
00111                mNavigator->torque( q );
00112             }
00113             break;
00114          case 4: // jump
00115             {
00116                gmtl::Vec3f accel( 0, 25, 0 );
00117                if (value == EDGE_DOWN)
00118                   mNavigator->impulseForce( accel * mAvatar->mass() );
00119                break;
00120             }
00121          default: break;
00122          }
00123       }
00124 
00126       virtual void analogInput( unsigned int id, float value )
00127       {
00128          switch (id)
00129          {
00130          case 0: // turn left or right.
00131             gmtl::Vec3f q;
00132             q.set( 0.0f, value, 0.0f );
00133             mNavigator->torque( q );
00134             break;
00135          }
00136       }
00137 
00139       virtual void xformInput( unsigned int id, const gmtl::Matrix44f& value ) {}
00140 
00145       virtual void setCollisionDetector( CollisionDetectorPtr& detect )
00146       {
00147          TravelMethod::setCollisionDetector( detect );
00148          mTireForce->setCollisionDetector( detect );
00149          mCollider->setCollisionDetector( detect );
00150       }
00151       
00152    protected:
00153       // physics system
00154       boost::shared_ptr< TireForceOperator >         mTireForce;
00155       boost::shared_ptr< DriveNavigationOperator >   mNavigator;
00156       boost::shared_ptr< CollisionResponseOperator > mCollider;
00157    };
00158 } // end namespace gator
00159 
00160 #endif

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