My Project
ParaSphere.h
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2006 Torus Knot Software Ltd
8 Also see acknowledgements in Readme.html
9 
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
13 version.
14 
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22 http://www.gnu.org/copyleft/lesser.txt.
23 
24 You may alternatively use this source under the terms of a specific version of
25 the OGRE Unrestricted License provided you have obtained such a license from
26 Torus Knot Software Ltd.
27 -----------------------------------------------------------------------------
28 */
29 #ifndef __Sphere_H_
30 #define __Sphere_H_
31 
32 // Precompiler options
33 
34 
35 #include "ParaVector3.h"
36 
37 namespace ParaEngine {
38 
39 
46  class Sphere
47  {
48  protected:
49  float mRadius;
50  Vector3 mCenter;
51  public:
53  Sphere() : mRadius(1.0), mCenter(Vector3::ZERO) {}
58  Sphere(const Vector3& center, float radius)
59  : mRadius(radius), mCenter(center) {}
60 
62  float getRadius(void) const { return mRadius; }
63 
65  void setRadius(float radius) { mRadius = radius; }
66 
68  const Vector3& getCenter(void) const { return mCenter; }
69 
71  void setCenter(const Vector3& center) { mCenter = center; }
72 
74  bool intersects(const Sphere& s) const
75  {
76  return (s.mCenter - mCenter).squaredLength() <=
77  Math::Sqr(s.mRadius + mRadius);
78  }
80  bool intersects(const AxisAlignedBox& box) const
81  {
82  return Math::intersects(*this, box);
83  }
85  bool intersects(const Plane& plane) const
86  {
87  return Math::intersects(*this, plane);
88  }
90  bool intersects(const Vector3& v) const
91  {
92  return ((v - mCenter).squaredLength() <= Math::Sqr(mRadius));
93  }
94 
95 
96  };
97 
98 }
99 
100 #endif
101 
float getRadius(void) const
Returns the radius of the sphere.
Definition: ParaSphere.h:62
bool intersects(const Plane &plane) const
Returns whether or not this sphere intersects a plane.
Definition: ParaSphere.h:85
different physics engine has different winding order.
Definition: EventBinding.h:32
Sphere()
Standard constructor - creates a unit sphere around the origin.
Definition: ParaSphere.h:53
static std::pair< bool, float > intersects(const Ray &ray, const Plane &plane)
Ray / plane intersection, returns boolean result and distance.
Definition: ParaMath.cpp:316
Sphere(const Vector3 &center, float radius)
Constructor allowing arbitrary spheres.
Definition: ParaSphere.h:58
const Vector3 & getCenter(void) const
Returns the center point of the sphere.
Definition: ParaSphere.h:68
A sphere primitive, mostly used for bounds checking.
Definition: ParaSphere.h:46
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
void setCenter(const Vector3 &center)
Sets the center point of the sphere.
Definition: ParaSphere.h:71
Defines a plane in 3D space.
Definition: ParaPlane.h:23
bool intersects(const Sphere &s) const
Returns whether or not this sphere intersects another sphere.
Definition: ParaSphere.h:74
bool intersects(const Vector3 &v) const
Returns whether or not this sphere intersects a point.
Definition: ParaSphere.h:90
bool intersects(const AxisAlignedBox &box) const
Returns whether or not this sphere intersects a box.
Definition: ParaSphere.h:80
A 3D box aligned with the x/y/z axes.
Definition: ParaAxisAlignedBox.h:16
void setRadius(float radius)
Sets the radius of the sphere.
Definition: ParaSphere.h:65