00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_FORCES_MBD_GRAVITY_H 00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_FORCES_MBD_GRAVITY_H 00003 // 00004 // OpenTissue, A toolbox for physical based simulation and animation. 00005 // Copyright (C) 2007 Department of Computer Science, University of Copenhagen 00006 // 00007 #include <OpenTissue/configuration.h> 00008 00009 #include <OpenTissue/dynamics/mbd/interfaces/mbd_force_interface.h> 00010 00011 namespace OpenTissue 00012 { 00013 namespace mbd 00014 { 00015 00016 template<typename mbd_types> 00017 class Gravity 00018 : public ForceInterface<mbd_types> 00019 { 00020 public: 00021 00022 typedef typename mbd_types::body_type body_type; 00023 typedef typename mbd_types::math_policy::vector3_type vector3_type; 00024 00025 protected: 00026 00027 vector3_type m_acceleration; 00028 00029 public: 00030 00031 Gravity() 00032 : m_acceleration(0,-9.81,0) 00033 {} 00034 00035 virtual ~Gravity(){} 00036 00037 public: 00038 00039 void compute(body_type const & body,vector3_type & force,vector3_type & torque) 00040 { 00041 if(body.is_fixed()) 00042 force.clear(); 00043 else 00044 { 00045 force = m_acceleration * body.get_mass(); 00046 } 00047 torque.clear(); 00048 } 00049 00050 void set_acceleration(vector3_type const & acceleration) { this->m_acceleration = acceleration; } 00051 00052 }; 00053 00054 } // namespace mbd 00055 } // namespace OpenTissue 00056 // OPENTISSUE_DYNAMICS_MBD_UTIL_FORCES_MBD_GRAVITY_H 00057 #endif