Added beginnings of osgUtil::PlaneIntersector and osgSim::ElevationSlice
This commit is contained in:
@@ -512,7 +512,7 @@ bool LineSegmentIntersector::intersectAndClip(osg::Vec3d& s, osg::Vec3d& e,const
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IntersectorGroup
|
||||
// PolytopeIntersector
|
||||
//
|
||||
PolytopeIntersector::PolytopeIntersector(const osg::Polytope& polytope):
|
||||
_parent(0),
|
||||
@@ -629,6 +629,105 @@ void PolytopeIntersector::reset()
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PlaneIntersector
|
||||
//
|
||||
PlaneIntersector::PlaneIntersector(const osg::Plane& plane, const osg::Polytope& boundingPolytope):
|
||||
_parent(0),
|
||||
_plane(plane),
|
||||
_polytope(boundingPolytope)
|
||||
{
|
||||
}
|
||||
|
||||
PlaneIntersector::PlaneIntersector(CoordinateFrame cf, const osg::Plane& plane, const osg::Polytope& boundingPolytope):
|
||||
Intersector(cf),
|
||||
_parent(0),
|
||||
_plane(plane),
|
||||
_polytope(boundingPolytope)
|
||||
{
|
||||
}
|
||||
|
||||
Intersector* PlaneIntersector::clone(osgUtil::IntersectionVisitor& iv)
|
||||
{
|
||||
if (_coordinateFrame==MODEL && iv.getModelMatrix()==0)
|
||||
{
|
||||
osg::ref_ptr<PlaneIntersector> pi = new PlaneIntersector(_plane, _polytope);
|
||||
pi->_parent = this;
|
||||
return pi.release();
|
||||
}
|
||||
|
||||
// compute the matrix that takes this Intersector from its CoordinateFrame into the local MODEL coordinate frame
|
||||
// that geometry in the scene graph will always be in.
|
||||
osg::Matrix matrix;
|
||||
switch (_coordinateFrame)
|
||||
{
|
||||
case(WINDOW):
|
||||
if (iv.getWindowMatrix()) matrix.preMult( *iv.getWindowMatrix() );
|
||||
if (iv.getProjectionMatrix()) matrix.preMult( *iv.getProjectionMatrix() );
|
||||
if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
|
||||
if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
|
||||
break;
|
||||
case(PROJECTION):
|
||||
if (iv.getProjectionMatrix()) matrix.preMult( *iv.getProjectionMatrix() );
|
||||
if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
|
||||
if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
|
||||
break;
|
||||
case(VIEW):
|
||||
if (iv.getViewMatrix()) matrix.preMult( *iv.getViewMatrix() );
|
||||
if (iv.getModelMatrix()) matrix.preMult( *iv.getModelMatrix() );
|
||||
break;
|
||||
case(MODEL):
|
||||
if (iv.getModelMatrix()) matrix = *iv.getModelMatrix();
|
||||
break;
|
||||
}
|
||||
|
||||
osg::Plane plane = _plane;
|
||||
plane.transformProvidingInverse(matrix);
|
||||
|
||||
osg::Polytope transformedPolytope;
|
||||
transformedPolytope.setAndTransformProvidingInverse(_polytope, matrix);
|
||||
|
||||
osg::ref_ptr<PlaneIntersector> pi = new PlaneIntersector(plane, transformedPolytope);
|
||||
pi->_parent = this;
|
||||
return pi.release();
|
||||
}
|
||||
|
||||
bool PlaneIntersector::enter(const osg::Node& node)
|
||||
{
|
||||
return !node.isCullingActive() ||
|
||||
( _plane.intersect(node.getBound()) && _polytope.contains(node.getBound()) );
|
||||
}
|
||||
|
||||
|
||||
void PlaneIntersector::leave()
|
||||
{
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
|
||||
void PlaneIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable)
|
||||
{
|
||||
if ( !_plane.intersect( drawable->getBound() ) ) return;
|
||||
if ( !_polytope.contains( drawable->getBound() ) ) return;
|
||||
|
||||
Intersection hit;
|
||||
hit.nodePath = iv.getNodePath();
|
||||
hit.drawable = drawable;
|
||||
|
||||
insertIntersection(hit);
|
||||
}
|
||||
|
||||
|
||||
void PlaneIntersector::reset()
|
||||
{
|
||||
Intersector::reset();
|
||||
|
||||
_intersections.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IntersectorGroup
|
||||
|
||||
Reference in New Issue
Block a user