diff --git a/VisualStudio/osgUtil/osgUtil.dsp b/VisualStudio/osgUtil/osgUtil.dsp index 42430f529..9a7c0171b 100755 --- a/VisualStudio/osgUtil/osgUtil.dsp +++ b/VisualStudio/osgUtil/osgUtil.dsp @@ -97,10 +97,6 @@ SOURCE=..\..\src\osgUtil\CubeMapGenerator.cpp # End Source File # Begin Source File -SOURCE=..\..\src\osgUtil\PickVisitor.cpp -# End Source File -# Begin Source File - SOURCE=..\..\src\osgUtil\HalfWayMapGenerator.cpp # End Source File # Begin Source File diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index fd651582f..303c3fdff 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -2,7 +2,6 @@ #include #include -#include #include @@ -18,7 +17,112 @@ using namespace Producer; using namespace osgProducer; +////////////////////////////////////////////////////////////////////////////// +// +// Picking intersection visitor. +// +class PickIntersectVisitor : public osgUtil::IntersectVisitor +{ +public: + PickIntersectVisitor() + { + setNodeMaskOverride(0xffffffff); // need to make the visitor override the nodemask to visit invisible actions + } + virtual ~PickIntersectVisitor() {} + + HitList& getIntersections(osg::Node *scene, osg::Vec3 nr, osg::Vec3 fr) + { + // option for non-sceneView users: you need to get the screen perp line and call getIntersections + // if you are using Projection nodes you should also call setxy to define the xp,yp positions for use with + // the ray transformed by Projection + _lineSegment = new osg::LineSegment; + _lineSegment->set(nr,fr); // make a line segment + addLineSegment(_lineSegment.get()); + + scene->accept(*this); + return getHitList(_lineSegment.get()); + } +private: + osg::ref_ptr _lineSegment; + friend class osgUtil::IntersectVisitor; +}; + +// PickVisitor traverses whole scene and checks below all Projection nodes +class PickVisitor : public osg::NodeVisitor +{ +public: + 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() {} + + virtual void apply(osg::Projection& pr) + { // stack the intersect rays, transform to new projection, traverse + // Assumes that the Projection is an absolute projection + osg::Matrix mt; + mt.invert(pr.getMatrix()); + osg::Vec3 npt=osg::Vec3(xp,yp,1.0f) * mt, farpt=osg::Vec3(xp,yp,-1.0f) * mt; + + // traversing the nodes children, using the projection direction + for (unsigned int i=0; i0;} + +private: + + PickIntersectVisitor _piv; + float xp, yp; // start point in viewport fraction coordiantes + osgUtil::IntersectVisitor::HitList _PIVsegHitList; +}; + +////////////////////////////////////////////////////////////////////////////// +// +// osgProducer::Viewer implemention +// Viewer::Viewer(): _done(0), _frameNumber(0), @@ -386,7 +490,7 @@ bool Viewer::computeIntersections(float x,float y,unsigned int cameraNum,osgUtil osg::Matrix(camera->getProjectionMatrix())); } - osgUtil::PickVisitor iv; + PickVisitor iv; osgUtil::IntersectVisitor::HitList localHits; localHits = iv.getHits(getSceneData(), vum, rx,ry); diff --git a/src/osgUtil/GNUmakefile b/src/osgUtil/GNUmakefile index 498efc166..346c429fc 100644 --- a/src/osgUtil/GNUmakefile +++ b/src/osgUtil/GNUmakefile @@ -9,7 +9,6 @@ CXXFILES = \ DisplayRequirementsVisitor.cpp\ InsertImpostorsVisitor.cpp\ IntersectVisitor.cpp\ - PickVisitor.cpp\ Optimizer.cpp\ RenderBin.cpp\ RenderGraph.cpp\