Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_BOX_BOX_HANDLER_H
00002 #define OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_BOX_BOX_HANDLER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/geometry/geometry_obb.h>
00013 #include <OpenTissue/collision/collision_box_box_improved.h>
00014
00015 namespace OpenTissue
00016 {
00017 namespace mbd
00018 {
00019 namespace collision_detection
00020 {
00021
00022 template<typename mbd_types>
00023 struct BoxBoxHandler
00024 {
00025 typedef typename mbd_types::collision_info_type collision_info_type;
00026 typedef typename mbd_types::math_policy math_policy;
00027 typedef typename math_policy::real_type real_type;
00028 typedef typename math_policy::index_type size_type;
00029 typedef typename math_policy::vector3_type vector3_type;
00030 typedef typename math_policy::matrix3x3_type matrix3x3_type;
00031 typedef typename math_policy::quaternion_type quaternion_type;
00032 typedef typename math_policy::coordsys_type coordsys_type;
00033
00034 typedef typename mbd_types::body_type body_type;
00035 typedef typename mbd_types::material_type material_type;
00036 typedef typename mbd_types::contact_container contact_container;
00037 typedef typename mbd_types::contact_type contact_type;
00038 typedef typename mbd_types::node_traits node_traits;
00039
00040 typedef OpenTissue::geometry::OBB<math_policy> box_type;
00041
00042 static bool test(
00043 box_type & boxA
00044 , box_type & boxB
00045 , collision_info_type & info
00046 )
00047 {
00048 coordsys_type BtoWCS;
00049 coordsys_type AtoWCS;
00050 vector3_type r_a;
00051 vector3_type r_b;
00052 quaternion_type Q_a;
00053 quaternion_type Q_b;
00054 info.get_body_A()->get_position( r_a );
00055 info.get_body_A()->get_orientation( Q_a );
00056 info.get_body_B()->get_position( r_b );
00057 info.get_body_B()->get_orientation( Q_b );
00058 BtoWCS = coordsys_type( r_b, Q_b );
00059 AtoWCS = coordsys_type( r_a, Q_a );
00060
00061 vector3_type p[16];
00062 vector3_type n;
00063 real_type distance[16];
00064
00065 matrix3x3_type RA(AtoWCS.Q());
00066 matrix3x3_type RB(BtoWCS.Q());
00067
00068 size_t cnt = OpenTissue::collision::box_box_improved(AtoWCS.T(),RA,boxA.ext(),BtoWCS.T(),RB,boxB.ext(),info.get_envelope(),p,n,distance);
00069
00070 info.get_contacts()->clear();
00071 if(cnt>0)
00072 {
00073 for(size_t i=0;i<cnt;++i)
00074 {
00075 contact_type contact;
00076 contact.init( info.get_body_A(), info.get_body_B(), p[i], n, distance[i], info.get_material() );
00077 info.get_contacts()->push_back(contact);
00078 }
00079 return ( distance[0] < -info.get_envelope() );
00080 }
00081 return false;
00082 }
00083
00084
00085 };
00086
00087
00088
00089
00090 }
00091 }
00092 }
00093
00094
00095 #endif