CrystalSpace

Public API Reference

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

plane3.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 1998,1999,2000 by Jorrit Tyberghein
00003     Largely rewritten by Ivan Avramovic <ivan@avramovic.com>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_PLANE3_H__
00021 #define __CS_PLANE3_H__
00022 
00029 #include "csextern.h"
00030 
00031 #include "csgeom/vector3.h"
00032 
00033 class csString;
00034 
00040 class CS_CRYSTALSPACE_EXPORT csPlane3
00041 {
00042 public:
00044   csVector3 norm;
00045 
00047   float DD;
00048 
00052   csPlane3 () : norm(0,0,1), DD(0) {}
00053 
00057   csPlane3 (const csVector3& plane_norm, float d=0) : norm(plane_norm), DD(d) {}
00058 
00062   csPlane3 (float a, float b, float c, float d=0) : norm(a,b,c), DD(d) {}
00063 
00070   csPlane3 (const csVector3& v1, const csVector3& v2, const csVector3& v3);
00071 
00077   csPlane3 (const csVector3& v2, const csVector3& v3)
00078   {
00079     norm = v2 % v3; DD = 0;
00080   }
00081 
00083   inline csVector3& Normal () { return norm; }
00085   inline const csVector3& Normal () const { return norm; }
00086 
00088   inline float A () const { return norm.x; }
00090   inline float B () const { return norm.y; }
00092   inline float C () const { return norm.z; }
00094   inline float D () const { return DD; }
00095 
00097   inline float& A () { return norm.x; }
00099   inline float& B () { return norm.y; }
00101   inline float& C () { return norm.z; }
00103   inline float& D () { return DD; }
00104 
00106   inline const csVector3& GetNormal () const { return norm; }
00107 
00109   inline void Set (float a, float b, float c, float d)
00110   { norm.x = a; norm.y = b; norm.z = c; DD = d; }
00111 
00113   inline void Set (const csVector3& normal, float d)
00114   { norm = normal; DD = d; }
00115 
00122   void Set (const csVector3& v1, const csVector3& v2, const csVector3& v3);
00123 
00129   inline void Set (const csVector3& v2, const csVector3& v3)
00130   {
00131     norm = v2 % v3; DD = 0;
00132   }
00133 
00138   inline void SetOrigin (const csVector3& p)
00139   {
00140     DD = -norm * p;
00141   }
00142 
00153   inline float Classify (const csVector3& pt) const { return norm*pt+DD; }
00154 
00159   static float Classify (float A, float B, float C, float D,
00160                          const csVector3& pt)
00161   {
00162     return A*pt.x + B*pt.y + C*pt.z + D;
00163   }
00164 
00171   inline float Distance (const csVector3& pt) const
00172   { return ABS (Classify (pt)); }
00173 
00178   inline void Invert () { norm = -norm;  DD = -DD; }
00179 
00183   inline void Normalize ()
00184   {
00185     float f = norm.Norm ();
00186     if (f) { norm /= f;  DD /= f; }
00187   }
00188 
00192   csVector3 FindPoint () const;
00193 
00204   bool ClipPolygon (csVector3*& pverts, int& num_verts, bool reversed = false);
00205 
00207   csString Description() const;
00208 };
00209 
00212 #endif // __CS_PLANE3_H__
00213 

Generated for Crystal Space by doxygen 1.4.4