Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_SPHERE_PLANE_HANDLER_H
00002 #define OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_SPHERE_PLANE_HANDLER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/collision/collision_sphere_plane.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace mbd
00017 {
00018 namespace collision_detection
00019 {
00020 template<typename mbd_types>
00021 struct SpherePlaneHandler
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
00037 typedef OpenTissue::geometry::Sphere<math_policy> sphere_type;
00038 typedef OpenTissue::geometry::Plane<math_policy> plane_type;
00039
00040 typedef typename mbd_types::collision_info_type collision_info_type;
00041
00042
00043 static bool test(
00044 sphere_type & sphere
00045 , plane_type & plane
00046 , collision_info_type & info
00047 )
00048 {
00049 coordsys_type BtoWCS;
00050 coordsys_type AtoWCS;
00051 vector3_type r_a;
00052 vector3_type r_b;
00053 quaternion_type Q_a;
00054 quaternion_type Q_b;
00055 info.get_body_A()->get_position( r_a );
00056 info.get_body_A()->get_orientation( Q_a );
00057 info.get_body_B()->get_position( r_b );
00058 info.get_body_B()->get_orientation( Q_b );
00059 BtoWCS = coordsys_type( r_b, Q_b );
00060 AtoWCS = coordsys_type( r_a, Q_a );
00061
00062 vector3_type p,n;
00063 real_type distance;
00064
00065 info.get_contacts()->clear();
00066 if(OpenTissue::collision::sphere_plane(AtoWCS,BtoWCS,sphere,plane,info.get_envelope(),p,n,distance))
00067 {
00068 contact_type contact;
00069 contact.init( info.get_body_B(), info.get_body_A(), p, n, distance, info.get_material() );
00070 info.get_contacts()->push_back(contact);
00071 return ( distance < -info.get_envelope() );
00072 }
00073 return false;
00074 }
00075
00076 static bool mirrowed_test(
00077 plane_type & plane
00078 , sphere_type & sphere
00079 , collision_info_type & info
00080 )
00081 {
00082 info.flip_bodies();
00083 return test( sphere, plane, info);
00084 }
00085
00086 };
00087
00088 }
00089 }
00090 }
00091
00092
00093 #endif