IceBoundingSphere.h
Go to the documentation of this file.
00001 
00002 
00008 
00009 
00011 // Include Guard
00012 #ifndef __ICEBOUNDINGSPHERE_H__
00013 #define __ICEBOUNDINGSPHERE_H__
00014 
00015         enum BSphereMethod
00016         {
00017                 BS_NONE,
00018                 BS_GEMS,
00019                 BS_MINIBALL,
00020 
00021                 BS_FORCE_DWORD  = 0x7fffffff
00022         };
00023 
00024         class ICEMATHS_API Sphere
00025         {
00026                 public:
00028                 inline_                                 Sphere()                                                                                                                                                {}
00030                 inline_                                 Sphere(const Point& center, float radius) : mCenter(center), mRadius(radius)    {}
00032                                                                 Sphere(udword nb_verts, const Point* verts);
00034                 inline_                                 Sphere(const Sphere& sphere) : mCenter(sphere.mCenter), mRadius(sphere.mRadius) {}
00036                 inline_                                 ~Sphere()                                                                                                                                               {}
00037 
00038                                 BSphereMethod   Compute(udword nb_verts, const Point* verts);
00039                                 bool                    FastCompute(udword nb_verts, const Point* verts);
00040 
00041                 // Access methods
00042                 inline_ const Point&    GetCenter()                                             const           { return mCenter; }
00043                 inline_ float                   GetRadius()                                             const           { return mRadius; }
00044 
00045                 inline_ const Point&    Center()                                                const           { return mCenter; }
00046                 inline_ float                   Radius()                                                const           { return mRadius; }
00047 
00048                 inline_ Sphere&                 Set(const Point& center, float radius)          { mCenter = center; mRadius = radius; return *this; }
00049                 inline_ Sphere&                 SetCenter(const Point& center)                          { mCenter = center; return *this; }
00050                 inline_ Sphere&                 SetRadius(float radius)                                         { mRadius = radius; return *this; }
00051 
00053 
00058 
00059                 inline_ bool                    Contains(const Point& p)                const
00060                                                                 {
00061                                                                         return mCenter.SquareDistance(p) <= mRadius*mRadius;
00062                                                                 }
00063 
00065 
00070 
00071                 inline_ bool                    Contains(const Sphere& sphere)  const
00072                                                                 {
00073                                                                         // If our radius is the smallest, we can't possibly contain the other sphere
00074                                                                         if(mRadius < sphere.mRadius)    return false;
00075                                                                         // So r is always positive or null now
00076                                                                         float r = mRadius - sphere.mRadius;
00077                                                                         return mCenter.SquareDistance(sphere.mCenter) <= r*r;
00078                                                                 }
00079 
00081 
00086 
00087                 inline_ BOOL                    Contains(const AABB& aabb)      const
00088                                                                 {
00089                                                                         // I assume if all 8 box vertices are inside the sphere, so does the whole box.
00090                                                                         // Sounds ok but maybe there's a better way?
00091                                                                         float R2 = mRadius * mRadius;
00092 #ifdef USE_MIN_MAX
00093                                                                         const Point& Max = ((ShadowAABB&)&aabb).mMax;
00094                                                                         const Point& Min = ((ShadowAABB&)&aabb).mMin;
00095 #else
00096                                                                         Point Max; aabb.GetMax(Max);
00097                                                                         Point Min; aabb.GetMin(Min);
00098 #endif
00099                                                                         Point p;
00100                                                                         p.x=Max.x; p.y=Max.y; p.z=Max.z;        if(mCenter.SquareDistance(p)>=R2)       return FALSE;
00101                                                                         p.x=Min.x;                                                      if(mCenter.SquareDistance(p)>=R2)       return FALSE;
00102                                                                         p.x=Max.x; p.y=Min.y;                           if(mCenter.SquareDistance(p)>=R2)       return FALSE;
00103                                                                         p.x=Min.x;                                                      if(mCenter.SquareDistance(p)>=R2)       return FALSE;
00104                                                                         p.x=Max.x; p.y=Max.y; p.z=Min.z;        if(mCenter.SquareDistance(p)>=R2)       return FALSE;
00105                                                                         p.x=Min.x;                                                      if(mCenter.SquareDistance(p)>=R2)       return FALSE;
00106                                                                         p.x=Max.x; p.y=Min.y;                           if(mCenter.SquareDistance(p)>=R2)       return FALSE;
00107                                                                         p.x=Min.x;                                                      if(mCenter.SquareDistance(p)>=R2)       return FALSE;
00108 
00109                                                                         return TRUE;
00110                                                                 }
00111 
00113 
00118 
00119                 inline_ bool                    Intersect(const Sphere& sphere) const
00120                                                                 {
00121                                                                         float r = mRadius + sphere.mRadius;
00122                                                                         return mCenter.SquareDistance(sphere.mCenter) <= r*r;
00123                                                                 }
00124 
00126 
00130 
00131                 inline_ BOOL                    IsValid()       const
00132                                                                 {
00133                                                                         // Consistency condition for spheres: Radius >= 0.0f
00134                                                                         if(mRadius < 0.0f)      return FALSE;
00135                                                                         return TRUE;
00136                                                                 }
00137                 public:
00138                                 Point                   mCenter;                
00139                                 float                   mRadius;                
00140         };
00141 
00142 #endif // __ICEBOUNDINGSPHERE_H__


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16