PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: PlaneSet.h * 00003 * 00004 * Copyright (C) 2002-2011 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_PLANESET_H__ 00024 #define __PLMATH_PLANESET_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 //[ Forward declarations ] 00043 //[-------------------------------------------------------] 00044 class Sphere; 00045 00046 00047 //[-------------------------------------------------------] 00048 //[ Classes ] 00049 //[-------------------------------------------------------] 00050 /** 00051 * @brief 00052 * A set of planes defines a convex volume (e.g. the frustum, an event area...) 00053 * 00054 * @note 00055 * - If there are no planes the tests whether something is inside the planes or not 00056 * will return always 'false' 00057 */ 00058 class PlaneSet { 00059 00060 00061 //[-------------------------------------------------------] 00062 //[ Public definitions ] 00063 //[-------------------------------------------------------] 00064 public: 00065 /** 00066 * @brief 00067 * Default view plane order 00068 */ 00069 enum EViewPlaneOrder { 00070 VPNear = 0, /**< Near plane */ 00071 VPRight = 1, /**< Right plane */ 00072 VPLeft = 2, /**< Left plane */ 00073 VPBottom = 3, /**< Bottom plane */ 00074 VPTop = 4, /**< Top plane */ 00075 VPFar = 5 /**< Far plane */ 00076 }; 00077 00078 00079 //[-------------------------------------------------------] 00080 //[ Public functions ] 00081 //[-------------------------------------------------------] 00082 public: 00083 /** 00084 * @brief 00085 * Constructor 00086 */ 00087 PLMATH_API PlaneSet(); 00088 00089 /** 00090 * @brief 00091 * Copy constructor 00092 * 00093 * @param[in] cSource 00094 * Source to copy from 00095 */ 00096 PLMATH_API PlaneSet(const PlaneSet &cSource); 00097 00098 /** 00099 * @brief 00100 * Destructor 00101 */ 00102 PLMATH_API virtual ~PlaneSet(); 00103 00104 /** 00105 * @brief 00106 * Creates and adds a new plane to the plane set 00107 * 00108 * @return 00109 * The created and added new plane, a null pointer if there was an error 00110 */ 00111 PLMATH_API Plane *Create(); 00112 00113 /** 00114 * @brief 00115 * Creates 6 planes which enclose a box area 00116 * 00117 * @param[in] vMin 00118 * Minimum position of the box 00119 * @param[in] vMax 00120 * Maximum position of the box 00121 * 00122 * @remarks 00123 * Plane order:\n 00124 * 0 = Left (min x)\n 00125 * 1 = Right (max x)\n 00126 * 2 = Bottom (min y)\n 00127 * 3 = Top (max y)\n 00128 * 4 = Back (min z)\n 00129 * 5 = Front (max z) 00130 * 00131 * @note 00132 * - The six enclosing planes corresponding to the box are created automatically 00133 */ 00134 PLMATH_API void CreateBox(const Vector3 &vMin, const Vector3 &vMax); 00135 00136 /** 00137 * @brief 00138 * Creates view planes using a view projection matrix 00139 * 00140 * @param[in] mViewProjection 00141 * View projection matrix 00142 * @param[in] bInfProj 00143 * Is the projection matrix part infinite? In this case, there's no far plane. 00144 * 00145 * @note 00146 * - If there are not enough planes this function will create it. There are 00147 * 6 view planes of the projection matrix is not infinite, else there are 00148 * 5 planes. (no far plane) 00149 * - See EViewPlaneOrder for plane order 00150 */ 00151 PLMATH_API void CreateViewPlanes(const Matrix4x4 &mViewProjection, bool bInfProj = false); 00152 00153 /** 00154 * @brief 00155 * Creates view planes using vertices and a view position 00156 * 00157 * @param[in] lstVertices 00158 * Vertices (xyz, counterclockwise) defining a 'portal'-polygon (there must be at least 3 vertices) 00159 * @param[in] vViewPosition 00160 * View position 00161 * 00162 * @return 00163 * 'true' if all went fine, else 'false' (not enough vertices provided?) 00164 * 00165 * @remarks 00166 * You can for example use this function to create a 'frustum of a portal'. 00167 * 00168 * @note 00169 * - If there are not enough planes this function will create it. There are 5 planes. (no far plane) 00170 */ 00171 PLMATH_API bool CreateViewPlanes(const PLCore::Array<Vector3> &lstVertices, const Vector3 &vViewPosition); 00172 00173 /** 00174 * @brief 00175 * Creates selection planes 00176 * 00177 * @param[in] vStartPos 00178 * Selection rectangle start position 00179 * @param[in] vEndPos 00180 * Selection rectangle end position 00181 * @param[in] nX 00182 * X component of the pixel coordinate of the upper-left corner of the viewport 00183 * @param[in] nY 00184 * Y component of the pixel coordinate of the upper-left corner of the viewport 00185 * @param[in] nWidth 00186 * Width of the clip volume, in pixels 00187 * @param[in] nHeight 00188 * Height of the clip volume, in pixels 00189 * @param[in] mProjection 00190 * Projection matrix 00191 * @param[in] mView 00192 * View matrix 00193 * @param[in] bInfProj 00194 * Is the projection matrix infinite? In this case, there's no far plane. 00195 * 00196 * @note 00197 * - Use this function for instance when dragging a selection rectangle via 00198 * mouse to receive the scene nodes within it. The start and end positions 00199 * are within the given viewport. 00200 * - If there are not enough planes this function will create it. There are 00201 * 6 selection planes. 00202 * - See EViewPlaneOrder for plane order 00203 */ 00204 PLMATH_API void CreateSelectionPlanes(const Vector2 &vStartPos, const Vector2 &vEndPos, 00205 int nX, int nY, int nWidth, int nHeight, 00206 const Matrix4x4 &mProjection, const Matrix4x4 &mView, 00207 bool bInfProj = false); 00208 PLMATH_API void CreateSelectionPlanes(const Vector2 &vStartPos, const Vector2 &vEndPos, 00209 int nX, int nY, int nWidth, int nHeight, 00210 const Matrix4x4 &mProjection, const Matrix3x4 &mView, 00211 bool bInfProj = false); 00212 00213 /** 00214 * @brief 00215 * Returns the number of planes 00216 * 00217 * @return 00218 * Number of planes in the set 00219 */ 00220 PLMATH_API PLCore::uint32 GetNumOfPlanes() const; 00221 00222 /** 00223 * @brief 00224 * Returns a plane 00225 * 00226 * @param[in] nID 00227 * ID of the plane which should be returned 00228 * 00229 * @return 00230 * Plane with the given ID, a null pointer if there was an error 00231 */ 00232 PLMATH_API const Plane *operator [](int nID) const; 00233 00234 /** 00235 * @brief 00236 * Returns a plane 00237 * 00238 * @param[in] nID 00239 * ID of the plane which should be returned 00240 * 00241 * @return 00242 * Plane with the given ID, a null pointer if there was an error 00243 */ 00244 PLMATH_API Plane *operator [](int nID); 00245 00246 /** 00247 * @brief 00248 * Returns the plane list 00249 * 00250 * @return 00251 * Plane list 00252 */ 00253 PLMATH_API PLCore::Array<Plane> &GetList(); 00254 00255 /** 00256 * @brief 00257 * Returns the plane list 00258 * 00259 * @return 00260 * Plane list 00261 */ 00262 PLMATH_API const PLCore::Array<Plane> &GetList() const; 00263 00264 /** 00265 * @brief 00266 * Removes a plane 00267 * 00268 * @param[in] nID 00269 * ID of the plane which should be removed 00270 * 00271 * @return 00272 * 'true' if all went fine, else 'false' 00273 */ 00274 PLMATH_API bool RemovePlane(PLCore::uint32 nID = 0); 00275 00276 /** 00277 * @brief 00278 * Clears the plane set 00279 */ 00280 PLMATH_API void Clear(); 00281 00282 /** 00283 * @brief 00284 * Copy operator 00285 * 00286 * @param[in] cSource 00287 * Source to copy from 00288 * 00289 * @return 00290 * Reference to this instance 00291 */ 00292 PLMATH_API PlaneSet &operator =(const PlaneSet &cSource); 00293 00294 /** 00295 * @brief 00296 * Plane set transformation 00297 * 00298 * @param[in] mRot 00299 * 3x3 rotation matrix 00300 * 00301 * @return 00302 * This instance 00303 */ 00304 PLMATH_API PlaneSet &operator *=(const Matrix3x3 &mRot); 00305 00306 /** 00307 * @brief 00308 * Plane set transformation 00309 * 00310 * @param[in] mTrans 00311 * 3x4 transformation matrix 00312 * 00313 * @return 00314 * This instance 00315 */ 00316 PLMATH_API PlaneSet &operator *=(const Matrix3x4 &mTrans); 00317 00318 /** 00319 * @brief 00320 * Plane set transformation 00321 * 00322 * @param[in] mTrans 00323 * 4x4 transformation matrix 00324 * 00325 * @return 00326 * This instance 00327 */ 00328 PLMATH_API PlaneSet &operator *=(const Matrix4x4 &mTrans); 00329 00330 /** 00331 * @brief 00332 * Checks whether the plane set is convex or not 00333 * 00334 * @return 00335 * 'true' if the plane set is convex, else 'false' 00336 * 00337 * @remarks 00338 * A plane set is a convex volume if each plane has at least one 'neighbour' 00339 * plane 'facing' it. 00340 */ 00341 PLMATH_API bool IsConvex() const; 00342 00343 /** 00344 * @brief 00345 * Calculates the sphere surrounding the enclosed area 00346 * 00347 * @param[out] cSphere 00348 * Will receive the sphere surrounding the enclosed area 00349 * 00350 * @see 00351 * - GetSphere() 00352 */ 00353 PLMATH_API void CalculateSphere(Sphere &cSphere) const; 00354 00355 /** 00356 * @brief 00357 * Calculates the box surrounding the enclosed area 00358 * 00359 * @param[out] vMin 00360 * Will receive the minimum position of the box 00361 * @param[out] vMax 00362 * Will receive the maximum position of the box 00363 */ 00364 PLMATH_API void CalculateBox(Vector3 &vMin, Vector3 &vMax) const; 00365 00366 00367 //[-------------------------------------------------------] 00368 //[ Protected data ] 00369 //[-------------------------------------------------------] 00370 protected: 00371 PLCore::Array<Plane> m_lstPlane; /**< Plane list */ 00372 00373 00374 }; 00375 00376 00377 //[-------------------------------------------------------] 00378 //[ Namespace ] 00379 //[-------------------------------------------------------] 00380 } // PLMath 00381 00382 00383 #endif // __PLMATH_PLANESET_H__
|