From: Markus R. <rol...@us...> - 2006-02-22 22:54:51
|
Update of /cvsroot/simspark/simspark/spark/salt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27982 Modified Files: plane.h plane.cpp Log Message: - indentation Index: plane.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/salt/plane.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** plane.h 5 Dec 2005 20:56:00 -0000 1.1 --- plane.h 22 Feb 2006 22:54:46 -0000 1.2 *************** *** 43,111 **** enum EPlaneSide { ! PLANESIDE_BACK = 0, ! PLANESIDE_ONPLANE = 1, ! PLANESIDE_FRONT = 2, ! PLANESIDE_SPLIT = 3, ! PLANESIDE_FORCE_32BIT = 0xffffffff // used to force the enum to be 32-bit wide ! }; /** defines possible dominant plane values */ enum EPlane { ! PLANE_XY = 0, ! PLANE_XZ = 1, ! PLANE_YZ = 2, ! PLANE_FORCE_32BIT = 0xffffffff // used to force the enum to be 32-bit wide }; ! /** ! * A mathematical plane is modeled by this class. It can be used to ! * classify points against planes (in front, on plane, ! * etc...). Several useful functions for constructing a plane are ! * provided. A plane is defined by the formula. Ax+By+Cz+D=0. The ! * vector formed by the coefficients <A,B,C> is the normal vector to ! * the plane. ! */ class Plane { // Members public: /** the normal vector of the modeled plane */ ! Vector3f normal; /** the distance */ ! float d; // Methods public: /** empty constructor for an undefined plane */ ! f_inline Plane() {} // empty constructor ... performance /** constructs a plane from a normal and a point on the plane */ ! f_inline Plane(const Vector3f& norm, const Vector3f& pnt) { normal=norm; d=-((norm.x()*pnt.x()) + (norm.y()*pnt.y()) + (norm.z()*pnt.z())); } /** constructs a plane from normal and constant D. If normal is a * unit vector, then D is the distance to the origin */ ! f_inline Plane(const Vector3f& norm, const float D) { normal=norm; d=D; } /** constructs a plane from 3 distinct points */ ! f_inline Plane(const Vector3f& v1, const Vector3f &v2, const Vector3f &v3) { normal=(v2-v1).Cross(v3-v1).Normalized(); d=-normal.Dot(v1); } // inline functions /** calculates the orientation of v to the plane */ ! f_inline EPlaneSide GetOrientation(const Vector3f &v, float delta=0.0001f) const { float dist=normal.Dot(v)+d; if (dist<-delta) return PLANESIDE_BACK; if (dist>delta) return PLANESIDE_FRONT; return PLANESIDE_ONPLANE; } /** calculates the dominant plane */ ! f_inline EPlane GetDominantPlane() const { return (gAbs(normal.y()) > gAbs(normal.x()) ? (gAbs(normal.z()) > gAbs(normal.y()) ? PLANE_XY : PLANE_XZ) : (gAbs(normal.z()) > gAbs(normal.x()) ? PLANE_XY : PLANE_YZ)); } /** calculates the distance from v to the plane */ ! f_inline float GetDistanceTo(const Vector3f &v) const { return normal.Dot(v) + d; } - /** calculates the relationship between the plane and the box */ EPlaneSide ClassifyBox(const AABB3& bb) const; --- 43,146 ---- enum EPlaneSide { ! PLANESIDE_BACK = 0, ! PLANESIDE_ONPLANE = 1, ! PLANESIDE_FRONT = 2, ! PLANESIDE_SPLIT = 3, + // used to force the enum to be 32-bit wide + PLANESIDE_FORCE_32BIT = 0xffffffff + }; /** defines possible dominant plane values */ enum EPlane { ! PLANE_XY = 0, ! PLANE_XZ = 1, ! PLANE_YZ = 2, ! ! // used to force the enum to be 32-bit wide ! PLANE_FORCE_32BIT = 0xffffffff }; ! /** A mathematical plane is modeled by this class. It can be used to ! classify points against planes (in front, on plane, ! etc...). Several useful functions for constructing a plane are ! provided. A plane is defined by the formula. Ax+By+Cz+D=0. The ! vector formed by the coefficients <A,B,C> is the normal vector ! to the plane. ! */ ! class Plane { // Members public: + /** the normal vector of the modeled plane */ ! Vector3f normal; /** the distance */ ! float d; // Methods public: + /** empty constructor for an undefined plane */ ! f_inline Plane() {} // empty constructor ... performance /** constructs a plane from a normal and a point on the plane */ ! f_inline Plane(const Vector3f& norm, const Vector3f& pnt) ! { ! normal=norm; ! d=-((norm.x()*pnt.x()) + (norm.y()*pnt.y()) + (norm.z()*pnt.z())); ! } /** constructs a plane from normal and constant D. If normal is a * unit vector, then D is the distance to the origin */ ! f_inline Plane(const Vector3f& norm, const float D) ! { ! normal=norm; d=D; ! } /** constructs a plane from 3 distinct points */ ! f_inline Plane(const Vector3f& v1, const Vector3f &v2, const Vector3f &v3) ! { ! normal=(v2-v1).Cross(v3-v1).Normalized(); ! d=-normal.Dot(v1); ! } // inline functions /** calculates the orientation of v to the plane */ ! f_inline EPlaneSide GetOrientation(const Vector3f &v, float delta=0.0001f) const ! { ! float dist=normal.Dot(v)+d; ! if (dist<-delta) return PLANESIDE_BACK; ! if (dist>delta) return PLANESIDE_FRONT; ! ! return PLANESIDE_ONPLANE; ! } /** calculates the dominant plane */ ! f_inline EPlane GetDominantPlane() const ! { ! return ( ! gAbs(normal.y()) > gAbs(normal.x()) ? ! ( ! gAbs(normal.z()) > gAbs(normal.y()) ? ! PLANE_XY : PLANE_XZ ! ) : ! ( ! gAbs(normal.z()) > gAbs(normal.x()) ? ! PLANE_XY : PLANE_YZ ! ) ! ); ! } /** calculates the distance from v to the plane */ ! f_inline float GetDistanceTo(const Vector3f &v) const { return normal.Dot(v) + d; } /** calculates the relationship between the plane and the box */ EPlaneSide ClassifyBox(const AABB3& bb) const; *************** *** 116,133 **** /** sets up a plane from a normal and a point on the plane */ f_inline void Set(const Vector3f& norm, const Vector3f& pnt) ! { normal=norm; d=-((norm.x()*pnt.x()) + (norm.y()*pnt.y()) + (norm.z()*pnt.z())); } /** sets up a plane from normal and constant D. If normal is a * unit vector, then D is the distance to the origin */ ! f_inline void Set(const Vector3f& norm, const float D) { normal=norm; d=D; } /** sets up a plane from 3 distinct points */ ! f_inline void Set(const Vector3f& v1, const Vector3f &v2, const Vector3f &v3) { normal=(v2-v1).Cross(v3-v1).Normalized(); d=-normal.Dot(v1); } /** the assignment operator for planes */ f_inline const Plane& operator=(const Plane& p) ! { normal=p.normal; d=p.d; return *this; } ! }; --- 151,182 ---- /** sets up a plane from a normal and a point on the plane */ f_inline void Set(const Vector3f& norm, const Vector3f& pnt) ! { ! normal=norm; ! d=-((norm.x()*pnt.x()) + (norm.y()*pnt.y()) + (norm.z()*pnt.z())); ! } /** sets up a plane from normal and constant D. If normal is a * unit vector, then D is the distance to the origin */ ! f_inline void Set(const Vector3f& norm, const float D) ! { ! normal=norm; ! d=D; ! } /** sets up a plane from 3 distinct points */ ! f_inline void Set(const Vector3f& v1, const Vector3f &v2, const Vector3f &v3) ! { ! normal=(v2-v1).Cross(v3-v1).Normalized(); ! d=-normal.Dot(v1); ! } /** the assignment operator for planes */ f_inline const Plane& operator=(const Plane& p) ! { ! normal=p.normal; ! d=p.d; ! return *this; ! } }; Index: plane.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/salt/plane.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** plane.cpp 5 Dec 2005 20:56:00 -0000 1.1 --- plane.cpp 22 Feb 2006 22:54:46 -0000 1.2 *************** *** 1,4 **** ! /* -*- mode: c++ -*- ! this file is part of rcssserver3D Fri May 9 2003 --- 1,4 ---- ! /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- ! this file is part of rcssserver3D Fri May 9 2003 *************** *** 9,18 **** it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. ! This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ! You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software --- 9,18 ---- it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. ! This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ! You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software *************** *** 25,94 **** EPlaneSide Plane::ClassifyBox(const AABB3& bb) const { ! Vector3f posFarPt; ! Vector3f negFarPt; ! if(normal.x()>0) // right ! if(normal.y()>0) // right, top ! if(normal.z()>0) // right, top, front ! { ! posFarPt.Set(bb.maxVec.x(),bb.maxVec.y(),bb.maxVec.z()); ! negFarPt.Set(bb.minVec.x(),bb.minVec.y(),bb.minVec.z()); ! } ! else // right, top, back ! { ! posFarPt.Set(bb.maxVec.x(),bb.maxVec.y(),bb.minVec.z()); ! negFarPt.Set(bb.minVec.x(),bb.minVec.y(),bb.maxVec.z()); ! } ! else // right, bottom ! if(normal.z()>0) // right, bottom, front ! { ! posFarPt.Set(bb.maxVec.x(),bb.minVec.y(),bb.maxVec.z()); ! negFarPt.Set(bb.minVec.x(),bb.maxVec.y(),bb.minVec.z()); ! } ! else // right, bottom, back ! { ! posFarPt.Set(bb.maxVec.x(),bb.minVec.y(),bb.minVec.z()); ! negFarPt.Set(bb.minVec.x(),bb.maxVec.y(),bb.maxVec.z()); ! } ! else ! if(normal.y()>0) // left, top ! if(normal.z()>0) // left, top, front ! { ! posFarPt.Set(bb.minVec.x(),bb.maxVec.y(),bb.maxVec.z()); ! negFarPt.Set(bb.maxVec.x(),bb.minVec.y(),bb.minVec.z()); ! } ! else // left, top, back ! { ! posFarPt.Set(bb.minVec.x(),bb.maxVec.y(),bb.minVec.z()); ! negFarPt.Set(bb.maxVec.x(),bb.minVec.y(),bb.maxVec.z()); ! } ! else // left, bottom ! if(normal.z()>0) // left, bottom, front ! { ! posFarPt.Set(bb.minVec.x(),bb.minVec.y(),bb.maxVec.z()); ! negFarPt.Set(bb.maxVec.x(),bb.maxVec.y(),bb.minVec.z()); ! } ! else // left, bottom, back ! { ! posFarPt.Set(bb.minVec.x(),bb.minVec.y(),bb.minVec.z()); ! negFarPt.Set(bb.maxVec.x(),bb.maxVec.y(),bb.maxVec.z()); ! } ! // BOX IS "OUTSIDE" ! if (GetOrientation(negFarPt, 0.0f)==PLANESIDE_FRONT) return PLANESIDE_FRONT; ! // BOX IS "INSIDE" ! if (GetOrientation(posFarPt, 0.0f)==PLANESIDE_BACK) return PLANESIDE_BACK; ! return PLANESIDE_SPLIT; } void Plane::Normalize() { ! float l=normal.Length(); ! float iLen = 1.0f/l; ! normal.x()*=iLen; ! normal.y()*=iLen; ! normal.z()*=iLen; ! d*=iLen; } --- 25,100 ---- EPlaneSide Plane::ClassifyBox(const AABB3& bb) const { ! Vector3f posFarPt; ! Vector3f negFarPt; ! if(normal.x()>0) // right ! if(normal.y()>0) // right, top ! if(normal.z()>0) // right, top, front ! { ! posFarPt.Set(bb.maxVec.x(),bb.maxVec.y(),bb.maxVec.z()); ! negFarPt.Set(bb.minVec.x(),bb.minVec.y(),bb.minVec.z()); ! } ! else // right, top, back ! { ! posFarPt.Set(bb.maxVec.x(),bb.maxVec.y(),bb.minVec.z()); ! negFarPt.Set(bb.minVec.x(),bb.minVec.y(),bb.maxVec.z()); ! } ! else // right, bottom ! if(normal.z()>0) // right, bottom, front ! { ! posFarPt.Set(bb.maxVec.x(),bb.minVec.y(),bb.maxVec.z()); ! negFarPt.Set(bb.minVec.x(),bb.maxVec.y(),bb.minVec.z()); ! } ! else // right, bottom, back ! { ! posFarPt.Set(bb.maxVec.x(),bb.minVec.y(),bb.minVec.z()); ! negFarPt.Set(bb.minVec.x(),bb.maxVec.y(),bb.maxVec.z()); ! } ! else ! if(normal.y()>0) // left, top ! if(normal.z()>0) // left, top, front ! { ! posFarPt.Set(bb.minVec.x(),bb.maxVec.y(),bb.maxVec.z()); ! negFarPt.Set(bb.maxVec.x(),bb.minVec.y(),bb.minVec.z()); ! } ! else // left, top, back ! { ! posFarPt.Set(bb.minVec.x(),bb.maxVec.y(),bb.minVec.z()); ! negFarPt.Set(bb.maxVec.x(),bb.minVec.y(),bb.maxVec.z()); ! } ! else // left, bottom ! if(normal.z()>0) // left, bottom, front ! { ! posFarPt.Set(bb.minVec.x(),bb.minVec.y(),bb.maxVec.z()); ! negFarPt.Set(bb.maxVec.x(),bb.maxVec.y(),bb.minVec.z()); ! } ! else // left, bottom, back ! { ! posFarPt.Set(bb.minVec.x(),bb.minVec.y(),bb.minVec.z()); ! negFarPt.Set(bb.maxVec.x(),bb.maxVec.y(),bb.maxVec.z()); ! } ! // BOX IS "OUTSIDE" ! if (GetOrientation(negFarPt, 0.0f)==PLANESIDE_FRONT) ! { ! return PLANESIDE_FRONT; ! } ! // BOX IS "INSIDE" ! if (GetOrientation(posFarPt, 0.0f)==PLANESIDE_BACK) ! { ! return PLANESIDE_BACK; ! } ! return PLANESIDE_SPLIT; } void Plane::Normalize() { ! float l=normal.Length(); ! float iLen = 1.0f/l; ! normal.x()*=iLen; ! normal.y()*=iLen; ! normal.z()*=iLen; ! d*=iLen; } |