2003-04-13 21:26:41 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
// PickIntersectVisitor == Pick visitor - used for screen based picking
|
|
|
|
// based on osgUtil::IntersectVisitor BUT
|
|
|
|
// traversing into Projection Nodes using the modified projections.
|
|
|
|
// also supplies high level intersector for 'what is under a pixel in a sceneview'
|
|
|
|
// GWM Feb 2003.
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef OSGUTIL_PICKINTERSECTVISITOR
|
|
|
|
#define OSGUTIL_PICKINTERSECTVISITOR 1
|
|
|
|
|
|
|
|
#include <osgUtil/IntersectVisitor>
|
|
|
|
#include <osgUtil/SceneView>
|
|
|
|
|
|
|
|
namespace osgUtil {
|
|
|
|
|
|
|
|
// PickIntersectVisitor simplifies picking - routines take x,y mouse pixel & detect hits
|
2003-04-14 23:44:30 +08:00
|
|
|
class OSGUTIL_EXPORT PickIntersectVisitor : public IntersectVisitor
|
|
|
|
{
|
2003-04-13 21:26:41 +08:00
|
|
|
public:
|
2003-04-14 23:44:30 +08:00
|
|
|
PickIntersectVisitor()
|
|
|
|
{
|
|
|
|
setNodeMaskOverride(0xffffffff); // need to make the visitor override the nodemask to visit invisible actions
|
|
|
|
}
|
|
|
|
~PickIntersectVisitor() { }
|
|
|
|
HitList& getHits(osgUtil::SceneView *, int x, int y);
|
|
|
|
HitList& PickIntersectVisitor::getIntersections(osg::Node *scene, osg::Vec3 nr, osg::Vec3 fr);
|
2003-04-13 21:26:41 +08:00
|
|
|
private:
|
2003-04-14 23:44:30 +08:00
|
|
|
osg::ref_ptr<osg::LineSegment> _lineSegment;
|
2003-04-13 21:26:41 +08:00
|
|
|
friend class osgUtil::IntersectVisitor;
|
|
|
|
};
|
|
|
|
|
|
|
|
// PickVisitor traverses whole scene and checks below all Projection nodes
|
2003-04-14 23:44:30 +08:00
|
|
|
class OSGUTIL_EXPORT PickVisitor : public osg::NodeVisitor
|
|
|
|
{
|
2003-04-13 21:26:41 +08:00
|
|
|
public:
|
2003-04-14 23:44:30 +08:00
|
|
|
PickVisitor()
|
|
|
|
{
|
|
|
|
xp=yp=0;
|
|
|
|
setNodeMaskOverride(0xffffffff); // need to make the visitor override the nodemask to visit invisible actions
|
|
|
|
setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
|
|
|
|
}
|
|
|
|
~PickVisitor() { }
|
2003-04-13 21:26:41 +08:00
|
|
|
virtual void apply(osg::Projection& pr);
|
2003-04-14 23:44:30 +08:00
|
|
|
osgUtil::IntersectVisitor::HitList& getHits(osg::Node *nd, const osg::Matrix &projm, const float x, const float y);
|
|
|
|
osgUtil::IntersectVisitor::HitList& getHits(osgUtil::SceneView *, double x, double y);
|
|
|
|
osgUtil::IntersectVisitor::HitList & getHits(osg::Node *nd, const osg::Vec3 near_point, const osg::Vec3 far_point);
|
|
|
|
osgUtil::IntersectVisitor::HitList& getHits(void);
|
|
|
|
inline void setxy(float xpt, float ypt) { xp=xpt; yp=ypt; }
|
|
|
|
inline bool hits() { return _PIVsegHitList.size()>0;}
|
2003-04-13 21:26:41 +08:00
|
|
|
private:
|
2003-04-14 23:44:30 +08:00
|
|
|
PickIntersectVisitor _piv;
|
|
|
|
float xp, yp; // start point in viewport fraction coordiantes
|
2003-04-13 21:26:41 +08:00
|
|
|
osgUtil::IntersectVisitor::HitList _PIVsegHitList;
|
|
|
|
};
|
|
|
|
}// namespace osgUtil
|
|
|
|
|
2003-04-14 23:44:30 +08:00
|
|
|
#endif // match OSGUTIL_PICKINTERSECTVISITOR
|