00001 #ifndef CURRENT_OPERATOR 00002 #define CURRENT_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 { 00017 template<class __EntityType> 00018 class CurrentOperator : public GlobalForceOperator<__EntityType> 00019 { 00020 public: 00021 CurrentOperator() : mSpeed() 00022 { 00023 } 00024 00025 virtual ~CurrentOperator() 00026 { 00027 } 00028 00029 void setSpeed( const gmtl::Vec3f& speed ) 00030 { 00031 mSpeed = speed; 00032 } 00033 00034 //: apply this force function to the particle 00035 virtual void exec( DynamicSystem<__EntityType>& ps, float timeDelta ); 00036 00037 private: 00038 gmtl::Vec3f mSpeed; 00039 }; 00040 00041 //: apply this force function to the particle 00042 template< class __EntityType > 00043 void CurrentOperator<__EntityType>::exec( ani::DynamicSystem<__EntityType>& ps, float timeDelta ) 00044 { 00045 std::vector<EntityTypePtr>::iterator it; 00046 for ( it = ps.entities().begin(); it != ps.entities().end(); ++it) 00047 { 00048 EntityTypePtr p = *it; 00049 if (this->isIgnored( p ) == false) 00050 { 00051 // meters velocity 00052 // acceleration = ------ = -------- 00053 // sec^2 sec 00054 gmtl::Vec3f& acc = mSpeed; 00055 00056 // meters 00057 // Force = kilograms * ------ = kilograms * acceleration 00058 // sec^2 00059 00060 // calculate how much force it will take to accelerate the particle 00061 gmtl::Vec3f force = acc * p->mass(); 00062 p->applyForce( force ); 00063 } 00064 } 00065 } 00066 } // end of namespace 00067 00068 #endif