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

Revision 657, 4.3 KB checked in by mattausch, 19 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 __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        virtual ~Ray() {}
47
48        /** Sets the origin of the ray. */
49        void setOrigin(const Vector3& origin) {mOrigin = origin;}
50        /** Gets the origin of the ray. */
51        const Vector3& getOrigin(void) const {return mOrigin;}
52
53        /** Sets the direction of the ray. */
54        void setDirection(const Vector3& dir) {mDirection = dir;}
55        /** Gets the direction of the ray. */
56        const Vector3& getDirection(void) const {return mDirection;}
57
58                /** Gets the position of a point t units along the ray. */
59                Vector3 getPoint(Real t) const {
60                        return Vector3(mOrigin + (mDirection * t));
61                }
62               
63                /** Gets the position of a point t units along the ray. */
64                Vector3 operator*(Real t) const {
65                        return getPoint(t);
66                };
67
68                /** Tests whether this ray intersects the given plane.
69                @returns A pair structure where the first element indicates whether
70                        an intersection occurs, and if true, the second element will
71                        indicate the distance along the ray at which it intersects.
72                        This can be converted to a point in space by calling getPoint().
73                */
74                std::pair<bool, Real> intersects(const Plane& p) const
75                {
76                        return Math::intersects(*this, p);
77                }
78        /** Tests whether this ray intersects the given plane bounded volume.
79        @returns A pair structure where the first element indicates whether
80        an intersection occurs, and if true, the second element will
81        indicate the distance along the ray at which it intersects.
82        This can be converted to a point in space by calling getPoint().
83        */
84        std::pair<bool, Real> intersects(const PlaneBoundedVolume& p) const
85        {
86            return Math::intersects(*this, p.planes, p.outside == Plane::POSITIVE_SIDE);
87        }
88                /** Tests whether this ray intersects the given sphere.
89                @returns A pair structure where the first element indicates whether
90                        an intersection occurs, and if true, the second element will
91                        indicate the distance along the ray at which it intersects.
92                        This can be converted to a point in space by calling getPoint().
93                */
94                std::pair<bool, Real> intersects(const Sphere& s) const
95                {
96                        return Math::intersects(*this, s);
97                }
98                /** Tests whether this ray intersects the given box.
99                @returns A pair structure where the first element indicates whether
100                        an intersection occurs, and if true, the second element will
101                        indicate the distance along the ray at which it intersects.
102                        This can be converted to a point in space by calling getPoint().
103                */
104                std::pair<bool, Real> intersects(const AxisAlignedBox& box) const
105                {
106                        return Math::intersects(*this, box);
107                }
108
109    };
110
111}
112#endif
Note: See TracBrowser for help on using the repository browser.