00001 // Polygon Class by Alan Baylis 2002 00002 00003 #ifndef Polygon_H 00004 #define Polygon_H 00005 00006 #include "vector.h" 00007 #include "vertex.h" 00008 00009 const int maxPolygonVerts = 20; 00010 00011 struct BSP_node; 00012 00013 class POLYGON 00014 { 00015 public: 00016 POLYGON(); 00017 ~POLYGON(); 00018 00019 // methods required for linked list 00020 int Compare(const POLYGON& Polygon); 00021 int GetMyPosition() const {return linkPosition;} 00022 void SetMyPosition(int newPosition) {linkPosition = newPosition;} 00023 int linkPosition; 00024 00025 // member variables and methods required to link polygons 00026 POLYGON* NextPoly; 00027 bool IsLast(); 00028 POLYGON* GetNext(); 00029 void AddPolygon(POLYGON* Poly); 00030 void SetNext(POLYGON* Poly); 00031 POLYGON* CopyList(); 00032 00033 VECTOR GetNormal(); 00034 void SetNormal(); 00035 00036 int id; 00037 int numVertices; 00038 int removable; 00039 unsigned int Texture; 00040 float Scale[2]; 00041 float Shift[2]; 00042 float Rotate; 00043 VERTEX Vertex[maxPolygonVerts]; 00044 00045 // operator overloading 00046 const bool POLYGON::operator == (const POLYGON &Poly) const 00047 { 00048 float PolyDistance = -(Poly.Vertex[0].normal.x * Poly.Vertex[0].coords.x + Poly.Vertex[0].normal.y * Poly.Vertex[0].coords.y + Poly.Vertex[0].normal.z * Poly.Vertex[0].coords.z); 00049 float ThisDistance = -(Vertex[0].normal.x * Vertex[0].coords.x + Vertex[0].normal.y * Vertex[0].coords.y + Vertex[0].normal.z * Vertex[0].coords.z); 00050 00051 if (numVertices == Poly.numVertices) 00052 { 00053 if (PolyDistance == ThisDistance) 00054 { 00055 if (Vertex[0].normal == Poly.Vertex[0].normal) 00056 { 00057 for (int loop = 0; loop < numVertices; loop++) 00058 { 00059 if (Vertex[loop].u != Poly.Vertex[loop].u) 00060 return false; 00061 if (Vertex[loop].v != Poly.Vertex[loop].v) 00062 return false; 00063 } 00064 00065 if (Texture == Poly.Texture) 00066 return true; 00067 } 00068 } 00069 } 00070 return false; 00071 } 00072 }; 00073 00074 void DeleteList(POLYGON* Poly); 00075 int SplitPolygon(POLYGON* PolygonToSplit, POLYGON inputplanePolygon, POLYGON* front, POLYGON* back); 00076 int SplitTriangle(POLYGON triangleToSplit, POLYGON planeTriangle, POLYGON* triangles); 00077 int ClassifyPolygon(POLYGON* Polygon, POLYGON planePolygon); 00078 void InvertPolygon(POLYGON* Polygon); 00079 VECTOR GetEdgeIntersection(VECTOR point0, VECTOR point1, POLYGON planePolygon); 00080 00081 #endif