PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Polygon.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLMATH_POLYGON_H__ 00024 #define __PLMATH_POLYGON_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Container/Array.h> 00032 #include "PLMath/Plane.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLMath { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Classes ] 00043 //[-------------------------------------------------------] 00044 /** 00045 * @brief 00046 * A polygon is a set of vertices on a same plane. This is only a base class with 00047 * vertices... to add texture coords etc. to have to derive it! 00048 */ 00049 class Polygon { 00050 00051 00052 //[-------------------------------------------------------] 00053 //[ Public definitions ] 00054 //[-------------------------------------------------------] 00055 public: 00056 /** 00057 * @brief 00058 * Plane/point relation 00059 */ 00060 enum ESide { 00061 Behind = -1, /**< Behind the plane (distance < 0) */ 00062 Coinciding = 0, /**< Lies on the plane (distance = 0) */ 00063 InFront = 1, /**< Is in front of the plane (distance > 0) */ 00064 Spanning = 2 /**< Spans the plane */ 00065 }; 00066 00067 00068 //[-------------------------------------------------------] 00069 //[ Public functions ] 00070 //[-------------------------------------------------------] 00071 public: 00072 /** 00073 * @brief 00074 * Constructor 00075 */ 00076 PLMATH_API Polygon(); 00077 00078 /** 00079 * @brief 00080 * Copy constructor 00081 * 00082 * @param[in] cSource 00083 * Polygon to copy 00084 */ 00085 PLMATH_API Polygon(const Polygon &cSource); 00086 00087 /** 00088 * @brief 00089 * Destructor 00090 */ 00091 PLMATH_API virtual ~Polygon(); 00092 00093 /** 00094 * @brief 00095 * Returns the plane the polygon is on 00096 * 00097 * @return 00098 * Plane the polygon is on 00099 */ 00100 PLMATH_API const Plane &GetPlane() const; 00101 00102 /** 00103 * @brief 00104 * Computes and returns the plane the polygon is on 00105 * 00106 * @return 00107 * Plane the polygon is on 00108 * 00109 * @note 00110 * - For the plane calculation the first three vertices are used 00111 */ 00112 PLMATH_API const Plane &ComputePlane(); 00113 00114 /** 00115 * @brief 00116 * Checks whether all vertices are on the polygon plane or not 00117 * 00118 * @return 00119 * 'true' if all vertices are on the polygon plane, else 'false' 00120 */ 00121 PLMATH_API bool CheckVerticesOnPlane() const; 00122 00123 /** 00124 * @brief 00125 * Returns a list of all vertices 00126 * 00127 * @return 00128 * List of all vertices 00129 * 00130 * @note 00131 * - If vertices are changed to should call the ComputePlane() 00132 * function to keep the polygon plane up to date! 00133 */ 00134 PLMATH_API PLCore::Array<Vector3> &GetVertexList(); 00135 00136 /** 00137 * @brief 00138 * Adds a vertex to the polygon 00139 * 00140 * @param[in] vV 00141 * Vertex to add 00142 * 00143 * @return 00144 * 'true' if all went fine and the vertex was added, else 'false' 00145 * (maybe the current last vertex is the same as the given one?) 00146 */ 00147 PLMATH_API bool AddVertex(const Vector3 &vV); 00148 00149 /** 00150 * @brief 00151 * Splits the polygon 00152 * 00153 * @param[in] cSplitter 00154 * Splitter plane 00155 * @param[out] cFrontPolygon 00156 * Polygon in front of the plane 00157 * @param[out] cBackPolygon 00158 * Polygon behind the plane 00159 * 00160 * @return 00161 * 'true' if all went fine, else 'false' 00162 */ 00163 PLMATH_API bool Split(const Plane &cSplitter, Polygon &cFrontPolygon, Polygon &cBackPolygon); 00164 00165 /** 00166 * @brief 00167 * Copy operator 00168 * 00169 * @param[in] cSource 00170 * Source to copy from 00171 * 00172 * @return 00173 * Reference to this instance 00174 */ 00175 PLMATH_API Polygon &operator =(const Polygon &cSource); 00176 00177 /** 00178 * @brief 00179 * Calculates the side the polygon is on 00180 * 00181 * @return 00182 * Plane side 00183 */ 00184 PLMATH_API ESide GetSide(const Plane &cPlane) const; 00185 00186 /** 00187 * @brief 00188 * Checks whether the polygon is completely in front of the given plane 00189 * 00190 * @return 00191 * 'true' if the polygon is completely in front of the given plane, else 'false' 00192 */ 00193 PLMATH_API bool IsInFront(const Plane &cPlane) const; 00194 00195 /** 00196 * @brief 00197 * Checks whether the polygon is completely behind the given plane 00198 * 00199 * @return 00200 * 'true' if the polygon is completely behind the given plane, else 'false' 00201 */ 00202 PLMATH_API bool IsBehind(const Plane &cPlane) const; 00203 00204 /** 00205 * @brief 00206 * Clips the polygon against a plane 00207 * 00208 * @param[in] cPlane 00209 * Plane to clip this polygon against 00210 * 00211 * @return 00212 * The resulting clipped plane 00213 */ 00214 PLMATH_API Polygon Clip(const Plane &cPlane) const; 00215 00216 00217 //[-------------------------------------------------------] 00218 //[ Private data ] 00219 //[-------------------------------------------------------] 00220 private: 00221 PLCore::Array<Vector3> m_lstVertices; /**< The vertices (xyz) */ 00222 Plane m_cPlane; /**< Plane the polygon is on */ 00223 00224 00225 //[-------------------------------------------------------] 00226 //[ Public virtual Polygon functions ] 00227 //[-------------------------------------------------------] 00228 public: 00229 /** 00230 * @brief 00231 * Initializes the data of the splitted polygon 00232 * 00233 * @param[out] cPolygon 00234 * Polygon which should be initialized 00235 * 00236 * @return 00237 * 'true' if all went fine, else 'false' 00238 */ 00239 PLMATH_API virtual bool CustomInit(Polygon &cPolygon); 00240 00241 /** 00242 * @brief 00243 * Adds data to a polygon 00244 * 00245 * @param[out] cPolygon 00246 * Polygon the data should be added 00247 * @param[in] nID 00248 * Current data ID 00249 * 00250 * @return 00251 * 'true' if all went fine, else 'false' 00252 * 00253 * @note 00254 * - Is called by Split() to get an custom split behavior... a 00255 * derived polygon could e.g. also have texture coordinates to be split or added! 00256 */ 00257 PLMATH_API virtual bool CustomAdd(Polygon &cPolygon, PLCore::uint32 nID); 00258 00259 /** 00260 * @brief 00261 * Splits the polygon using the custom function 00262 * 00263 * @param[out] cFrontPolygon 00264 * Polygon in front of the plane 00265 * @param[out] cBackPolygon 00266 * Polygon behind the plane 00267 * @param[in] nID 00268 * Current data ID 00269 * @param[in] fDistance 00270 * Distance from nID-1 to the splitter plane intersection point 00271 * 00272 * @return 00273 * 'true' if all went fine, else 'false' 00274 * 00275 * @see 00276 * - CustomAdd() 00277 */ 00278 PLMATH_API virtual bool CustomSplit(Polygon &cFrontPolygon, Polygon &cBackPolygon, PLCore::uint32 nID, float fDistance); 00279 00280 00281 }; 00282 00283 00284 //[-------------------------------------------------------] 00285 //[ Namespace ] 00286 //[-------------------------------------------------------] 00287 } // PLMath 00288 00289 00290 #endif // __PLMATH_POLYGON_H__
|