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-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 
47  {
48  protected:
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 
57  void setOrigin(const Vector3& origin) {mOrigin = origin;}
59  const Vector3& getOrigin(void) const {return mOrigin;}
60 
62  void setDirection(const Vector3& dir) {mDirection = dir;}
64  const Vector3& getDirection(void) const {return mDirection;}
65 
67  Vector3 getPoint(Real t) const {
68  return Vector3(mOrigin + (mDirection * t));
69  }
70 
72  Vector3 operator*(Real t) const {
73  return getPoint(t);
74  }
75 
82  std::pair<bool, Real> intersects(const Plane& p) const
83  {
84  return Math::intersects(*this, p);
85  }
92  std::pair<bool, Real> intersects(const PlaneBoundedVolume& p) const
93  {
94  return Math::intersects(*this, p.planes, p.outside == Plane::POSITIVE_SIDE);
95  }
102  std::pair<bool, Real> intersects(const Sphere& s) const
103  {
104  return Math::intersects(*this, s);
105  }
112  std::pair<bool, Real> intersects(const AxisAlignedBox& box) const
113  {
114  return Math::intersects(*this, box);
115  }
116 
117  };
121 }
122 #endif
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::Plane
Defines a plane in 3D space.
Definition: OgrePlane.h:61
Ogre::Ray::Ray
Ray()
Definition: OgreRay.h:52
Ogre::Ray::intersects
std::pair< bool, Real > intersects(const PlaneBoundedVolume &p) const
Tests whether this ray intersects the given plane bounded volume.
Definition: OgreRay.h:92
Ogre::Ray::Ray
Ray(const Vector3 &origin, const Vector3 &direction)
Definition: OgreRay.h:53
Ogre::Ray::mDirection
Vector3 mDirection
Definition: OgreRay.h:50
Ogre::Ray::getDirection
const Vector3 & getDirection(void) const
Gets the direction of the ray.
Definition: OgreRay.h:64
Ogre::Plane::POSITIVE_SIDE
Definition: OgrePlane.h:83
Ogre::Ray::intersects
std::pair< bool, Real > intersects(const Plane &p) const
Tests whether this ray intersects the given plane.
Definition: OgreRay.h:82
Ogre::PlaneBoundedVolume::outside
Plane::Side outside
Definition: OgrePlaneBoundedVolume.h:55
OgrePrerequisites.h
Ogre::Ray::setDirection
void setDirection(const Vector3 &dir)
Sets the direction of the ray.
Definition: OgreRay.h:62
Ogre::Ray::intersects
std::pair< bool, Real > intersects(const AxisAlignedBox &box) const
Tests whether this ray intersects the given box.
Definition: OgreRay.h:112
Ogre::AxisAlignedBox
A 3D box aligned with the x/y/z axes.
Definition: OgreAxisAlignedBox.h:54
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::Ray::getOrigin
const Vector3 & getOrigin(void) const
Gets the origin of the ray.
Definition: OgreRay.h:59
Ogre::Sphere
A sphere primitive, mostly used for bounds checking.
Definition: OgreSphere.h:51
Ogre::Ray::operator*
Vector3 operator*(Real t) const
Gets the position of a point t units along the ray.
Definition: OgreRay.h:72
Ogre::Ray::mOrigin
Vector3 mOrigin
Definition: OgreRay.h:49
Ogre::PlaneBoundedVolume
Represents a convex volume bounded by planes.
Definition: OgrePlaneBoundedVolume.h:49
Ogre::Math::intersects
static std::pair< bool, Real > intersects(const Ray &ray, const Plane &plane)
Ray / plane intersection, returns boolean result and distance.
Ogre::Ray::setOrigin
void setOrigin(const Vector3 &origin)
Sets the origin of the ray.
Definition: OgreRay.h:57
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::PlaneBoundedVolume::planes
PlaneList planes
Publicly accessible plane list, you can modify this direct.
Definition: OgrePlaneBoundedVolume.h:54
Ogre::Ray
Representation of a ray in space, i.e.
Definition: OgreRay.h:46
OgreVector3.h
Ogre::Ray::getPoint
Vector3 getPoint(Real t) const
Gets the position of a point t units along the ray.
Definition: OgreRay.h:67
OgrePlaneBoundedVolume.h
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::Ray::intersects
std::pair< bool, Real > intersects(const Sphere &s) const
Tests whether this ray intersects the given sphere.
Definition: OgreRay.h:102

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.