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