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

Go to the documentation of this file.
00001 #ifndef ACCEL_OPER
00002 #define ACCEL_OPER
00003 #include <vector>
00004 #include "ani/Dynamics/Operator.h"
00005 #include "ani/Dynamics/DynamicSystem.h"
00006 
00007 namespace gator
00008 {
00009    //: FORCE by Acceleration
00010    //  specify an acceleration, will compute the force for each particle to accelerate it that fast
00011    class Acceleration : public ani::Operator<ani::Body>
00012    {
00013    public:
00014       typedef boost::shared_ptr<ani::Body> EntityTypePtr;
00015 
00016    public:
00017       Acceleration() : ani::Operator<ani::Body>()
00018       {
00019       }
00020 
00021       Acceleration( float x, float y, float z ) : ani::Operator<ani::Body>(), mAcceleration( x, y, z )
00022       {
00023       }
00024 
00025       virtual ~Acceleration()
00026       {
00027       }
00028 
00029       void setAcceleration( const gmtl::Vec3f& acceleration )
00030       {
00031          mAcceleration = acceleration;
00032       }
00033 
00034       //: apply this force function to the particle
00035       virtual void exec( ani::DynamicSystem<ani::Body>& ps, float timeDelta )
00036       {
00037          std::vector<EntityTypePtr>& entities = ps.entities();
00038          std::vector<EntityTypePtr>::iterator it;
00039          for ( it = entities.begin(); it != entities.end(); ++it)
00040          {
00041             ani::Body& p = *(*it);
00042             //                     meters
00043             // Force = kilograms * ------ = kilograms * acceleration
00044             //                     sec^2
00045 
00046             // calculate how much force it will take to accelerate the particle
00047             gmtl::Vec3f force = mAcceleration * p.mass();
00048             p.applyForce( force );
00049          }
00050       }
00051 
00052    private:
00053       gmtl::Vec3f mAcceleration;
00054    };
00055 } // end namespace gator
00056 
00057 #endif

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