## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# 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/vector3.h"
    00033
    00034 class csString;
    00035
    00041 class CS_CRYSTALSPACE_EXPORT csPlane3
    00042 {
    00043 public:
    00045   csVector3 norm;
    00046
    00048   float DD;
    00049
    00053   csPlane3 () : norm(0,0,1), DD(0) {}
    00054
    00058   csPlane3 (const csVector3& plane_norm, float d=0) : norm(plane_norm), DD(d) {}
    00059
    00063   csPlane3 (float a, float b, float c, float d=0) : norm(a,b,c), DD(d) {}
    00064
    00071   csPlane3 (const csVector3& v1, const csVector3& v2, const csVector3& v3);
    00072
    00078   csPlane3 (const csVector3& v2, const csVector3& v3)
    00079   {
    00080     norm = v2 % v3; DD = 0;
    00081   }
    00082
    00084   inline csVector3& Normal () { return norm; }
    00086   inline const csVector3& Normal () const { return norm; }
    00087
    00089   inline float A () const { return norm.x; }
    00091   inline float B () const { return norm.y; }
    00093   inline float C () const { return norm.z; }
    00095   inline float D () const { return DD; }
    00096
    00098   inline float& A () { return norm.x; }
    00100   inline float& B () { return norm.y; }
    00102   inline float& C () { return norm.z; }
    00104   inline float& D () { return DD; }
    00105
    00107   inline const csVector3& GetNormal () const { return norm; }
    00108
    00110   inline void Set (float a, float b, float c, float d)
    00111   { norm.x = a; norm.y = b; norm.z = c; DD = d; }
    00112
    00114   inline void Set (const csVector3& normal, float d)
    00115   { norm = normal; DD = d; }
    00116
    00123   void Set (const csVector3& v1, const csVector3& v2, const csVector3& v3);
    00124
    00130   inline void Set (const csVector3& v2, const csVector3& v3)
    00131   {
    00132     norm = v2 % v3; DD = 0;
    00133   }
    00134
    00139   inline void SetOrigin (const csVector3& p)
    00140   {
    00141     DD = -norm * p;
    00142   }
    00143
    00154   inline float Classify (const csVector3& pt) const { return norm*pt+DD; }
    00155
    00160   static float Classify (float A, float B, float C, float D,
    00161                          const csVector3& pt)
    00162   {
    00163     return A*pt.x + B*pt.y + C*pt.z + D;
    00164   }
    00165
    00172   inline float Distance (const csVector3& pt) const
    00173   { return ABS (Classify (pt)); }
    00174
    00179   inline void Invert () { norm = -norm;  DD = -DD; }
    00180
    00184   inline void Normalize ()
    00185   {
    00186     float f = norm.Norm ();
    00187     if (f) { norm /= f;  DD /= f; }
    00188   }
    00189
    00193   csVector3 FindPoint () const;
    00194
    00205   bool ClipPolygon (csVector3*& pverts, int& num_verts, bool reversed = false);
    00206
    00208   csString Description() const;
    00209 };
    00210
    00213 #endif // __CS_PLANE3_H__
    00214