From 47efc556215b9e4ea353d4dd325b3788420cde5f Mon Sep 17 00:00:00 2001 From: blobfish Date: Mon, 29 May 2017 12:19:08 -0400 Subject: [PATCH] osgUtil: PolytopeIntersector: don't increment primitive index until after adding intersection --- src/osgUtil/PolytopeIntersector.cpp | 43 ++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/osgUtil/PolytopeIntersector.cpp b/src/osgUtil/PolytopeIntersector.cpp index 12c680145..ae0debacb 100644 --- a/src/osgUtil/PolytopeIntersector.cpp +++ b/src/osgUtil/PolytopeIntersector.cpp @@ -256,9 +256,11 @@ struct IntersectFunctor { if (_settings->_limitOneIntersection && _hit) return; - ++_primitiveIndex; - - if ((_settings->_primitiveMask&PolytopeIntersector::POINT_PRIMITIVES)==0) return; + if ((_settings->_primitiveMask&PolytopeIntersector::POINT_PRIMITIVES)==0) + { + ++_primitiveIndex; + return; + } // initialize the set of vertices to test. src.clear(); @@ -278,7 +280,11 @@ struct IntersectFunctor { const osg::Plane& plane=*pitr; double d1=plane.distance(v0); - if (d1<0.0) return; // point outside + if (d1<0.0) // point outside + { + ++_primitiveIndex; + return; + } } } } @@ -286,6 +292,8 @@ struct IntersectFunctor src.push_back(v0); addIntersection(); + + ++_primitiveIndex; } // handle lines @@ -293,9 +301,11 @@ struct IntersectFunctor { if (_settings->_limitOneIntersection && _hit) return; - ++_primitiveIndex; - - if ((_settings->_primitiveMask&PolytopeIntersector::LINE_PRIMITIVES)==0) return; + if ((_settings->_primitiveMask&PolytopeIntersector::LINE_PRIMITIVES)==0) + { + ++_primitiveIndex; + return; + } src.clear(); src.push_back(v0); @@ -305,6 +315,7 @@ struct IntersectFunctor { addIntersection(); } + ++_primitiveIndex; } // handle triangles @@ -312,9 +323,11 @@ struct IntersectFunctor { if (_settings->_limitOneIntersection && _hit) return; - ++_primitiveIndex; - - if ((_settings->_primitiveMask&PolytopeIntersector::TRIANGLE_PRIMITIVES)==0) return; + if ((_settings->_primitiveMask&PolytopeIntersector::TRIANGLE_PRIMITIVES)==0) + { + ++_primitiveIndex; + return; + } src.clear(); src.push_back(v0); @@ -326,15 +339,18 @@ struct IntersectFunctor { addIntersection(); } + ++_primitiveIndex; } void operator()(const osg::Vec3& v0, const osg::Vec3& v1, const osg::Vec3& v2, const osg::Vec3& v3, bool /*treatVertexDataAsTemporary*/) { if (_settings->_limitOneIntersection && _hit) return; - ++_primitiveIndex; - - if ((_settings->_primitiveMask&PolytopeIntersector::TRIANGLE_PRIMITIVES)==0) return; + if ((_settings->_primitiveMask&PolytopeIntersector::TRIANGLE_PRIMITIVES)==0) + { + ++_primitiveIndex; + return; + } src.clear(); @@ -348,6 +364,7 @@ struct IntersectFunctor { addIntersection(); } + ++_primitiveIndex; } void intersect(const osg::Vec3Array* vertices, int primitiveIndex, unsigned int p0)