From b50ac89b9d61642bcba3f8a84b142f1f10636ef8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 22 Aug 2005 14:07:47 +0000 Subject: [PATCH] From Domenico Mangieri: "I've added a Plane constructor which accepts a normal and a point. I also removed calculateUpperLowerBBCorners() from the Plane(const Vec3& v1, const Vec3& v2, const Vec3& v3) since the constructor is using the function set(const Vec3& v1, const Vec3& v2, const Vec3& v3) which already computes the upper and lower bounding box." --- include/osg/Plane | 65 ++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/include/osg/Plane b/include/osg/Plane index 053eae247..c289348bb 100644 --- a/include/osg/Plane +++ b/include/osg/Plane @@ -31,13 +31,14 @@ class OSG_EXPORT Plane public: - inline Plane():_fv(0.0f,0.0f,0.0f,0.0f) { _lowerBBCorner = 0; _upperBBCorner = 0; } - inline Plane(const Plane& pl):_fv(pl._fv) { calculateUpperLowerBBCorners(); } - inline Plane(float a,float b,float c,float d):_fv(a,b,c,d) { calculateUpperLowerBBCorners(); } - inline Plane(const Vec4& vec):_fv(vec) { calculateUpperLowerBBCorners(); } - inline Plane(const Vec3& norm,float d):_fv(norm[0],norm[1],norm[2],d) { calculateUpperLowerBBCorners(); } - inline Plane(const Vec3& v1, const Vec3& v2, const Vec3& v3) { set(v1,v2,v3); calculateUpperLowerBBCorners(); } - + inline Plane():_fv(0.0f,0.0f,0.0f,0.0f) { _lowerBBCorner = 0; _upperBBCorner = 0; } + inline Plane(const Plane& pl):_fv(pl._fv) { calculateUpperLowerBBCorners(); } + inline Plane(float a,float b,float c,float d):_fv(a,b,c,d) { calculateUpperLowerBBCorners(); } + inline Plane(const Vec4& vec):_fv(vec) { calculateUpperLowerBBCorners(); } + inline Plane(const Vec3& norm,float d):_fv(norm[0],norm[1],norm[2],d) { calculateUpperLowerBBCorners(); } + inline Plane(const Vec3& v1, const Vec3& v2, const Vec3& v3) { set(v1,v2,v3); } + inline Plane(const Vec3& norm, const Vec3& point) { set(norm,point); } + inline Plane& operator = (const Plane& pl) { if (&pl==this) return *this; @@ -47,10 +48,10 @@ class OSG_EXPORT Plane return *this; } - inline void set(const Plane& pl) { _fv = pl._fv; calculateUpperLowerBBCorners(); } - inline void set(float a,float b,float c,float d) { _fv.set(a,b,c,d); calculateUpperLowerBBCorners(); } - inline void set(const Vec4& vec) { _fv = vec; calculateUpperLowerBBCorners(); } - inline void set(const Vec3& norm,float d) { _fv.set(norm[0],norm[1],norm[2],d); calculateUpperLowerBBCorners(); } + inline void set(const Plane& pl) { _fv = pl._fv; calculateUpperLowerBBCorners(); } + inline void set(float a,float b,float c,float d) { _fv.set(a,b,c,d); calculateUpperLowerBBCorners(); } + inline void set(const Vec4& vec) { _fv = vec; calculateUpperLowerBBCorners(); } + inline void set(const Vec3& norm,float d) { _fv.set(norm[0],norm[1],norm[2],d); calculateUpperLowerBBCorners(); } inline void set(const Vec3& v1, const Vec3& v2, const Vec3& v3) { osg::Vec3 norm = (v2-v1)^(v3-v2); @@ -60,7 +61,7 @@ class OSG_EXPORT Plane _fv.set(norm[0],norm[1],norm[2],-(v1*norm)); calculateUpperLowerBBCorners(); } - + inline void set(const Vec3& norm, const Vec3& point) { float d = -norm[0]*point[0] - norm[1]*point[1] - norm[2]*point[2]; @@ -100,20 +101,20 @@ class OSG_EXPORT Plane inline bool operator != (const Plane& plane) const { return _fv!=plane._fv; } inline bool operator < (const Plane& plane) const { return _fv& vertices) const { if (vertices.empty()) return -1; - + int noAbove = 0; int noBelow = 0; int noOn = 0; @@ -142,7 +143,7 @@ class OSG_EXPORT Plane else if (d<0.0f) ++noBelow; else ++noOn; } - + if (noAbove>0) { if (noBelow>0) return 0; @@ -158,29 +159,29 @@ class OSG_EXPORT Plane inline int intersect(const BoundingSphere& bs) const { float d = distance(bs.center()); - + if (d>bs.radius()) return 1; else if (d<-bs.radius()) return -1; else return 0; } - - + + /** 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 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; - + } /** Transform the plane by matrix. Note, this operation carries out @@ -195,7 +196,7 @@ class OSG_EXPORT Plane inverse.invert(matrix); transformProvidingInverse(inverse); } - + /** Transform the plane by providing a pre inverted matrix. * see transform for details. */ inline void transformProvidingInverse(const osg::Matrix& matrix) @@ -208,8 +209,8 @@ class OSG_EXPORT Plane protected: - Vec4 _fv; - + Vec4 _fv; + // variables cached to optimize calcs against bounding boxes. unsigned int _upperBBCorner; unsigned int _lowerBBCorner; @@ -217,6 +218,6 @@ class OSG_EXPORT Plane }; -} // end of namespace +} // end of namespace #endif