From 55de8b03d994b7b3f3a58a65b34963c402df7cbf Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 25 Feb 2008 14:15:27 +0000 Subject: [PATCH] From Wojciech Lewandowski, "----1---- Attached is a fixed version of OverlayNode.cpp. I fixed CustomPolytope::cut( osg::Plane ) method. Bug was apparent in such scenario: Let P1 be some random frustum polytope Let P2 be the polytope that was created from P1 bounding box (P2 contains P1 entirely) Then ignoring precision errors: P1.cut( P2 ) == P2.cut( P1 ) == P1. But this condition was not always met. Cut failed when some of the polytope reference points happened to lie exactly on some intersecting planes in both P1 & P2 (plane distance was = 0). I only use CustomPolytope for my shadowing stuff so I did not test how this affects rest of OverlayNode.cpp. ----2---- Also attached is a minor precision improvement for osg::Plane intersect method (double version). ----3---- I have also one observation regarding osg::Plane - There are two intersect vertices methods (float and double flavour): inline int intersect(const std::vector& vertices) const inline int intersect(const std::vector& vertices) const I guess osg::Plane won't compile when someone changes default vec3 typedef to vec3d. Shouldn't the first method be changed to use vec3f explicitly ? Ie: inline int intersect(const std::vector& vertices) const" --- include/osg/Plane | 10 +++++----- src/osgSim/OverlayNode.cpp | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/osg/Plane b/include/osg/Plane index c2b82765e..750ac4454 100644 --- a/include/osg/Plane +++ b/include/osg/Plane @@ -189,14 +189,14 @@ class OSG_EXPORT Plane return 1 if the bs is completely above plane, return 0 if the bs intersects the plane, return -1 if the bs is completely below the plane.*/ - inline int intersect(const std::vector& vertices) const + inline int intersect(const std::vector& vertices) const { if (vertices.empty()) return -1; int noAbove = 0; int noBelow = 0; int noOn = 0; - for(std::vector::const_iterator itr=vertices.begin(); + for(std::vector::const_iterator itr=vertices.begin(); itr != vertices.end(); ++itr) { @@ -229,9 +229,9 @@ class OSG_EXPORT Plane itr != vertices.end(); ++itr) { - float d = distance(*itr); - if (d>0.0f) ++noAbove; - else if (d<0.0f) ++noBelow; + double d = distance(*itr); + if (d>0.0) ++noAbove; + else if (d<0.0) ++noBelow; else ++noOn; } diff --git a/src/osgSim/OverlayNode.cpp b/src/osgSim/OverlayNode.cpp index e4d91fb81..a9f00933a 100644 --- a/src/osgSim/OverlayNode.cpp +++ b/src/osgSim/OverlayNode.cpp @@ -641,6 +641,9 @@ public: // is first edge point inside plane? if (distance_a>=0.0) newVertices.push_back(vertices[i]); + // add point to new face if point exactly on a plane + if (distance_a==0.0) newFace.vertices.push_back(vertices[i]); + // does edge intersect plane if (distance_a * distance_b<0.0) {