00001 #ifndef OPENTISSUE_DYNAMICS_PSYS_FORCE_PSYS_GRAVITY_H 00002 #define OPENTISSUE_DYNAMICS_PSYS_FORCE_PSYS_GRAVITY_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 namespace OpenTissue 00013 { 00014 namespace psys 00015 { 00016 00017 00018 template<typename types> 00019 class Gravity 00020 : public types::force_type 00021 { 00022 public: 00023 00024 typedef typename types::math_types math_types; 00025 typedef typename math_types::real_type real_type; 00026 typedef typename math_types::vector3_type vector3_type; 00027 typedef typename types::system_type system_type; 00028 00029 protected: 00030 00031 real_type m_gravity; 00032 00033 public: 00034 00035 real_type & gravity() { return m_gravity; } 00036 real_type const & gravity() const { return m_gravity; } 00037 00038 public: 00039 00040 Gravity() 00041 : m_gravity(9.81) 00042 {} 00043 00044 ~Gravity(){} 00045 00046 public: 00047 00048 void apply() 00049 { 00050 typedef typename system_type::particle_iterator particle_iterator; 00051 using std::fabs; 00052 00053 if(!(fabs(m_gravity) > 0)) 00054 return; 00055 00056 particle_iterator p = this->owner()->particle_begin(); 00057 particle_iterator end = this->owner()->particle_end(); 00058 00059 for(;p!=end;++p) 00060 { 00061 if( p->inv_mass() <= 0 ) 00062 continue; 00063 p->force() += vector3_type(0,0, -m_gravity*p->mass()); 00064 } 00065 } 00066 00067 }; 00068 00069 } // namespace psys 00070 } // namespace OpenTissue 00071 00072 // OPENTISSUE_DYNAMICS_PSYS_FORCE_PSYS_GRAVITY_H 00073 #endif