OPC_SphereAABBOverlap.h
Go to the documentation of this file.
00001 
00002 
00008 
00009 inline_ BOOL SphereCollider::SphereAABBOverlap(const Point& center, const Point& extents)
00010 { 
00011         // Stats
00012         mNbVolumeBVTests++;
00013 
00014         float d = 0.0f;
00015 
00016         //find the square of the distance
00017         //from the sphere to the box
00018 #ifdef OLDIES
00019         for(udword i=0;i<3;i++)
00020         {
00021                 float tmp = mCenter[i] - center[i];
00022                 float s = tmp + extents[i];
00023 
00024                 if(s<0.0f)      d += s*s;
00025                 else
00026                 {
00027                         s = tmp - extents[i];
00028                         if(s>0.0f)      d += s*s;
00029                 }
00030         }
00031 #endif
00032 
00033 //#ifdef NEW_TEST
00034 
00035 //      float tmp = mCenter.x - center.x;
00036 //      float s = tmp + extents.x;
00037 
00038         float tmp,s;
00039 
00040         tmp = mCenter.x - center.x;
00041         s = tmp + extents.x;
00042 
00043         if(s<0.0f)
00044         {
00045                 d += s*s;
00046                 if(d>mRadius2)  return FALSE;
00047         }
00048         else
00049         {
00050                 s = tmp - extents.x;
00051                 if(s>0.0f)
00052                 {
00053                         d += s*s;
00054                         if(d>mRadius2)  return FALSE;
00055                 }
00056         }
00057 
00058         tmp = mCenter.y - center.y;
00059         s = tmp + extents.y;
00060 
00061         if(s<0.0f)
00062         {
00063                 d += s*s;
00064                 if(d>mRadius2)  return FALSE;
00065         }
00066         else
00067         {
00068                 s = tmp - extents.y;
00069                 if(s>0.0f)
00070                 {
00071                         d += s*s;
00072                         if(d>mRadius2)  return FALSE;
00073                 }
00074         }
00075 
00076         tmp = mCenter.z - center.z;
00077         s = tmp + extents.z;
00078 
00079         if(s<0.0f)
00080         {
00081                 d += s*s;
00082                 if(d>mRadius2)  return FALSE;
00083         }
00084         else
00085         {
00086                 s = tmp - extents.z;
00087                 if(s>0.0f)
00088                 {
00089                         d += s*s;
00090                         if(d>mRadius2)  return FALSE;
00091                 }
00092         }
00093 //#endif
00094 
00095 #ifdef OLDIES
00096 //      Point Min = center - extents;
00097 //      Point Max = center + extents;
00098 
00099         float d = 0.0f;
00100 
00101         //find the square of the distance
00102         //from the sphere to the box
00103         for(udword i=0;i<3;i++)
00104         {
00105 float Min = center[i] - extents[i];
00106 
00107 //              if(mCenter[i]<Min[i])
00108                 if(mCenter[i]<Min)
00109                 {
00110 //                      float s = mCenter[i] - Min[i];
00111                         float s = mCenter[i] - Min;
00112                         d += s*s;
00113                 }
00114                 else
00115                 {
00116 float Max = center[i] + extents[i];
00117 
00118 //                      if(mCenter[i]>Max[i])
00119                         if(mCenter[i]>Max)
00120                         {
00121                                 float s = mCenter[i] - Max;
00122                                 d += s*s;
00123                         }
00124                 }
00125         }
00126 #endif
00127         return d <= mRadius2;
00128 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:56