00001 #ifndef GLOBAL_FORCE_OPERATOR 00002 #define GLOBAL_FORCE_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/GlobalOperator.h> 00009 00010 namespace ani 00011 { 00015 template<class __EntityType> 00016 class GlobalForceOperator : public GlobalOperator<__EntityType> 00017 { 00018 public: 00019 GlobalForceOperator(){} 00020 GlobalForceOperator( float x, float y, float z ) : mForce( x, y, z ) {} 00021 virtual ~GlobalForceOperator(){} 00022 void setForce( const gmtl::Vec3f& force ) { mForce = force; } 00023 00024 //: apply this force function to the particle 00025 virtual void exec( DynamicSystem<__EntityType>& ps, float timeDelta ); 00026 00027 private: 00028 gmtl::Vec3f mForce; 00029 }; 00030 00032 template< class __EntityType > 00033 void GlobalForceOperator<__EntityType>::exec( ani::DynamicSystem<__EntityType>& ps, float timeDelta ) 00034 { 00035 std::vector<EntityTypePtr>::iterator it; 00036 for ( it = ps.entities().begin(); it != ps.entities().end(); ++it) 00037 { 00038 EntityTypePtr p = *it; 00039 if (this->isIgnored(p) == false) 00040 { 00041 p->applyForce( mForce ); 00042 } 00043 } 00044 } 00045 } // end of namespace 00046 00047 #endif