Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_APPLY_IMPULSE_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_APPLY_IMPULSE_H
00003
00004
00005
00006
00007 #include <OpenTissue/configuration.h>
00008
00009 namespace OpenTissue
00010 {
00011 namespace mbd
00012 {
00013
00021 template<typename body_type>
00022 void apply_impulse(body_type * body, typename body_type::vector3_type const & r, typename body_type::vector3_type const & J)
00023 {
00024 typedef typename body_type::real_type real_type;
00025 typedef typename body_type::vector3_type vector3_type;
00026 typedef typename body_type::matrix3x3_type matrix3x3_type;
00027
00028 vector3_type v,w,dw;
00029 real_type inv_m = body->get_inverse_mass();
00030 body->get_velocity(v);
00031 v += J*inv_m;
00032 body->set_velocity(v);
00033
00034 dw = cross(r , J);
00035 body->get_spin(w);
00036 matrix3x3_type invI;
00037 body->get_inverse_inertia_wcs(invI);
00038 w += invI*dw;
00039 body->set_spin(w);
00040 }
00041
00042 }
00043 }
00044 #endif // OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_APPLY_IMPULSE_H