Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_SPHERE_BOX_HANDLER_H
00002 #define OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_SPHERE_BOX_HANDLER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/collision/collision_box_sphere.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace mbd
00017 {
00018 namespace collision_detection
00019 {
00020 template<typename mbd_types>
00021 struct SphereBoxHandler
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 typedef OpenTissue::geometry::OBB<math_policy> box_type;
00038
00039 typedef typename mbd_types::collision_info_type collision_info_type;
00040
00041
00042 static bool test(
00043 sphere_type & sphere
00044 , box_type & box
00045 , collision_info_type & info
00046 )
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
00067 if(OpenTissue::collision::box_sphere(BtoWCS,AtoWCS,box,sphere,info.get_envelope(),p,n,distance) )
00068 {
00069 contact_type contact;
00070 contact.init( info.get_body_B(), info.get_body_A(), p, n, distance, info.get_material() );
00071 info.get_contacts()->push_back(contact);
00072 return ( distance < -info.get_envelope() );
00073 }
00074 return false;
00075 }
00076
00077
00078 static bool mirrowed_test(
00079 box_type & box
00080 , sphere_type & sphere
00081 , collision_info_type & info
00082 )
00083 {
00084 info.flip_bodies();
00085 return test( sphere, box, info);
00086 }
00087
00088 };
00089
00090
00091 }
00092 }
00093 }
00094
00095
00096 #endif