OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreSphere.h
Go to the documentation of this file.
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-2011 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __Sphere_H_
29 #define __Sphere_H_
30 
31 // Precompiler options
32 #include "OgrePrerequisites.h"
33 
34 #include "OgreVector3.h"
35 
36 namespace Ogre {
37 
38 
52  {
53  protected:
56  public:
58  Sphere() : mRadius(1.0), mCenter(Vector3::ZERO) {}
63  Sphere(const Vector3& center, Real radius)
64  : mRadius(radius), mCenter(center) {}
65 
67  Real getRadius(void) const { return mRadius; }
68 
70  void setRadius(Real radius) { mRadius = radius; }
71 
73  const Vector3& getCenter(void) const { return mCenter; }
74 
76  void setCenter(const Vector3& center) { mCenter = center; }
77 
79  bool intersects(const Sphere& s) const
80  {
81  return (s.mCenter - mCenter).squaredLength() <=
82  Math::Sqr(s.mRadius + mRadius);
83  }
85  bool intersects(const AxisAlignedBox& box) const
86  {
87  return Math::intersects(*this, box);
88  }
90  bool intersects(const Plane& plane) const
91  {
92  return Math::intersects(*this, plane);
93  }
95  bool intersects(const Vector3& v) const
96  {
97  return ((v - mCenter).squaredLength() <= Math::Sqr(mRadius));
98  }
99 
100 
101  };
105 }
106 
107 #endif
108 
Sphere(const Vector3 &center, Real radius)
Constructor allowing arbitrary spheres.
Definition: OgreSphere.h:63
const Vector3 & getCenter(void) const
Returns the center point of the sphere.
Definition: OgreSphere.h:73
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:203
Real mRadius
Definition: OgreSphere.h:54
Defines a plane in 3D space.
Definition: OgrePlane.h:61
Sphere()
Standard constructor - creates a unit sphere around the origin.
Definition: OgreSphere.h:58
A 3D box aligned with the x/y/z axes.
static std::pair< bool, Real > intersects(const Ray &ray, const Plane &plane)
Ray / plane intersection, returns boolean result and distance.
bool intersects(const Plane &plane) const
Returns whether or not this sphere intersects a plane.
Definition: OgreSphere.h:90
void setCenter(const Vector3 &center)
Sets the center point of the sphere.
Definition: OgreSphere.h:76
A sphere primitive, mostly used for bounds checking.
Definition: OgreSphere.h:51
static Real Sqr(Real fValue)
Definition: OgreMath.h:321
Real getRadius(void) const
Returns the radius of the sphere.
Definition: OgreSphere.h:67
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
void setRadius(Real radius)
Sets the radius of the sphere.
Definition: OgreSphere.h:70
bool intersects(const Sphere &s) const
Returns whether or not this sphere intersects another sphere.
Definition: OgreSphere.h:79
Vector3 mCenter
Definition: OgreSphere.h:55
bool intersects(const Vector3 &v) const
Returns whether or not this sphere intersects a point.
Definition: OgreSphere.h:95
bool intersects(const AxisAlignedBox &box) const
Returns whether or not this sphere intersects a box.
Definition: OgreSphere.h:85