Moved the PickVisitor from osgUtil into the implementation of

osgProducer::Viewer.  Removed methods in PickVisitor which wern't being
used by osgProducer::Viewer.  This has been done because the PickVisitor
interface and implementation weren't ready for general usage.
This commit is contained in:
Robert Osfield
2003-04-16 15:14:25 +00:00
parent 2e659c9ebf
commit 3bd03476f4
3 changed files with 106 additions and 7 deletions

View File

@@ -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

View File

@@ -2,7 +2,6 @@
#include <osg/ApplicationUsage>
#include <osgUtil/UpdateVisitor>
#include <osgUtil/PickVisitor>
#include <osgDB/Registry>
@@ -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<osg::LineSegment> _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; i<pr.getNumChildren(); i++)
{
osg::Node *nodech=pr.getChild(i);
osgUtil::IntersectVisitor::HitList &hli=_piv.getIntersections(nodech,npt, farpt);
for(osgUtil::IntersectVisitor::HitList::iterator hitr=hli.begin();
hitr!=hli.end();
++hitr)
{ // add the projection hits to the scene hits.
// This is why _lineSegment is retained as a member of PickIntersectVisitor
_PIVsegHitList.push_back(*hitr);
}
traverse(*nodech);
}
}
osgUtil::IntersectVisitor::HitList& getHits(osg::Node *node, const osg::Vec3& near_point, const osg::Vec3& far_point)
{
// High level get intersection with sceneview using a ray from x,y on the screen
// sets xp,yp as pixels scaled to a mapping of (-1,1, -1,1); needed for Projection from x,y pixels
// first get the standard hits in un-projected nodes
_PIVsegHitList=_piv.getIntersections(node,near_point,far_point); // fill hitlist
// then get hits in projection nodes
traverse(*node); // check for projection nodes
return _PIVsegHitList;
}
osgUtil::IntersectVisitor::HitList& getHits(osg::Node *node, const osg::Matrix &projm, const float x, const float y)
{
// utility for non=sceneview viewers
// x,y are values returned by
osg::Matrix inverseMVPW;
inverseMVPW.invert(projm);
osg::Vec3 near_point = osg::Vec3(x,y,1.0f)*inverseMVPW;
osg::Vec3 far_point = osg::Vec3(x,y,-1.0f)*inverseMVPW;
setxy(x,y);
getHits(node,near_point,far_point);
return _PIVsegHitList;
}
inline void setxy(float xpt, float ypt) { xp=xpt; yp=ypt; }
inline bool hits() const { return _PIVsegHitList.size()>0;}
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);

View File

@@ -9,7 +9,6 @@ CXXFILES = \
DisplayRequirementsVisitor.cpp\
InsertImpostorsVisitor.cpp\
IntersectVisitor.cpp\
PickVisitor.cpp\
Optimizer.cpp\
RenderBin.cpp\
RenderGraph.cpp\