00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_PLANE3_H__
00021 #define __CS_PLANE3_H__
00022
00029 #ifndef __CS_CSSYSDEFS_H__
00030 #error "cssysdef.h must be included in EVERY source file!"
00031 #endif
00032
00033 #include "csgeom/vector3.h"
00034
00040 class 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 void Set (float a, float b, float c, float d)
00107 { norm.x = a; norm.y = b; norm.z = c; DD = d; }
00108
00110 inline void Set (const csVector3& normal, float d)
00111 { norm = normal; DD = d; }
00112
00119 void Set (const csVector3& v1, const csVector3& v2, const csVector3& v3);
00120
00126 void Set (const csVector3& v2, const csVector3& v3)
00127 {
00128 norm = v2 % v3; DD = 0;
00129 }
00130
00141 inline float Classify (const csVector3& pt) const { return norm*pt+DD; }
00142
00147 static float Classify (float A, float B, float C, float D,
00148 const csVector3& pt)
00149 {
00150 return A*pt.x + B*pt.y + C*pt.z + D;
00151 }
00152
00159 inline float Distance (const csVector3& pt) const
00160 { return ABS (Classify (pt)); }
00161
00166 void Invert () { norm = -norm; DD = -DD; }
00167
00171 void Normalize ()
00172 {
00173 float f = norm.Norm ();
00174 if (f) { norm /= f; DD /= f; }
00175 }
00176
00187 bool ClipPolygon (csVector3*& pverts, int& num_verts, bool reversed = false);
00188 };
00189
00192 #endif // __CS_PLANE3_H__
00193