CrystalSpace

Public API Reference

csgeom/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 
00030 #include "csextern.h"
00031 
00032 #include "csgeom/matrix4.h"
00033 #include "csgeom/vector3.h"
00034 
00035 class csString;
00036 struct csVertexStatus;
00037 
00043 class CS_CRYSTALSPACE_EXPORT csPlane3
00044 {
00045 public:
00047   csVector3 norm;
00048 
00050   float DD;
00051 
00055   csPlane3 () : norm(0,0,1), DD(0) {}
00056 
00060   csPlane3 (const csVector3& plane_norm, float d=0) : norm(plane_norm), DD(d) {}
00061 
00065   csPlane3 (float a, float b, float c, float d=0) : norm(a,b,c), DD(d) {}
00066 
00073   csPlane3 (const csVector3& v1, const csVector3& v2, const csVector3& v3);
00074 
00080   csPlane3 (const csVector3& v2, const csVector3& v3)
00081   {
00082     norm = v2 % v3; DD = 0;
00083   }
00084 
00088   bool operator==(const csPlane3& other) const
00089   {
00090     return (norm * other.norm) > 0.999f && fabsf(DD - other.DD) < 0.001f;
00091   }
00092 
00094   inline csVector3& Normal () { return norm; }
00096   inline const csVector3& Normal () const { return norm; }
00097 
00099   inline float A () const { return norm.x; }
00101   inline float B () const { return norm.y; }
00103   inline float C () const { return norm.z; }
00105   inline float D () const { return DD; }
00106 
00108   inline float& A () { return norm.x; }
00110   inline float& B () { return norm.y; }
00112   inline float& C () { return norm.z; }
00114   inline float& D () { return DD; }
00115 
00117   inline const csVector3& GetNormal () const { return norm; }
00118 
00120   inline void Set (float a, float b, float c, float d)
00121   { norm.x = a; norm.y = b; norm.z = c; DD = d; }
00122 
00124   inline void Set (const csVector3& normal, float d)
00125   { norm = normal; DD = d; }
00126 
00133   void Set (const csVector3& v1, const csVector3& v2, const csVector3& v3);
00134 
00140   inline void Set (const csVector3& v2, const csVector3& v3)
00141   {
00142     norm = v2 % v3; DD = 0;
00143   }
00144 
00149   inline void SetOrigin (const csVector3& p)
00150   {
00151     DD = -norm * p;
00152   }
00153 
00164   inline float Classify (const csVector3& pt) const { return norm*pt+DD; }
00165 
00170   static float Classify (float A, float B, float C, float D,
00171                          const csVector3& pt)
00172   {
00173     return A*pt.x + B*pt.y + C*pt.z + D;
00174   }
00175 
00182   inline float Distance (const csVector3& pt) const
00183   { return ABS (Classify (pt)); }
00184 
00189   inline void Invert () { norm = -norm;  DD = -DD; }
00190   
00192   inline csPlane3 Inverse() const { csPlane3 p (*this); p.Invert(); return p; }
00193 
00197   inline void Normalize ()
00198   {
00199     float f = norm.Norm ();
00200     if (f) { norm /= f;  DD /= f; }
00201   }
00202 
00206   csVector3 FindPoint () const;
00207 
00209 
00212   csVector3 ProjectOnto(const csVector3& p);
00213   csVector3 ProjectOnto (const csVector3& p) const
00214   {
00215     // @@@ Kludge - needed since ProjectOnto() modifies the plane
00216     csPlane3 thisNonConst (*this);
00217     return thisNonConst.ProjectOnto (p);
00218   }
00220 
00226   static void FindOrthogonalPoints (const csVector3& norm,
00227       csVector3& p, csVector3& q);
00228 
00238   bool ClipPolygon (csVector3*& pverts, int& num_verts, bool reversed = false);
00239 
00254   uint8 ClipPolygon (const csVector3* InVerts, size_t InCount,
00255     csVector3* OutPolygon, size_t& OutCount, csVertexStatus* OutStatus,
00256     bool reversed = false) const;
00257 
00259   csString Description() const;
00260   
00266   inline friend csPlane3 operator* (const CS::Math::Matrix4& m_inv_t,
00267                                     const csPlane3& p)
00268   {
00269     csVector4 v (p.norm, p.DD);
00270     v = m_inv_t * v;
00271     return csPlane3 (v.x, v.y, v.z, v.w);
00272   }
00273 };
00274 
00277 #endif // __CS_PLANE3_H__
00278 

Generated for Crystal Space 2.0 by doxygen 1.7.6.1