OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreRay.h
Go to the documentation of this file.
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-2014 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 "OgrePlaneBoundedVolume.h"
35 
36 namespace Ogre {
37 
46  {
47  protected:
50  public:
51  Ray():mOrigin(Vector3::ZERO), mDirection(Vector3::UNIT_Z) {}
52  Ray(const Vector3& origin, const Vector3& direction)
53  :mOrigin(origin), mDirection(direction) {}
54 
56  void setOrigin(const Vector3& origin) {mOrigin = origin;}
58  const Vector3& getOrigin(void) const {return mOrigin;}
59 
61  void setDirection(const Vector3& dir) {mDirection = dir;}
63  const Vector3& getDirection(void) const {return mDirection;}
64 
66  Vector3 getPoint(Real t) const {
67  return Vector3(mOrigin + (mDirection * t));
68  }
69 
71  Vector3 operator*(Real t) const {
72  return getPoint(t);
73  }
74 
81  std::pair<bool, Real> intersects(const Plane& p) const
82  {
83  return Math::intersects(*this, p);
84  }
91  std::pair<bool, Real> intersects(const PlaneBoundedVolume& p) const
92  {
93  return Math::intersects(*this, p.planes, p.outside == Plane::POSITIVE_SIDE);
94  }
101  std::pair<bool, Real> intersects(const Sphere& s) const
102  {
103  return Math::intersects(*this, s);
104  }
111  std::pair<bool, Real> intersects(const AxisAlignedBox& box) const
112  {
113  return Math::intersects(*this, box);
114  }
115 
116  };
120 }
121 #endif
Representation of a ray in space, i.e.
Definition: OgreRay.h:45
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:255
std::pair< bool, Real > intersects(const Plane &p) const
Tests whether this ray intersects the given plane.
Definition: OgreRay.h:81
void setOrigin(const Vector3 &origin)
Sets the origin of the ray.
Definition: OgreRay.h:56
PlaneList planes
Publicly accessible plane list, you can modify this direct.
Defines a plane in 3D space.
Definition: OgrePlane.h:61
void setDirection(const Vector3 &dir)
Sets the direction of the ray.
Definition: OgreRay.h:61
A 3D box aligned with the x/y/z axes.
static std::pair< bool, Real > intersects(const Ray &ray, const Plane &plane)
Ray / plane intersection, returns boolean result and distance.
Vector3 mOrigin
Definition: OgreRay.h:48
std::pair< bool, Real > intersects(const Sphere &s) const
Tests whether this ray intersects the given sphere.
Definition: OgreRay.h:101
Ray(const Vector3 &origin, const Vector3 &direction)
Definition: OgreRay.h:52
const Vector3 & getDirection(void) const
Gets the direction of the ray.
Definition: OgreRay.h:63
A sphere primitive, mostly used for bounds checking.
Definition: OgreSphere.h:51
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
Represents a convex volume bounded by planes.
std::pair< bool, Real > intersects(const AxisAlignedBox &box) const
Tests whether this ray intersects the given box.
Definition: OgreRay.h:111
const Vector3 & getOrigin(void) const
Gets the origin of the ray.
Definition: OgreRay.h:58
Vector3 operator*(Real t) const
Gets the position of a point t units along the ray.
Definition: OgreRay.h:71
std::pair< bool, Real > intersects(const PlaneBoundedVolume &p) const
Tests whether this ray intersects the given plane bounded volume.
Definition: OgreRay.h:91
Vector3 mDirection
Definition: OgreRay.h:49
Vector3 getPoint(Real t) const
Gets the position of a point t units along the ray.
Definition: OgreRay.h:66