Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_SPHERE_SPHERE_HANDLER_H
00002 #define OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_SPHERE_SPHERE_HANDLER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/collision/collision_sphere_sphere.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace mbd
00017 {
00018 namespace collision_detection
00019 {
00020 template<typename mbd_types>
00021 struct SphereSphereHandler
00022 {
00023 typedef typename mbd_types::math_policy math_policy;
00024
00025 typedef typename math_policy::real_type real_type;
00026 typedef typename math_policy::vector3_type vector3_type;
00027 typedef typename math_policy::quaternion_type quaternion_type;
00028 typedef typename math_policy::coordsys_type coordsys_type;
00029
00030 typedef typename mbd_types::body_type body_type;
00031 typedef typename mbd_types::material_type material_type;
00032 typedef typename mbd_types::contact_container contact_container;
00033 typedef typename mbd_types::contact_type contact_type;
00034 typedef typename mbd_types::node_traits node_traits;
00035
00036 typedef OpenTissue::geometry::Sphere<math_policy> sphere_type;
00037
00038 typedef typename mbd_types::collision_info_type collision_info_type;
00039
00040 static bool test(
00041 sphere_type & sphereA
00042 , sphere_type & sphereB
00043 , collision_info_type & info
00044 )
00045 {
00046 coordsys_type BtoWCS;
00047 coordsys_type AtoWCS;
00048 vector3_type r_a;
00049 vector3_type r_b;
00050 quaternion_type Q_a;
00051 quaternion_type Q_b;
00052 info.get_body_A()->get_position( r_a );
00053 info.get_body_A()->get_orientation( Q_a );
00054 info.get_body_B()->get_position( r_b );
00055 info.get_body_B()->get_orientation( Q_b );
00056 BtoWCS = coordsys_type( r_b, Q_b );
00057 AtoWCS = coordsys_type( r_a, Q_a );
00058
00059 vector3_type p,n;
00060 real_type distance;
00061
00062 info.get_contacts()->clear();
00063
00064 if( OpenTissue::collision::sphere_sphere(AtoWCS.T(),sphereA.radius(),BtoWCS.T(),sphereB.radius(), info.get_envelope() ,p,n,distance) )
00065 {
00066 contact_type contact;
00067 contact.init( info.get_body_A(), info.get_body_B(), p, n, distance, info.get_material() );
00068 info.get_contacts()->push_back(contact);
00069 return (distance < -info.get_envelope() );
00070 }
00071 return false;
00072 }
00073 };
00074
00075 }
00076 }
00077 }
00078
00079
00080 #endif