00001 /* 00002 * Polygon header 00003 * 00004 * This file is part of the "SoftPixel Engine" (Copyright (c) 2008 by Lukas Hermanns) 00005 * See "SoftPixelEngine.hpp" for license information. 00006 */ 00007 00008 #ifndef __SP_DIMENSION_POLYGON_H__ 00009 #define __SP_DIMENSION_POLYGON_H__ 00010 00011 00012 #include "Base/spStandard.hpp" 00013 #include "Base/spDimensionVector3D.hpp" 00014 00015 #include <vector> 00016 00017 00018 namespace sp 00019 { 00020 namespace dim 00021 { 00022 00023 00029 template <typename T> class polygon 00030 { 00031 00032 public: 00033 00034 polygon() 00035 { 00036 } 00037 polygon(const polygon<T> &Other) : 00038 Points(Other.Points) 00039 { 00040 } 00041 ~polygon() 00042 { 00043 } 00044 00045 /* === Operators === */ 00046 00047 inline polygon<T>& operator = (const polygon<T> &Other) 00048 { 00049 Points = Other.Points; 00050 return *this; 00051 } 00052 00053 /* === Additional operators === */ 00054 00055 inline const T& operator [] (u32 Index) const 00056 { 00057 return Points[Index]; 00058 } 00059 inline T& operator [] (u32 Index) 00060 { 00061 return Points[Index]; 00062 } 00063 00064 /* === Extra functions === */ 00065 00066 inline u32 getCount() const 00067 { 00068 return Points.size(); 00069 } 00070 00071 inline void clear() 00072 { 00073 Points.clear(); 00074 } 00075 00076 inline void push(const T &Point) 00077 { 00078 Points.push_back(Point); 00079 } 00080 inline void pop() 00081 { 00082 Points.pop_back(); 00083 } 00084 00085 inline polygon<T> getSwaped() const 00086 { 00087 polygon<T> Swaped(*this); 00088 Swaped.swap(); 00089 return Swaped; 00090 } 00091 inline polygon<T>& swap() 00092 { 00093 for (u32 i = 0, c = getCount()/2; i < c; ++i) 00094 math::Swap(Points[i], Points[getCount() - i - 1]); 00095 return *this; 00096 } 00097 00098 template <typename T2> inline polygon<T2> cast() const 00099 { 00100 polygon<T2> Casted; 00101 00102 for (u32 i = 0; i < getCount(); ++i) 00103 Casted.Points[i] = Points[i].cast<T2>(); 00104 00105 return Casted; 00106 } 00107 00108 /* === Members === */ 00109 00110 std::vector<T> Points; 00111 00112 }; 00113 00114 typedef polygon<vector3di> polygon3di; 00115 typedef polygon<vector3df> polygon3df; 00116 00117 00118 } // /namespace dim 00119 00120 } // /namespace sp 00121 00122 00123 #endif 00124 00125 00126 00127 // ================================================================================