Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/OgreMain/include/OgreSphere.h @ 29

Last change on this file since 29 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 3.4 KB
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-2006 Torus Knot Software Ltd
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
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#ifndef __Sphere_H_
30#define __Sphere_H_
31
32// Precompiler options
33#include "OgrePrerequisites.h"
34
35#include "OgreVector3.h"
36
37namespace Ogre {
38
39
40    /** A sphere primitive, mostly used for bounds checking.
41    @remarks
42        A sphere in math texts is normally represented by the function
43        x^2 + y^2 + z^2 = r^2 (for sphere's centered on the origin). Ogre stores spheres
44        simply as a center point and a radius.
45    */
46    class _OgreExport Sphere
47    {
48    protected:
49        Real mRadius;
50        Vector3 mCenter;
51    public:
52        /** Standard constructor - creates a unit sphere around the origin.*/
53        Sphere() : mRadius(1.0), mCenter(Vector3::ZERO) {}
54        /** Constructor allowing arbitrary spheres.
55            @param center The center point of the sphere.
56            @param radius The radius of the sphere.
57        */
58        Sphere(const Vector3& center, Real radius)
59            : mRadius(radius), mCenter(center) {}
60
61        /** Returns the radius of the sphere. */
62        Real getRadius(void) const { return mRadius; }
63
64        /** Sets the radius of the sphere. */
65        void setRadius(Real radius) { mRadius = radius; }
66
67        /** Returns the center point of the sphere. */
68        const Vector3& getCenter(void) const { return mCenter; }
69
70        /** Sets the center point of the sphere. */
71        void setCenter(const Vector3& center) { mCenter = center; }
72
73                /** Returns whether or not this sphere interects another sphere. */
74                bool intersects(const Sphere& s) const
75                {
76            return (s.mCenter - mCenter).squaredLength() <=
77                Math::Sqr(s.mRadius + mRadius);
78                }
79                /** Returns whether or not this sphere interects a box. */
80                bool intersects(const AxisAlignedBox& box) const
81                {
82                        return Math::intersects(*this, box);
83                }
84                /** Returns whether or not this sphere interects a plane. */
85                bool intersects(const Plane& plane) const
86                {
87                        return Math::intersects(*this, plane);
88                }
89                /** Returns whether or not this sphere interects a point. */
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
Note: See TracBrowser for help on using the repository browser.