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
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
00046 csPlane3 () : norm(0,0,1), DD(0) {}
00047
00051 csPlane3 (const csVector3& plane_norm, float d=0) : norm(plane_norm), DD(d) {}
00052
00056 csPlane3 (float a, float b, float c, float d=0) : norm(a,b,c), DD(d) {}
00057
00064 csPlane3 (const csVector3& v1, const csVector3& v2, const csVector3& v3);
00065
00071 csPlane3 (const csVector3& v2, const csVector3& v3)
00072 {
00073 norm = v2 % v3; DD = 0;
00074 }
00075
00077 inline csVector3& Normal () { return norm; }
00079 inline const csVector3& Normal () const { return norm; }
00080
00082 inline float A () const { return norm.x; }
00084 inline float B () const { return norm.y; }
00086 inline float C () const { return norm.z; }
00088 inline float D () const { return DD; }
00089
00091 inline float& A () { return norm.x; }
00093 inline float& B () { return norm.y; }
00095 inline float& C () { return norm.z; }
00097 inline float& D () { return DD; }
00098
00100 inline void Set (float a, float b, float c, float d)
00101 { norm.x = a; norm.y = b; norm.z = c; DD = d; }
00102
00104 inline void Set (const csVector3& normal, float d)
00105 { norm = normal; DD = d; }
00106
00113 void Set (const csVector3& v1, const csVector3& v2, const csVector3& v3);
00114
00120 void Set (const csVector3& v2, const csVector3& v3)
00121 {
00122 norm = v2 % v3; DD = 0;
00123 }
00124
00135 inline float Classify (const csVector3& pt) const { return norm*pt+DD; }
00136
00141 static float Classify (float A, float B, float C, float D,
00142 const csVector3& pt)
00143 {
00144 return A*pt.x + B*pt.y + C*pt.z + D;
00145 }
00146
00153 inline float Distance (const csVector3& pt) const
00154 { return ABS (Classify (pt)); }
00155
00160 void Invert () { norm = -norm; DD = -DD; }
00161
00165 void Normalize ()
00166 {
00167 float f = norm.Norm ();
00168 if (f) { norm /= f; DD /= f; }
00169 }
00170
00181 bool ClipPolygon (csVector3*& pverts, int& num_verts, bool reversed = false);
00182 };
00183
00184 #endif // __CS_PLANE3_H__
00185