source: GTP/trunk/App/Demos/Geom/OgreStuff/include/OgreRay.h @ 1812

Revision 1812, 4.3 KB checked in by gumbau, 18 years ago (diff)
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 __Ray_H_
26#define __Ray_H_
27
28// Precompiler options
29#include "OgrePrerequisites.h"
30
31#include "OgreVector3.h"
32#include "OgrePlaneBoundedVolume.h"
33
34namespace Ogre {
35
36    /** Representation of a ray in space, ie a line with an origin and direction. */
37    class _OgreExport Ray
38    {
39    protected:
40        Vector3 mOrigin;
41        Vector3 mDirection;
42    public:
43        Ray():mOrigin(Vector3::ZERO), mDirection(Vector3::UNIT_Z) {}
44        Ray(const Vector3& origin, const Vector3& direction)
45            :mOrigin(origin), mDirection(direction) {}
46
47        /** Sets the origin of the ray. */
48        void setOrigin(const Vector3& origin) {mOrigin = origin;}
49        /** Gets the origin of the ray. */
50        const Vector3& getOrigin(void) const {return mOrigin;}
51
52        /** Sets the direction of the ray. */
53        void setDirection(const Vector3& dir) {mDirection = dir;}
54        /** Gets the direction of the ray. */
55        const Vector3& getDirection(void) const {return mDirection;}
56
57                /** Gets the position of a point t units along the ray. */
58                Vector3 getPoint(Real t) const {
59                        return Vector3(mOrigin + (mDirection * t));
60                }
61               
62                /** Gets the position of a point t units along the ray. */
63                Vector3 operator*(Real t) const {
64                        return getPoint(t);
65                };
66
67                /** Tests whether this ray intersects the given plane.
68                @returns A pair structure where the first element indicates whether
69                        an intersection occurs, and if true, the second element will
70                        indicate the distance along the ray at which it intersects.
71                        This can be converted to a point in space by calling getPoint().
72                */
73                std::pair<bool, Real> intersects(const Plane& p) const
74                {
75                        return Math::intersects(*this, p);
76                }
77        /** Tests whether this ray intersects the given plane bounded volume.
78        @returns A pair structure where the first element indicates whether
79        an intersection occurs, and if true, the second element will
80        indicate the distance along the ray at which it intersects.
81        This can be converted to a point in space by calling getPoint().
82        */
83        std::pair<bool, Real> intersects(const PlaneBoundedVolume& p) const
84        {
85            return Math::intersects(*this, p.planes, p.outside == Plane::POSITIVE_SIDE);
86        }
87                /** Tests whether this ray intersects the given sphere.
88                @returns A pair structure where the first element indicates whether
89                        an intersection occurs, and if true, the second element will
90                        indicate the distance along the ray at which it intersects.
91                        This can be converted to a point in space by calling getPoint().
92                */
93                std::pair<bool, Real> intersects(const Sphere& s) const
94                {
95                        return Math::intersects(*this, s);
96                }
97                /** Tests whether this ray intersects the given box.
98                @returns A pair structure where the first element indicates whether
99                        an intersection occurs, and if true, the second element will
100                        indicate the distance along the ray at which it intersects.
101                        This can be converted to a point in space by calling getPoint().
102                */
103                std::pair<bool, Real> intersects(const AxisAlignedBox& box) const
104                {
105                        return Math::intersects(*this, box);
106                }
107
108    };
109
110}
111#endif
Note: See TracBrowser for help on using the repository browser.