Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_BOX_PLANE_HANDLER_H
00002 #define OPENTISSUE_DYNAMICS_MBD_COLLISION_DETECTION_COLLISION_HANDLERS_MBD_BOX_PLANE_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/core/geometry/geometry_plane.h>
00014
00015 #include <OpenTissue/collision/collision_plane_box.h>
00016
00017 namespace OpenTissue
00018 {
00019 namespace mbd
00020 {
00021 namespace collision_detection
00022 {
00023
00024 template<typename mbd_types>
00025 struct BoxPlaneHandler
00026 {
00027 typedef typename mbd_types::math_policy math_policy;
00028 typedef typename math_policy::index_type size_type;
00029 typedef typename math_policy::real_type real_type;
00030 typedef typename math_policy::vector3_type vector3_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::Plane<math_policy> plane_type;
00041 typedef OpenTissue::geometry::OBB<math_policy> box_type;
00042
00043 typedef typename mbd_types::collision_info_type collision_info_type;
00044
00045 static bool test(
00046 box_type & box
00047 , plane_type & plane
00048 , collision_info_type & info
00049 )
00050 {
00051 coordsys_type BtoWCS;
00052 coordsys_type AtoWCS;
00053 vector3_type r_a;
00054 vector3_type r_b;
00055 quaternion_type Q_a;
00056 quaternion_type Q_b;
00057 info.get_body_A()->get_position( r_a );
00058 info.get_body_A()->get_orientation( Q_a );
00059 info.get_body_B()->get_position( r_b );
00060 info.get_body_B()->get_orientation( Q_b );
00061 BtoWCS = coordsys_type( r_b, Q_b );
00062 AtoWCS = coordsys_type( r_a, Q_a );
00063
00064 vector3_type p[4],n;
00065 real_type distance[4];
00066
00067 size_t cnt = OpenTissue::collision::plane_box(BtoWCS,AtoWCS,plane,box,info.get_envelope(),p,n,distance);
00068
00069 info.get_contacts()->clear();
00070 if(cnt>0)
00071 {
00072 for(size_t i=0;i<cnt;++i)
00073 {
00074 contact_type contact;
00075 contact.init( info.get_body_B(), info.get_body_A(), p[i], n, distance[i], info.get_material() );
00076 info.get_contacts()->push_back(contact);
00077 }
00078 return ( distance[0] < -info.get_envelope() );
00079 }
00080 return false;
00081 }
00082
00083 static bool mirrowed_test(
00084 plane_type & plane
00085 , box_type & box
00086 , collision_info_type & info
00087 )
00088 {
00089 info.flip_bodies();
00090 return test(box,plane, info );
00091 }
00092
00093 };
00094
00095 }
00096 }
00097 }
00098
00099
00100 #endif