OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RayIntersector.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSGUTIL_RAYINTERSECTOR
15 #define OSGUTIL_RAYINTERSECTOR 1
16 
17 #include <osgUtil/IntersectionVisitor>
18 
19 namespace osgUtil
20 {
21 
33 {
34  public:
35 
38  RayIntersector(CoordinateFrame cf = MODEL, RayIntersector* parent = NULL,
40 
43  RayIntersector(const osg::Vec3d& start, const osg::Vec3d& direction);
44 
46  RayIntersector(CoordinateFrame cf, const osg::Vec3d& start, const osg::Vec3d& direction, RayIntersector* parent = NULL,
48 
53  RayIntersector(CoordinateFrame cf, double x, double y);
54 
56  {
57  Intersection() : distance(-1.0), primitiveIndex(0) {}
58 
59  bool operator < (const Intersection& rhs) const { return distance < rhs.distance; }
60 
61  typedef std::vector<unsigned int> IndexList;
62  typedef std::vector<double> RatioList;
63 
64  double distance;
70  IndexList indexList;
71  RatioList ratioList;
72  unsigned int primitiveIndex;
73 
74  const osg::Vec3d& getLocalIntersectPoint() const { return localIntersectionPoint; }
75  osg::Vec3d getWorldIntersectPoint() const { return matrix.valid() ? localIntersectionPoint * (*matrix) : localIntersectionPoint; }
76 
77  const osg::Vec3& getLocalIntersectNormal() const { return localIntersectionNormal; }
78  osg::Vec3 getWorldIntersectNormal() const { return matrix.valid() ? osg::Matrix::transform3x3(osg::Matrix::inverse(*matrix),localIntersectionNormal) : localIntersectionNormal; }
79 
82  osg::Texture* getTextureLookUp(osg::Vec3& tc) const;
83 
84  };
85 
86  typedef std::multiset<Intersection> Intersections;
87 
88  inline void insertIntersection(const Intersection& intersection) { getIntersections().insert(intersection); }
89  inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
90  inline Intersection getFirstIntersection() { Intersections& intersections = getIntersections(); return intersections.empty() ? Intersection() : *(intersections.begin()); }
91 
92  virtual void setStart(const osg::Vec3d& start) { _start = start; }
93  inline const osg::Vec3d& getStart() const { return _start; }
94 
95  virtual void setDirection(const osg::Vec3d& dir) { _direction = dir; }
96  inline const osg::Vec3d& getDirection() const { return _direction; }
97 
98  public:
99 
101 
102  virtual bool enter(const osg::Node& node);
103 
104  virtual void leave();
105 
106  virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable);
107 
108  virtual void reset();
109 
110  virtual bool containsIntersections() { return !getIntersections().empty(); }
111 
112  protected:
113 
114  virtual bool intersects(const osg::BoundingSphere& bs);
115  bool intersectAndClip(osg::Vec3d& s, const osg::Vec3d& d, osg::Vec3d& e, const osg::BoundingBox& bb);
116 
118 
121 
122  Intersections _intersections;
123 
124 };
125 
126 }
127 
128 #endif
virtual bool containsIntersections()
std::multiset< Intersection > Intersections
#define NULL
Definition: Export.h:59
const osg::Vec3d & getDirection() const
static Vec3f transform3x3(const Vec3f &v, const Matrixd &m)
Definition: Matrixd.h:659
bool valid() const
Definition: ref_ptr.h:95
Intersections _intersections
const osg::Vec3 & getLocalIntersectNormal() const
T * clone(const T *t, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Object.h:242
virtual void setDirection(const osg::Vec3d &dir)
static Matrixd inverse(const Matrixd &matrix)
Definition: Matrixd.h:530
osg::Vec3 getWorldIntersectNormal() const
const osg::Vec3d & getStart() const
osg::Vec3d getWorldIntersectPoint() const
RayIntersector * _parent
std::vector< unsigned int > IndexList
Intersections & getIntersections()
Definition: Node.h:71
Intersection getFirstIntersection()
#define OSGUTIL_EXPORT
Definition: Export.h:40
virtual void setStart(const osg::Vec3d &start)
void insertIntersection(const Intersection &intersection)
osg::ref_ptr< osg::RefMatrix > matrix
osg::ref_ptr< osg::Drawable > drawable
const osg::Vec3d & getLocalIntersectPoint() const
std::vector< Node * > NodePath
Definition: Node.h:44
Shader generator framework.
Definition: RenderInfo.h:20