Added osgUtil::IntersectorGroup to handle groups of osgUtil::Intersectors
This commit is contained in:
@@ -33,29 +33,40 @@ class Intersector : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
Intersector():
|
||||
_disabledCount(0) {}
|
||||
|
||||
virtual Intersector* clone(osgUtil::IntersectionVisitor& iv) = 0;
|
||||
|
||||
virtual void merge(Intersector* intersector) = 0;
|
||||
|
||||
virtual bool enter(const osg::Node& node) = 0;
|
||||
|
||||
virtual void leave() = 0;
|
||||
|
||||
virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable) = 0;
|
||||
|
||||
virtual void reset() = 0;
|
||||
virtual void reset() { _disabledCount = 0; }
|
||||
|
||||
virtual bool containsIntersections() = 0;
|
||||
|
||||
inline bool disabled() const { return _disabledCount!=0; }
|
||||
|
||||
inline void incrementDisabledCount() { ++_disabledCount; }
|
||||
|
||||
inline void decrementDisabledCount() { if (_disabledCount>0) --_disabledCount; }
|
||||
|
||||
protected:
|
||||
|
||||
unsigned int _disabledCount;
|
||||
|
||||
};
|
||||
|
||||
/** Concrent class for implementing line intersections with the scene graph.
|
||||
* To be used in conjunction with IntersectionVisitor. */
|
||||
class LineSegmentIntersector : public Intersector
|
||||
class OSGUTIL_EXPORT LineSegmentIntersector : public Intersector
|
||||
{
|
||||
public:
|
||||
|
||||
LineSegmentIntersector(const osg::Vec3d& start, const osg::Vec3d& end);
|
||||
LineSegmentIntersector(const osg::Vec3d& start, const osg::Vec3d& end, LineSegmentIntersector* parent=0);
|
||||
|
||||
struct Intersection
|
||||
{
|
||||
@@ -75,14 +86,15 @@ class LineSegmentIntersector : public Intersector
|
||||
|
||||
typedef std::multiset<Intersection> Intersections;
|
||||
|
||||
Intersections& getIntersections() { return _intersections; }
|
||||
inline void insertIntersection(const Intersection& intersection) { getIntersections().insert(intersection); }
|
||||
|
||||
inline Intersections& getIntersections() { return _parent ? _parent->_intersections : _intersections; }
|
||||
|
||||
|
||||
public:
|
||||
|
||||
virtual Intersector* clone(osgUtil::IntersectionVisitor& iv);
|
||||
|
||||
virtual void merge(Intersector* intersector);
|
||||
|
||||
virtual bool enter(const osg::Node& node);
|
||||
|
||||
virtual void leave();
|
||||
@@ -98,6 +110,8 @@ class LineSegmentIntersector : public Intersector
|
||||
bool intersects(const osg::BoundingSphere& bs);
|
||||
bool intersectAndClip(osg::Vec3d& s, osg::Vec3d& e,const osg::BoundingBox& bb);
|
||||
|
||||
LineSegmentIntersector* _parent;
|
||||
|
||||
osg::Vec3d _start;
|
||||
osg::Vec3d _end;
|
||||
|
||||
@@ -105,6 +119,45 @@ class LineSegmentIntersector : public Intersector
|
||||
|
||||
};
|
||||
|
||||
/** Concrent class for passing multiple intersectors through the scene graph.
|
||||
* To be used in conjunction with IntersectionVisitor. */
|
||||
class OSGUTIL_EXPORT IntersectorGroup : public Intersector
|
||||
{
|
||||
public:
|
||||
|
||||
IntersectorGroup();
|
||||
|
||||
/** Add an Intersector. */
|
||||
void addIntersector(Intersector* intersector);
|
||||
|
||||
typedef std::vector< osg::ref_ptr<Intersector> > Intersectors;
|
||||
|
||||
/** Get the list of intersector. */
|
||||
Intersectors& getIntersectors() { return _intersectors; }
|
||||
|
||||
/** Clear the list of intersectors.*/
|
||||
void clear();
|
||||
|
||||
public:
|
||||
|
||||
virtual Intersector* clone(osgUtil::IntersectionVisitor& iv);
|
||||
|
||||
virtual bool enter(const osg::Node& node);
|
||||
|
||||
virtual void leave();
|
||||
|
||||
virtual void intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable);
|
||||
|
||||
virtual void reset();
|
||||
|
||||
virtual bool containsIntersections();
|
||||
|
||||
protected:
|
||||
|
||||
Intersectors _intersectors;
|
||||
|
||||
};
|
||||
|
||||
/** InteresectionVisitor is used to testing for intersections with the scene, traversing the scene using generic osgUtil::Intersector's to test against the scene.
|
||||
* To implement different types of intersection techniques, one implements custom versions of the osgUtil::Intersector, and then
|
||||
* pass the constructed intersector to the IntersectionVisitor.*/
|
||||
@@ -170,7 +223,7 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
|
||||
inline void leave() { _intersectorStack.back()->leave(); }
|
||||
inline void intersect(osg::Drawable* drawable) { _intersectorStack.back()->intersect(*this, drawable); }
|
||||
inline void push_clone() { _intersectorStack.push_back ( _intersectorStack.front()->clone(*this) ); }
|
||||
inline void pop_clone() { if (_intersectorStack.size()>=2) { _intersectorStack.front()->merge(_intersectorStack.back().get()); _intersectorStack.pop_back(); } }
|
||||
inline void pop_clone() { if (_intersectorStack.size()>=2) _intersectorStack.pop_back(); }
|
||||
|
||||
typedef std::list< osg::ref_ptr<Intersector> > IntersectorStack;
|
||||
IntersectorStack _intersectorStack;
|
||||
|
||||
Reference in New Issue
Block a user