Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_COLLISION_RAY_OBB_H
00002 #define OPENTISSUE_COLLISION_COLLISION_RAY_OBB_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace collision
00015 {
00016
00030 template<typename vector3_type>
00031 bool ray_obb(
00032 vector3_type const & p
00033 , vector3_type const & r
00034 , vector3_type const & c
00035 , vector3_type const & a0
00036 , vector3_type const & a1
00037 , vector3_type const & a2
00038 , vector3_type const & e
00039 )
00040 {
00041 using std::fabs;
00042
00043 assert(e(0) >=0 || !"obb was incorrect");
00044 assert(e(1) >=0 || !"obb was incorrect");
00045 assert(e(2) >=0 || !"obb was incorrect");
00046 assert(r(0)!=0 || r(1)!=0 || r(2)!=0 || !"ray vector was zero!");
00047
00048 vector3_type d = p - c;
00049
00050 if (fabs(a0*d) > e(0) && (a0*d)*(a0*r) >= 0) return false;
00051 if (fabs(a1*d) > e(1) && (a1*d)*(a1*r) >= 0) return false;
00052 if (fabs(a2*d) > e(2) && (a2*d)*(a2*r) >= 0) return false;
00053
00054
00055 vector3_type rXd = r % d;
00056 if (fabs(a0*rXd) > (e(1)*fabs(r*a2) + e(2)*fabs(r*a1) )) return false;
00057 if (fabs(a1*rXd) > (e(0)*fabs(r*a2) + e(2)*fabs(r*a0) )) return false;
00058 if (fabs(a2*rXd) > (e(0)*fabs(r*a1) + e(1)*fabs(r*a0) )) return false;
00059
00060 return true;
00061 }
00062
00063 template<typename vector3_type, typename obb_type>
00064 bool ray_obb(vector3_type const & p,vector3_type const & r, obb_type const & obb)
00065
00066 {
00067 return ray_obb(p,r,obb.center(),obb.orientation().column(0),obb.orientation().column(1),obb.orientation().column(2),obb.ext());
00068 }
00069
00070 template<typename ray_type, typename obb_type>
00071 bool ray_obb(ray_type const & ray, obb_type const & obb)
00072
00073 {
00074 return ray_obb(ray.p(),ray.r(),obb.center(),obb.orientation().column(0),obb.orientation().column(1),obb.orientation().column(2),obb.ext());
00075 }
00076
00077 }
00078 }
00079
00080
00081 #endif