Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

plane.h

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: plane.h,v 1.5 2003/11/14 14:05:54 fruit Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 
00022    NOTE:
00023 
00024    HISTORY:
00025                 11.06.01 - MK
00026                         - Initial version
00027 
00028    TODO:
00029 
00030    TOFIX:
00031 */
00032 #ifndef SALT_PLANE_H
00033 #define SALT_PLANE_H
00034 
00035 #include "defines.h"
00036 #include "vector.h"
00037 #include "bounds.h"
00038 
00039 namespace salt
00040 {
00041 
00043 enum EPlaneSide
00044 {
00045     PLANESIDE_BACK                      =       0,
00046     PLANESIDE_ONPLANE           =       1,
00047     PLANESIDE_FRONT                     =       2,
00048     PLANESIDE_SPLIT                     =       3,
00049     PLANESIDE_FORCE_32BIT       =       0xffffffff      // used to force the enum to be 32-bit wide
00050 };
00051 
00052 
00054 enum EPlane
00055 {
00056     PLANE_XY                    =       0,
00057     PLANE_XZ                    =       1,
00058     PLANE_YZ                    =       2,
00059     PLANE_FORCE_32BIT   =       0xffffffff      // used to force the enum to be 32-bit wide
00060 };
00061 
00062 
00071 class Plane
00072 {
00073 // Members
00074 public:
00076     Vector3f    normal;
00077 
00079     float               d;
00080 
00081 // Methods
00082 public:
00084     f_inline Plane() {}         // empty constructor ... performance
00085 
00087     f_inline Plane(const Vector3f& norm, const Vector3f& pnt)                                           { normal=norm; d=-((norm.x()*pnt.x()) + (norm.y()*pnt.y()) + (norm.z()*pnt.z())); }
00088 
00092     f_inline Plane(const Vector3f& norm, const float D)                                                         { normal=norm; d=D; }
00093 
00095     f_inline Plane(const Vector3f& v1,  const Vector3f &v2, const Vector3f &v3)         { normal=(v2-v1).Cross(v3-v1).Normalized(); d=-normal.Dot(v1); }
00096 
00097     // inline functions
00098 
00100     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;  }
00101 
00103     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)); }
00104 
00106     f_inline float              GetDistanceTo(const Vector3f &v) const
00107     { return normal.Dot(v) + d; }
00108 
00109 
00111     EPlaneSide ClassifyBox(const AABB3& bb) const;
00112 
00114     void Normalize();
00115 
00117     f_inline void Set(const Vector3f& norm, const Vector3f& pnt)
00118     { normal=norm; d=-((norm.x()*pnt.x()) + (norm.y()*pnt.y()) + (norm.z()*pnt.z())); }
00119 
00123     f_inline void Set(const Vector3f& norm, const float D)                                                      { normal=norm; d=D; }
00124 
00126     f_inline void Set(const Vector3f& v1,   const Vector3f &v2, const Vector3f &v3)     { normal=(v2-v1).Cross(v3-v1).Normalized(); d=-normal.Dot(v1); }
00127 
00129     f_inline const Plane&       operator=(const Plane& p)
00130     { normal=p.normal; d=p.d; return *this; }
00131 
00132 };
00133 
00134 }
00135 
00136 #endif //SALT_PLANE_H

Generated on Thu Apr 6 15:25:39 2006 for rcssserver3d by  doxygen 1.4.4