openscenegraph
RayIntersector
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
18
19namespace osgUtil
20{
21
33{
34 public:
35
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;
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
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
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);
116
118
121
123
124};
125
126}
127
128#endif
Definition IntersectionVisitor:152
Definition IntersectionVisitor:34
IntersectionLimit
Definition IntersectionVisitor:46
@ NO_LIMIT
Definition IntersectionVisitor:47
CoordinateFrame
Definition IntersectionVisitor:38
Definition RayIntersector:33
RayIntersector(const osg::Vec3d &start, const osg::Vec3d &direction)
virtual void setStart(const osg::Vec3d &start)
Definition RayIntersector:92
virtual bool enter(const osg::Node &node)
bool intersectAndClip(osg::Vec3d &s, const osg::Vec3d &d, osg::Vec3d &e, const osg::BoundingBox &bb)
virtual void reset()
const osg::Vec3d & getDirection() const
Definition RayIntersector:96
osg::Vec3d _start
Definition RayIntersector:119
Intersection getFirstIntersection()
Definition RayIntersector:90
osg::Vec3d _direction
Definition RayIntersector:120
virtual void setDirection(const osg::Vec3d &dir)
Definition RayIntersector:95
Intersections _intersections
Definition RayIntersector:122
RayIntersector * _parent
Definition RayIntersector:117
void insertIntersection(const Intersection &intersection)
Definition RayIntersector:88
RayIntersector(CoordinateFrame cf, double x, double y)
RayIntersector(CoordinateFrame cf=MODEL, RayIntersector *parent=NULL, osgUtil::Intersector::IntersectionLimit intersectionLimit=osgUtil::Intersector::NO_LIMIT)
RayIntersector(CoordinateFrame cf, const osg::Vec3d &start, const osg::Vec3d &direction, RayIntersector *parent=NULL, osgUtil::Intersector::IntersectionLimit intersectionLimit=osgUtil::Intersector::NO_LIMIT)
std::multiset< Intersection > Intersections
Definition RayIntersector:86
virtual Intersector * clone(osgUtil::IntersectionVisitor &iv)
virtual void intersect(osgUtil::IntersectionVisitor &iv, osg::Drawable *drawable)
virtual void leave()
Intersections & getIntersections()
Definition RayIntersector:89
virtual bool containsIntersections()
Definition RayIntersector:110
virtual bool intersects(const osg::BoundingSphere &bs)
const osg::Vec3d & getStart() const
Definition RayIntersector:93
Definition BoundingBox:34
Definition BoundingSphere:35
Definition Drawable:89
static Vec3f transform3x3(const Vec3f &v, const Matrixd &m)
Definition Matrixd:665
static Matrixd inverse(const Matrixd &matrix)
Definition Matrixd:536
Definition Node:72
Definition Texture:422
Definition Vec3d:30
Definition Vec3f:29
Definition ref_ptr:32
bool valid() const
Definition ref_ptr:120
Shader generator framework.
Definition NodeVisitor:25
std::vector< Node * > NodePath
Definition Node:47
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40
#define NULL
Definition osg/Export:55
Definition RayIntersector:56
osg::ref_ptr< osg::RefMatrix > matrix
Definition RayIntersector:67
osg::Vec3d getWorldIntersectPoint() const
Definition RayIntersector:75
std::vector< double > RatioList
Definition RayIntersector:62
double distance
Definition RayIntersector:64
osg::Vec3d localIntersectionPoint
Definition RayIntersector:68
RatioList ratioList
Definition RayIntersector:71
osg::NodePath nodePath
Definition RayIntersector:65
const osg::Vec3 & getLocalIntersectNormal() const
Definition RayIntersector:77
IndexList indexList
Definition RayIntersector:70
osg::Texture * getTextureLookUp(osg::Vec3 &tc) const
osg::ref_ptr< osg::Drawable > drawable
Definition RayIntersector:66
osg::Vec3 getWorldIntersectNormal() const
Definition RayIntersector:78
const osg::Vec3d & getLocalIntersectPoint() const
Definition RayIntersector:74
std::vector< unsigned int > IndexList
Definition RayIntersector:61
unsigned int primitiveIndex
Definition RayIntersector:72
osg::Vec3 localIntersectionNormal
Definition RayIntersector:69
Intersection()
Definition RayIntersector:57