Hi Tanguy, What makes you think its wrong ? I think its very smart code which does only whats really neccessary. _lowerBBCorner and _upperBBCorner are not constant and in fact are relative and precalculated based on plane orientation. Depending on the plane orientation its possible to know before hand which corners of axis aligned bounding box will represent most extreme points of the box.
Cheers, Wojtek ----- Original Message ----- From: Tanguy Fautre To: OpenSceneGraph Users Sent: Monday, October 19, 2009 3:25 PM Subject: [osg-users] Plane::intersect(BoundingBox & box) buggy ? Hi, I've used an osg::Polytope to test whether a given convex volume was colliding against a BoundingBox. Unfortunately it wouldn't work. I've tracked the problem down to Plane::intersect(). /** intersection test between plane and bounding sphere. 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 BoundingBox& bb) const { // if lowest point above plane than all above. if (distance(bb.corner(_lowerBBCorner))>0.0f) return 1; // if highest point is below plane then all below. if (distance(bb.corner(_upperBBCorner))<0.0f) return -1; // d_lower<=0.0f && d_upper>=0.0f // therefore must be crossing plane. return 0; } The piece of code above assumes that the plane is axis aligned and that the normal is pointing toward the positive part of the axis. Such an assumption is wrong for most other planes, and certainly does break osg::Polytope implementation (from what I understand). I had to bypass it with the following (note that in my case I only needed a Boolean returned value). bool intersect(const osg::Plane & plane, const osg::BoundingBox & bb) { if (plane.distance(osg::Vec3(bb.xMin(), bb.yMin(), bb.zMin())) <= 0) return true; if (plane.distance(osg::Vec3(bb.xMin(), bb.yMin(), bb.zMax())) <= 0) return true; if (plane.distance(osg::Vec3(bb.xMin(), bb.yMax(), bb.zMin())) <= 0) return true; if (plane.distance(osg::Vec3(bb.xMin(), bb.yMax(), bb.zMax())) <= 0) return true; if (plane.distance(osg::Vec3(bb.xMax(), bb.yMin(), bb.zMin())) <= 0) return true; if (plane.distance(osg::Vec3(bb.xMax(), bb.yMin(), bb.zMax())) <= 0) return true; if (plane.distance(osg::Vec3(bb.xMax(), bb.yMax(), bb.zMin())) <= 0) return true; if (plane.distance(osg::Vec3(bb.xMax(), bb.yMax(), bb.zMax())) <= 0) return true; return false; } I wonder whether the OSG implementation is limited on purpose (in which case it should be documented), or whether this is a real bug. Cheers, Tanguy ------------------------------------------------------------------------------ _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org