Main Page   Class Hierarchy   Compound List   File List   Compound Members  

plane3.h

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 
00023 #ifndef __CS_CSSYSDEFS_H__
00024 #error "cssysdef.h must be included in EVERY source file!"
00025 #endif
00026 
00027 #include "csgeom/vector3.h"
00028 
00034 class csPlane3
00035 {
00036 public:
00038   csVector3 norm;
00039 
00041   float DD;
00042 
00044   csPlane3 () : norm(0,0,1), DD(0) {}
00045 
00047   csPlane3 (const csVector3& plane_norm, float d=0) : norm(plane_norm), DD(d) {}
00048 
00050   csPlane3 (float a, float b, float c, float d=0) : norm(a,b,c), DD(d) {}
00051 
00053   csPlane3 (const csVector3& v1, const csVector3& v2, const csVector3& v3);
00055   csPlane3 (const csVector3& v2, const csVector3& v3)
00056   {
00057     norm = v2 % v3; DD = 0;
00058   }
00059 
00061   inline csVector3& Normal () { return norm; }
00063   inline const csVector3& Normal () const { return norm; }
00064 
00066   inline float A () const { return norm.x; }
00068   inline float B () const { return norm.y; }
00070   inline float C () const { return norm.z; }
00072   inline float D () const { return DD; }
00073 
00075   inline float& A () { return norm.x; }
00077   inline float& B () { return norm.y; }
00079   inline float& C () { return norm.z; }
00081   inline float& D () { return DD; }
00082 
00084   inline void Set (float a, float b, float c, float d)
00085   { norm.x = a; norm.y = b; norm.z = c; DD = d; }
00086 
00088   inline void Set (const csVector3& normal, float d)
00089   { norm = normal; DD = d; }
00090 
00092   void Set (const csVector3& v1, const csVector3& v2, const csVector3& v3);
00094   void Set (const csVector3& v2, const csVector3& v3)
00095   {
00096     norm = v2 % v3; DD = 0;
00097   }
00098 
00100   inline float Classify (const csVector3& pt) const { return norm*pt+DD; }
00101 
00103   static float Classify (float A, float B, float C, float D,
00104                          const csVector3& pt)
00105   { return A*pt.x + B*pt.y + C*pt.z + D; }
00106 
00112   inline float Distance (const csVector3& pt) const
00113   { return ABS (Classify (pt)); }
00114 
00116   void Invert() { norm = -norm;  DD = -DD; }
00117 
00119   void Normalize()
00120   {
00121     float f = norm.Norm();
00122     if (f) { norm /= f;  DD /= f; }
00123   }
00124 };
00125 
00126 #endif // __CS_PLANE3_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000