source: OGRE/trunk/ogrenew/OgreMain/include/OgreSphere.h @ 657

Revision 657, 3.2 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#ifndef __Sphere_H_
26#define __Sphere_H_
27
28// Precompiler options
29#include "OgrePrerequisites.h"
30
31#include "OgreVector3.h"
32
33namespace Ogre {
34
35
36    /** A sphere primitive, mostly used for bounds checking.
37    @remarks
38        A sphere in math texts is normally represented by the function
39        x^2 + y^2 + z^2 = r^2 (for sphere's centered on the origin). Ogre stores spheres
40        simply as a center point and a radius.
41    */
42    class _OgreExport Sphere
43    {
44    protected:
45        Real mRadius;
46        Vector3 mCenter;
47    public:
48        /** Standard constructor - creates a unit sphere around the origin.*/
49        Sphere() : mRadius(1.0), mCenter(Vector3::ZERO) {}
50        /** Constructor allowing arbitrary spheres.
51            @param center The center point of the sphere.
52            @param radius The radius of the sphere.
53        */
54        Sphere(const Vector3& center, Real radius)
55            : mRadius(radius), mCenter(center) {}
56
57        /** Returns the radius of the sphere. */
58        Real getRadius(void) const { return mRadius; }
59
60        /** Sets the radius of the sphere. */
61        void setRadius(Real radius) { mRadius = radius; }
62
63        /** Returns the center point of the sphere. */
64        const Vector3& getCenter(void) const { return mCenter; }
65
66        /** Sets the center point of the sphere. */
67        void setCenter(const Vector3& center) { mCenter = center; }
68
69                /** Returns whether or not this sphere interects another sphere. */
70                bool intersects(const Sphere& s) const
71                {
72                        return (s.mCenter - mCenter).length() <=
73                                (s.mRadius + mRadius);
74                }
75                /** Returns whether or not this sphere interects a box. */
76                bool intersects(const AxisAlignedBox& box) const
77                {
78                        return Math::intersects(*this, box);
79                }
80                /** Returns whether or not this sphere interects a plane. */
81                bool intersects(const Plane& plane) const
82                {
83                        return Math::intersects(*this, plane);
84                }
85                /** Returns whether or not this sphere interects a point. */
86                bool intersects(const Vector3& v) const
87                {
88                        return ((v - mCenter).length() <= mRadius);
89                }
90       
91
92    };
93
94}
95
96#endif
97
Note: See TracBrowser for help on using the repository browser.