diff --git a/components/terrain/quadtreenode.cpp b/components/terrain/quadtreenode.cpp index 7583cd09ff..a28554be94 100644 --- a/components/terrain/quadtreenode.cpp +++ b/components/terrain/quadtreenode.cpp @@ -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) diff --git a/components/terrain/quadtreenode.hpp b/components/terrain/quadtreenode.hpp index 9aaf1beab7..4adbc60250 100644 --- a/components/terrain/quadtreenode.hpp +++ b/components/terrain/quadtreenode.hpp @@ -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; diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index e8089e1c4d..8dd3a07061 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -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 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); + } } }