00001 #ifndef ACCELERATION_OPERATOR 00002 #define ACCELERATION_OPERATOR 00003 00004 #include <boost/smart_ptr.hpp> 00005 #include <gmtl/Vec.h> 00006 #include "ani/Dynamics/Operator.h" 00007 #include "ani/Dynamics/DynamicSystem.h" 00008 #include "ani/Dynamics/operators/GlobalForceOperator.h" 00009 00010 namespace ani 00011 { 00016 template<class __EntityType> 00017 class AccelerationOperator : public GlobalForceOperator<__EntityType> 00018 { 00019 public: 00020 AccelerationOperator() {} 00021 AccelerationOperator( float x, float y, float z ) : mAcceleration( x, y, z ) 00022 { 00023 } 00024 00025 virtual ~AccelerationOperator() 00026 { 00027 } 00028 00029 void setAcceleration( const gmtl::Vec3f& acceleration ) 00030 { 00031 mAcceleration = acceleration; 00032 } 00033 00034 const gmtl::Vec3f& getAcceleration() const { return mAcceleration; } 00035 00036 //: apply this force function to the particle 00037 virtual void exec( DynamicSystem<__EntityType>& ps, float timeDelta ); 00038 00039 private: 00040 gmtl::Vec3f mAcceleration; 00041 }; 00042 00043 //: apply this force function to the particle 00044 template< class __EntityType > 00045 void AccelerationOperator<__EntityType>::exec( ani::DynamicSystem<__EntityType>& ps, float timeDelta ) 00046 { 00047 std::vector<EntityTypePtr>::iterator it; 00048 for ( it = ps.entities().begin(); it != ps.entities().end(); ++it) 00049 { 00050 EntityTypePtr p = *it; 00051 if (this->isIgnored( p ) == false) 00052 { 00053 // meters 00054 // Force = kilograms * ------ = kilograms * acceleration 00055 // sec^2 00056 00057 // calculate how much force it will take to accelerate the particle 00058 gmtl::Vec3f force = mAcceleration * p->mass(); 00059 p->applyForce( force ); 00060 //cout<<"Applied force "<<force[0]<<" "<<force[1]<<" "<<force[2]<<"\n"<<flush; 00061 } 00062 } 00063 } 00064 00065 } // end of namespace 00066 00067 #endif