From 1c91b505dd05b5e742821008f1a83833a6efdbfa Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 2 Nov 2006 15:22:38 +0000 Subject: [PATCH] Fixed bug in Polytope::contains(const std::vector& vertices) which resulted in false positives. --- include/osg/Polytope | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/include/osg/Polytope b/include/osg/Polytope index cf2a256ad..b41b07470 100644 --- a/include/osg/Polytope +++ b/include/osg/Polytope @@ -200,21 +200,25 @@ class OSG_EXPORT Polytope if (!_maskStack.back()) return true; _resultMask = _maskStack.back(); - ClippingMask selector_mask = 0x1; - for(PlaneList::const_iterator itr=_planeList.begin(); - itr!=_planeList.end(); - ++itr) + for(std::vector::const_iterator vitr = vertices.begin(); + vitr != vertices.end(); + ++vitr) { - if (_resultMask&selector_mask) + const osg::Vec3& v = *vitr; + bool outside = false; + ClippingMask selector_mask = 0x1; + for(PlaneList::const_iterator itr=_planeList.begin(); + itr!=_planeList.end() && !outside; + ++itr) { - int res=itr->intersect(vertices); - if (res<0) return false; // outside clipping set. - else if (res>0) _resultMask ^= selector_mask; // subsequent checks against this plane not required. + if ((_maskStack.back()&selector_mask) && (itr->distance(v)<0.0f)) outside = true; + selector_mask <<= 1; } - selector_mask <<= 1; + + if (!outside) return true; } - return true; + return false; } /** Check whether any part of a bounding sphere is contained within clipping set.