Merge pull request #2696 from akortunov/intersector

Fix LineSegmentIntersector usage
pull/2697/head
Alexei Dobrohotov 5 years ago committed by GitHub
commit 54e7e0c718
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -150,12 +150,12 @@ void QuadTreeNode::traverseTo(ViewData* vd, float size, const osg::Vec2f& center
}
}
void QuadTreeNode::intersect(ViewData* vd, TerrainLineIntersector* intersector)
void QuadTreeNode::intersect(ViewData* vd, TerrainLineIntersector& intersector)
{
if (!hasValidBounds())
return;
if (!intersector->intersectAndClip(getBoundingBox()))
if (!intersector.intersectAndClip(getBoundingBox()))
return;
if (getNumChildren() == 0)

@ -20,6 +20,14 @@ namespace Terrain
_parent = intersector;
}
TerrainLineIntersector(osgUtil::LineSegmentIntersector* intersector) :
osgUtil::LineSegmentIntersector(intersector->getStart(), intersector->getEnd())
{
setPrecisionHint(intersector->getPrecisionHint());
_intersectionLimit = intersector->getIntersectionLimit();
_parent = intersector;
}
bool intersectAndClip(const osg::BoundingBox& bbInput)
{
osg::Vec3d s(_start), e(_end);
@ -98,7 +106,7 @@ namespace Terrain
void traverseTo(ViewData* vd, float size, const osg::Vec2f& center);
/// Adds all leaf nodes which intersect the line from start to end
void intersect(ViewData* vd, TerrainLineIntersector* intersector);
void intersect(ViewData* vd, TerrainLineIntersector& intersector);
private:
QuadTreeNode* mParent;

@ -362,11 +362,17 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv)
if (!lineIntersector)
throw std::runtime_error("Cannot update QuadTreeWorld: node visitor is not LineSegmentIntersector");
osg::Matrix matrix = osg::Matrix::identity();
if (lineIntersector->getCoordinateFrame() == osgUtil::Intersector::CoordinateFrame::MODEL && iv->getModelMatrix() == 0)
matrix = lineIntersector->getTransformation(*iv, osgUtil::Intersector::CoordinateFrame::MODEL);
osg::ref_ptr<TerrainLineIntersector> terrainIntersector (new TerrainLineIntersector(lineIntersector, matrix));
mRootNode->intersect(vd, terrainIntersector);
{
TerrainLineIntersector terrainIntersector(lineIntersector);
mRootNode->intersect(vd, terrainIntersector);
}
else
{
osg::Matrix matrix(lineIntersector->getTransformation(*iv, lineIntersector->getCoordinateFrame()));
TerrainLineIntersector terrainIntersector(lineIntersector, matrix);
mRootNode->intersect(vd, terrainIntersector);
}
}
}

Loading…
Cancel
Save