Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sphere Class Reference

#include <IceBoundingSphere.h>

Public Member Functions

inline_ Sphere ()
 Constructor. More...
 
inline_ Sphere (const Point &center, float radius)
 Constructor. More...
 
 Sphere (udword nb_verts, const Point *verts)
 Constructor. More...
 
inline_ Sphere (const Sphere &sphere)
 Copy constructor. More...
 
inline_ ~Sphere ()
 Destructor. More...
 
BSphereMethod Compute (udword nb_verts, const Point *verts)
 
bool FastCompute (udword nb_verts, const Point *verts)
 
inline_ const PointGetCenter () const
 
inline_ float GetRadius () const
 
inline_ const PointCenter () const
 
inline_ float Radius () const
 
inline_ SphereSet (const Point &center, float radius)
 
inline_ SphereSetCenter (const Point &center)
 
inline_ SphereSetRadius (float radius)
 
inline_ bool Contains (const Point &p) const
 
inline_ bool Contains (const Sphere &sphere) const
 
inline_ BOOL Contains (const AABB &aabb) const
 
inline_ bool Intersect (const Sphere &sphere) const
 
inline_ BOOL IsValid () const
 

Public Attributes

Point mCenter
 Sphere center. More...
 
float mRadius
 Sphere radius. More...
 

Detailed Description

Definition at line 24 of file IceBoundingSphere.h.

Constructor & Destructor Documentation

inline_ Sphere::Sphere ( )
inline

Constructor.

Definition at line 28 of file IceBoundingSphere.h.

28 {}
inline_ Sphere::Sphere ( const Point center,
float  radius 
)
inline

Constructor.

Definition at line 30 of file IceBoundingSphere.h.

30 : mCenter(center), mRadius(radius) {}
Sphere::Sphere ( udword  nb_verts,
const Point verts 
)

Constructor.

inline_ Sphere::Sphere ( const Sphere sphere)
inline

Copy constructor.

Definition at line 34 of file IceBoundingSphere.h.

34 : mCenter(sphere.mCenter), mRadius(sphere.mRadius) {}
inline_ Sphere::~Sphere ( )
inline

Destructor.

Definition at line 36 of file IceBoundingSphere.h.

36 {}

Member Function Documentation

inline_ const Point& Sphere::Center ( ) const
inline

Definition at line 45 of file IceBoundingSphere.h.

45 { return mCenter; }
BSphereMethod Sphere::Compute ( udword  nb_verts,
const Point verts 
)
inline_ bool Sphere::Contains ( const Point p) const
inline

Tests if a point is contained within the sphere.

Parameters
p[in] the point to test
Returns
true if inside the sphere

Definition at line 59 of file IceBoundingSphere.h.

60  {
62  }
inline_ bool Sphere::Contains ( const Sphere sphere) const
inline

Tests if a sphere is contained within the sphere.

Parameters
sphere[in] the sphere to test
Returns
true if inside the sphere

Definition at line 71 of file IceBoundingSphere.h.

72  {
73  // If our radius is the smallest, we can't possibly contain the other sphere
74  if(mRadius < sphere.mRadius) return false;
75  // So r is always positive or null now
76  float r = mRadius - sphere.mRadius;
77  return mCenter.SquareDistance(sphere.mCenter) <= r*r;
78  }
inline_ BOOL Sphere::Contains ( const AABB aabb) const
inline

Tests if a box is contained within the sphere.

Parameters
aabb[in] the box to test
Returns
true if inside the sphere

Definition at line 87 of file IceBoundingSphere.h.

88  {
89  // I assume if all 8 box vertices are inside the sphere, so does the whole box.
90  // Sounds ok but maybe there's a better way?
91  float R2 = mRadius * mRadius;
92 #ifdef USE_MIN_MAX
93  const Point& Max = ((ShadowAABB&)&aabb).mMax;
94  const Point& Min = ((ShadowAABB&)&aabb).mMin;
95 #else
96  Point Max; aabb.GetMax(Max);
97  Point Min; aabb.GetMin(Min);
98 #endif
99  Point p;
100  p.x=Max.x; p.y=Max.y; p.z=Max.z; if(mCenter.SquareDistance(p)>=R2) return FALSE;
101  p.x=Min.x; if(mCenter.SquareDistance(p)>=R2) return FALSE;
102  p.x=Max.x; p.y=Min.y; if(mCenter.SquareDistance(p)>=R2) return FALSE;
103  p.x=Min.x; if(mCenter.SquareDistance(p)>=R2) return FALSE;
104  p.x=Max.x; p.y=Max.y; p.z=Min.z; if(mCenter.SquareDistance(p)>=R2) return FALSE;
105  p.x=Min.x; if(mCenter.SquareDistance(p)>=R2) return FALSE;
106  p.x=Max.x; p.y=Min.y; if(mCenter.SquareDistance(p)>=R2) return FALSE;
107  p.x=Min.x; if(mCenter.SquareDistance(p)>=R2) return FALSE;
108 
109  return TRUE;
110  }
bool Sphere::FastCompute ( udword  nb_verts,
const Point verts 
)
inline_ const Point& Sphere::GetCenter ( ) const
inline

Definition at line 42 of file IceBoundingSphere.h.

42 { return mCenter; }
inline_ float Sphere::GetRadius ( ) const
inline

Definition at line 43 of file IceBoundingSphere.h.

43 { return mRadius; }
inline_ bool Sphere::Intersect ( const Sphere sphere) const
inline

Tests if the sphere intersects another sphere

Parameters
sphere[in] the other sphere
Returns
true if spheres overlap

Definition at line 119 of file IceBoundingSphere.h.

120  {
121  float r = mRadius + sphere.mRadius;
122  return mCenter.SquareDistance(sphere.mCenter) <= r*r;
123  }
inline_ BOOL Sphere::IsValid ( ) const
inline

Checks the sphere is valid.

Returns
true if the box is valid

Definition at line 131 of file IceBoundingSphere.h.

132  {
133  // Consistency condition for spheres: Radius >= 0.0f
134  if(mRadius < 0.0f) return FALSE;
135  return TRUE;
136  }
inline_ float Sphere::Radius ( ) const
inline

Definition at line 46 of file IceBoundingSphere.h.

46 { return mRadius; }
inline_ Sphere& Sphere::Set ( const Point center,
float  radius 
)
inline

Definition at line 48 of file IceBoundingSphere.h.

References center.

48 { mCenter = center; mRadius = radius; return *this; }
inline_ Sphere& Sphere::SetCenter ( const Point center)
inline

Definition at line 49 of file IceBoundingSphere.h.

References center.

49 { mCenter = center; return *this; }
inline_ Sphere& Sphere::SetRadius ( float  radius)
inline

Definition at line 50 of file IceBoundingSphere.h.

50 { mRadius = radius; return *this; }

Member Data Documentation

Point Sphere::mCenter

Sphere center.

Definition at line 138 of file IceBoundingSphere.h.

float Sphere::mRadius

Sphere radius.

Definition at line 139 of file IceBoundingSphere.h.


The documentation for this class was generated from the following file: