From 941ec1e4514d819b246232dd09f40eb18a8131d5 Mon Sep 17 00:00:00 2001 From: "Konstantin S. Matveyev" Date: Fri, 22 Sep 2017 11:38:43 +0300 Subject: [PATCH] LineSegmentIntersector fixed: intersection ratio remaped to the range of LineSegment => correct order in multiset of intersections --- src/osgUtil/LineSegmentIntersector.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/osgUtil/LineSegmentIntersector.cpp b/src/osgUtil/LineSegmentIntersector.cpp index 5a6b69afe..08faade5e 100644 --- a/src/osgUtil/LineSegmentIntersector.cpp +++ b/src/osgUtil/LineSegmentIntersector.cpp @@ -299,13 +299,17 @@ struct IntersectFunctor return; } - Vec3 in = v0*r0 + v1*r1 + v2*r2; + // Remap ratio into the range of LineSegment + const osg::Vec3d& lsStart = _settings->_lineSegIntersector->getStart(); + const osg::Vec3d& lsEnd = _settings->_lineSegIntersector->getEnd(); + double remap_ratio = ((_start - lsStart).length() + r*_length)/(lsEnd - lsStart).length(); + + Vec3 in = lsStart*(1.0 - remap_ratio) + lsEnd*remap_ratio; // == v0*r0 + v1*r1 + v2*r2; Vec3 normal = E1^E2; normal.normalize(); - LineSegmentIntersector::Intersection hit; - hit.ratio = r; + hit.ratio = remap_ratio; hit.matrix = _settings->_iv->getModelMatrix(); hit.nodePath = _settings->_iv->getNodePath(); hit.drawable = _settings->_drawable;