My Project
ShapeSphere.h
1 #pragma once
2 
3 namespace ParaEngine
4 {
5  class CShapeAABB;
7  {
8  public:
10  inline CShapeSphere() {}
12  inline CShapeSphere(const Vector3& center, float radius) : mCenter(center), mRadius(radius) {}
14  CShapeSphere(int nb_verts, const Vector3* verts);
16  inline CShapeSphere(const CShapeSphere& sphere) : mCenter(sphere.mCenter), mRadius(sphere.mRadius) {}
18  inline ~CShapeSphere() {}
19 
20  void Compute(int nb_verts, const Vector3* verts);
21 
22  // Access methods
23  inline const Vector3& GetCenter() const { return mCenter; }
24  inline float GetRadius() const { return mRadius; }
25 
26  inline const Vector3& Center() const { return mCenter; }
27  inline float Radius() const { return mRadius; }
28 
29  inline CShapeSphere& Set(const Vector3& center, float radius) { mCenter = center; mRadius = radius; return *this; }
30  inline CShapeSphere& SetCenter(const Vector3& center) { mCenter = center; return *this; }
31  inline CShapeSphere& SetRadius(float radius) { mRadius = radius; return *this; }
32 
34 
39  inline bool Contains(const Vector3& p) const
41  {
42  return (mCenter-p).squaredLength() <= mRadius*mRadius;
43  }
44 
46 
51  inline bool Contains(const CShapeSphere& sphere) const
53  {
54  // If our radius is the smallest, we can't possibly contain the other sphere
55  if(mRadius < sphere.mRadius) return false;
56  // So r is always positive or null now
57  float r = mRadius - sphere.mRadius;
58  return (mCenter-sphere.mCenter).squaredLength() <= r*r;
59  }
60 
62 
67  BOOL Contains(const CShapeAABB& aabb) const;
69 
71 
76  inline bool Intersect(const CShapeSphere& sphere) const
78  {
79  float r = mRadius + sphere.mRadius;
80  return (mCenter-sphere.mCenter).squaredLength() <= r*r;
81  }
82 
84 
88  inline BOOL IsValid() const
90  {
91  // Consistency condition for spheres: Radius >= 0.0f
92  if(mRadius < 0.0f) return FALSE;
93  return TRUE;
94  }
95  public:
97  float mRadius;
98  };
99 
100 }
~CShapeSphere()
Destructor.
Definition: ShapeSphere.h:18
CShapeSphere()
Constructor.
Definition: ShapeSphere.h:10
Vector3 mCenter
Sphere center.
Definition: ShapeSphere.h:96
different physics engine has different winding order.
Definition: EventBinding.h:32
BOOL IsValid() const
Checks the sphere is valid.
Definition: ShapeSphere.h:89
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
bool Intersect(const CShapeSphere &sphere) const
Tests if the sphere intersects another sphere.
Definition: ShapeSphere.h:77
Definition: ShapeSphere.h:6
AABB-related code.
Definition: ShapeAABB.h:11
CShapeSphere(const CShapeSphere &sphere)
Copy constructor.
Definition: ShapeSphere.h:16
float mRadius
Sphere radius.
Definition: ShapeSphere.h:97
bool Contains(const Vector3 &p) const
Tests if a point is contained within the sphere.
Definition: ShapeSphere.h:40
CShapeSphere(const Vector3 &center, float radius)
Constructor.
Definition: ShapeSphere.h:12