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
00010
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
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
00043
00044
00045
00046
00047 gmtl::Vec3f force = mAcceleration * p.mass();
00048 p.applyForce( force );
00049 }
00050 }
00051
00052 private:
00053 gmtl::Vec3f mAcceleration;
00054 };
00055 }
00056
00057 #endif