PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Quadtree.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_QUADTREE_H__ 00024 #define __PLMATH_QUADTREE_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLMath/Vector3.h" 00032 00033 00034 //[-------------------------------------------------------] 00035 //[ Namespace ] 00036 //[-------------------------------------------------------] 00037 namespace PLMath { 00038 00039 00040 //[-------------------------------------------------------] 00041 //[ Forward declarations ] 00042 //[-------------------------------------------------------] 00043 class PlaneSet; 00044 00045 00046 //[-------------------------------------------------------] 00047 //[ Classes ] 00048 //[-------------------------------------------------------] 00049 /** 00050 * @brief 00051 * Quadtree patch 00052 */ 00053 class QuadtreePatch { 00054 00055 00056 //[-------------------------------------------------------] 00057 //[ Public functions ] 00058 //[-------------------------------------------------------] 00059 public: 00060 /** 00061 * @brief 00062 * Constructor 00063 */ 00064 PLMATH_API QuadtreePatch(); 00065 00066 /** 00067 * @brief 00068 * Destructor 00069 */ 00070 PLMATH_API virtual ~QuadtreePatch(); 00071 00072 /** 00073 * @brief 00074 * Returns whether the patch is currently visible or not 00075 * 00076 * @return 00077 * 'true' if the patch is visible, else 'false' 00078 */ 00079 PLMATH_API bool IsVisible() const; 00080 00081 /** 00082 * @brief 00083 * Sets whether the patch is currently visible or not 00084 * 00085 * @param[in] bVisible 00086 * Should the patch be visible? 00087 */ 00088 PLMATH_API void SetVisible(bool bVisible = true); 00089 00090 /** 00091 * @brief 00092 * Returns the bounding box minimum coordinate 00093 * 00094 * @return 00095 * Bounding box minimum coordinate 00096 */ 00097 PLMATH_API Vector3 &GetBBMin(); 00098 00099 /** 00100 * @brief 00101 * Returns the bounding box maximum coordinate 00102 * 00103 * @return 00104 * Bounding box maximum coordinate 00105 */ 00106 PLMATH_API Vector3 &GetBBMax(); 00107 00108 00109 //[-------------------------------------------------------] 00110 //[ Private data ] 00111 //[-------------------------------------------------------] 00112 public: 00113 bool m_bVisible; /**< Is the quadtree visible? */ 00114 Vector3 m_vBoundingBox[2]; /**< Quadtree bounding box (min/max) */ 00115 00116 00117 }; 00118 00119 /** 00120 * @brief 00121 * Quadtree 00122 */ 00123 class Quadtree { 00124 00125 00126 //[-------------------------------------------------------] 00127 //[ Public functions ] 00128 //[-------------------------------------------------------] 00129 public: 00130 /** 00131 * @brief 00132 * Constructor 00133 */ 00134 PLMATH_API Quadtree(); 00135 00136 /** 00137 * @brief 00138 * Destructor 00139 */ 00140 PLMATH_API virtual ~Quadtree(); 00141 00142 /** 00143 * @brief 00144 * Initializes the quadtree 00145 * 00146 * @param[in] nXOffset 00147 * Quadtree x offset 00148 * @param[in] nYOffset 00149 * Quadtree y offset 00150 * @param[in] nXSize 00151 * Quadtree x dimension 00152 * @param[in] nYSize 00153 * Quadtree y dimension 00154 * @param[in] pParent 00155 * Parent quadtree, can be a null pointer 00156 * 00157 * @note 00158 * - You should destroy the old quadtree before you initialize the new one! 00159 */ 00160 PLMATH_API void Init(PLCore::uint32 nXOffset = 0, PLCore::uint32 nYOffset = 0, PLCore::uint32 nXSize = 0, PLCore::uint32 nYSize = 0, Quadtree *pParent = nullptr); 00161 00162 /** 00163 * @brief 00164 * Builds the quadtree 00165 * 00166 * @return 00167 * 'true' if all went fine, else 'false' 00168 * 00169 * @note 00170 * - The quadtree must be initialized first! 00171 */ 00172 PLMATH_API bool Build(); 00173 00174 /** 00175 * @brief 00176 * Destroy the quadtree 00177 */ 00178 PLMATH_API void Destroy(); 00179 00180 /** 00181 * @brief 00182 * Updates the bounding boxes of the quadtree 00183 * 00184 * @param[out] ppPatch 00185 * Pointer to the quadtree patches, can be a null pointer (in that case this function is quite useless...) 00186 * 00187 * @note 00188 * - There must be x size * y size patches in the array! 00189 * - The quadtree patches must have correct bounding boxes 00190 * - If the bounding box of a patch is changed you have to recall this 00191 * function! 00192 */ 00193 PLMATH_API void UpdateBoundingBoxes(QuadtreePatch **ppPatch); 00194 00195 /** 00196 * @brief 00197 * Updates the visibility information of the quadtree patches 00198 * 00199 * @param[in] cPlaneSet 00200 * Plane set to check 00201 * @param[out] ppPatch 00202 * Patches to be updated, can be a null pointer (in that case this function is quite useless...) 00203 * 00204 * @note 00205 * - The quadtree bounding boxes must being initialized with this patches! 00206 * 00207 * @see 00208 * - UpdateBoundingBoxes() 00209 */ 00210 PLMATH_API void UpdateVisibility(const PlaneSet &cPlaneSet, QuadtreePatch **ppPatch) const; 00211 00212 /** 00213 * @brief 00214 * Returns the bounding box minimum/maximum values 00215 * 00216 * @param[out] vMin 00217 * Receives the bounding box minimum value 00218 * @param[out] vMax 00219 * Receives the bounding box maximum value 00220 */ 00221 PLMATH_API void GetBoundingBoxMinMax(Vector3 &vMin, Vector3 &vMax) const; 00222 00223 /** 00224 * @brief 00225 * Returns the number of children 00226 * 00227 * @return 00228 * Number of children 00229 */ 00230 PLMATH_API PLCore::uint32 GetNumOfChildren() const; 00231 00232 /** 00233 * @brief 00234 * Returns a child 00235 * 00236 * @param[in] nChild 00237 * Child to return 00238 * 00239 * @return 00240 * The requested child, a null pointer on error 00241 */ 00242 PLMATH_API Quadtree *GetChild(PLCore::uint32 nChild) const; 00243 00244 00245 //[-------------------------------------------------------] 00246 //[ Private functions ] 00247 //[-------------------------------------------------------] 00248 private: 00249 /** 00250 * @brief 00251 * Copy constructor 00252 * 00253 * @param[in] cSource 00254 * Source to copy from 00255 */ 00256 Quadtree(const Quadtree &cSource); 00257 00258 /** 00259 * @brief 00260 * Copy operator 00261 * 00262 * @param[in] cSource 00263 * Source to copy from 00264 * 00265 * @return 00266 * Reference to this instance 00267 */ 00268 Quadtree &operator =(const Quadtree &cSource); 00269 00270 00271 //[-------------------------------------------------------] 00272 //[ Private data ] 00273 //[-------------------------------------------------------] 00274 private: 00275 PLCore::uint32 m_nXOffset; /**< X offset */ 00276 PLCore::uint32 m_nYOffset; /**< Y offset */ 00277 PLCore::uint32 m_nXSize; /**< X size */ 00278 PLCore::uint32 m_nYSize; /**< Y size */ 00279 Quadtree *m_pTopmost; /**< Topmost quadtree (always valid!) */ 00280 Quadtree *m_pParent; /**< Quadtree parent, can be a null pointer */ 00281 PLCore::uint32 m_nNumOfChildren; /**< Number of children */ 00282 Quadtree *m_pChild; /**< The children, can be a null pointer */ 00283 Vector3 m_vBoundingBox[2]; /**< Quadtree bounding box (min/max) */ 00284 00285 00286 }; 00287 00288 00289 //[-------------------------------------------------------] 00290 //[ Namespace ] 00291 //[-------------------------------------------------------] 00292 } // PLMath 00293 00294 00295 #endif // __PLMATH_QUADTREE_H__
|