PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: AABoundingBox.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_AABOUNDINGBOX_H__ 00024 #define __PLMATH_AABOUNDINGBOX_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 //[ Classes ] 00042 //[-------------------------------------------------------] 00043 /** 00044 * @brief 00045 * Axis align bounding box class 00046 * 00047 * @remarks 00048 * @code 00049 * 3+------+2 y 00050 * /| /| | 00051 * / | / | | 00052 * / 0+---/--+1 *---x 00053 * 7+------+6 / / 00054 * | / | / z 00055 * |/ |/ 00056 * 4+------+5 00057 * @endcode 00058 * 00059 * @note 00060 * - It's highly recommended (but not enforced by this class) that the minimum is 00061 * really the minimum and the maximum is really the maximum 00062 */ 00063 class AABoundingBox { 00064 00065 00066 //[-------------------------------------------------------] 00067 //[ Public definitions ] 00068 //[-------------------------------------------------------] 00069 public: 00070 /** 00071 * @brief 00072 * Axis 00073 */ 00074 enum Axis { 00075 X = 0, /**< X axis */ 00076 Y = 1, /**< Y axis */ 00077 Z = 2 /**< Z axis */ 00078 }; 00079 00080 00081 //[-------------------------------------------------------] 00082 //[ Public data ] 00083 //[-------------------------------------------------------] 00084 public: 00085 Vector3 vMin; /**< Minimum position */ 00086 Vector3 vMax; /**< Maximum position */ 00087 00088 00089 //[-------------------------------------------------------] 00090 //[ Public functions ] 00091 //[-------------------------------------------------------] 00092 public: 00093 /** 00094 * @brief 00095 * Default constructor setting all minimum and maximum components to 0 00096 */ 00097 inline AABoundingBox(); 00098 00099 /** 00100 * @brief 00101 * Copy constructor 00102 * 00103 * @param[in] cSource 00104 * Source to copy from 00105 */ 00106 inline AABoundingBox(const AABoundingBox &cSource); 00107 00108 /** 00109 * @brief 00110 * Constructor 00111 * 00112 * @param[in] vMinMax 00113 * Minimum and maximum position 00114 */ 00115 inline AABoundingBox(const Vector3 &vMinMax); 00116 00117 /** 00118 * @brief 00119 * Constructor 00120 * 00121 * @param[in] vMin 00122 * Minimum position 00123 * @param[in] vMax 00124 * Maximum position 00125 */ 00126 inline AABoundingBox(const Vector3 &vMin, const Vector3 &vMax); 00127 00128 /** 00129 * @brief 00130 * Constructor 00131 * 00132 * @param[in] fMinX 00133 * X component of the minimum position 00134 * @param[in] fMinY 00135 * Y component of the minimum position 00136 * @param[in] fMinZ 00137 * Z component of the minimum position 00138 * @param[in] fMaxX 00139 * X component of the maximum position 00140 * @param[in] fMaxY 00141 * Y component of the maximum position 00142 * @param[in] fMaxZ 00143 * Z component of the maximum position 00144 */ 00145 inline AABoundingBox(float fMinX, float fMinY, float fMinZ, float fMaxX, float fMaxY, float fMaxZ); 00146 00147 /** 00148 * @brief 00149 * Destructor 00150 */ 00151 inline ~AABoundingBox(); 00152 00153 /** 00154 * @brief 00155 * Copy operator 00156 * 00157 * @param[in] cSource 00158 * Source to copy from 00159 * 00160 * @return 00161 * Reference to this instance 00162 */ 00163 PLMATH_API AABoundingBox &operator =(const AABoundingBox &cSource); 00164 00165 /** 00166 * @brief 00167 * Returns the center of the box 00168 * 00169 * @return 00170 * Center of the box ((vMax+vMin)/2) 00171 */ 00172 inline Vector3 GetCenter() const; 00173 00174 /** 00175 * @brief 00176 * Returns the width 00177 * 00178 * @return 00179 * Width (vMax.x - vMin.x) 00180 */ 00181 inline float GetWidth() const; 00182 00183 /** 00184 * @brief 00185 * Returns the height 00186 * 00187 * @return 00188 * Height (vMax.y - vMin.y) 00189 */ 00190 inline float GetHeight() const; 00191 00192 /** 00193 * @brief 00194 * Returns the depth 00195 * 00196 * @return 00197 * Depth (vMax.z - vMin.z) 00198 */ 00199 inline float GetDepth() const; 00200 00201 /** 00202 * @brief 00203 * Returns the longest axis 00204 * 00205 * @return 00206 * The longest axis 00207 */ 00208 inline Axis GetLongestAxis() const; 00209 00210 /** 00211 * @brief 00212 * Returns the length of the longest axis 00213 * 00214 * @return 00215 * The length of the longest axis 00216 */ 00217 inline float GetLongestAxisLength() const; 00218 00219 /** 00220 * @brief 00221 * Returns the radius of a sphere placed at the origin (0, 0, 0) enclosing this axis align bounding box 00222 * 00223 * @return 00224 * The radius of a sphere placed at the origin (0, 0, 0) enclosing this axis align bounding box 00225 */ 00226 inline float GetEnclosingRadius() const; 00227 00228 /** 00229 * @brief 00230 * Returns the radius of a sphere placed at the origin (0, 0, 0) inside this axis align bounding box 00231 * 00232 * @return 00233 * The radius of a sphere placed at the origin (0, 0, 0) inside this axis align bounding box 00234 * 00235 * @note 00236 * - Smaller than GetEnclosingRadius() 00237 * - Same as GetLongestAxisLength()/2 00238 */ 00239 inline float GetInsideRadius() const; 00240 00241 /** 00242 * @brief 00243 * Calculates the surface of the box 00244 * 00245 * @return 00246 * Surface of the box 00247 */ 00248 inline float CalculateSurface() const; 00249 00250 /** 00251 * @brief 00252 * Calculates the volume of the box 00253 * 00254 * @return 00255 * Volume of the box 00256 */ 00257 inline float CalculateVolume() const; 00258 00259 /** 00260 * @brief 00261 * Clips this box with another one 00262 * 00263 * @param[in] cEnclosed 00264 * Axis align box to clip this box with 00265 */ 00266 inline void ClipByAABox(const AABoundingBox &cEnclosed); 00267 00268 /** 00269 * @brief 00270 * Appends a vertex to the cubic hull 00271 * 00272 * @param[in] vV 00273 * Vertex to append 00274 */ 00275 inline void AppendToCubicHull(const Vector3 &vV); 00276 00277 /** 00278 * @brief 00279 * Combines two axis align boxes 00280 * 00281 * @param[in] cBox 00282 * Axis align box to combine with this box 00283 */ 00284 inline void CombineAABoxes(const AABoundingBox &cBox); 00285 00286 /** 00287 * @brief 00288 * Returns the 8 corner vertices 00289 * 00290 * @param[out] vVertex 00291 * This array will receive the 8 corner vertices 00292 * 00293 * @see 00294 * - Remarks of this class for the positions of the 8 corner vertices 00295 */ 00296 PLMATH_API void GetVertices(Vector3 vVertex[8]) const; 00297 00298 /** 00299 * @brief 00300 * Returns one of the 8 corner vertices 00301 * 00302 * @param[in] nIndex 00303 * Index of the corner vertex to return 00304 * 00305 * @return 00306 * The requested corner vertex 00307 * 00308 * @see 00309 * - GetVertices() 00310 */ 00311 PLMATH_API Vector3 GetVertex(PLCore::uint32 nIndex) const; 00312 00313 /** 00314 * @brief 00315 * Calculates the index of the nearest vertex in the AAB according to the normal vector of a clip plane 00316 * 00317 * @param[in] vClipPlaneNormal 00318 * Clip plane normal 00319 * 00320 * @return 00321 * Index of the nearest vertex in the AAB according to the normal vector of a clip plane 00322 */ 00323 PLMATH_API PLCore::uint32 GetNearestVertexIndex(const Vector3 &vClipPlaneNormal) const; 00324 00325 /** 00326 * @brief 00327 * Calculates the index of the furthest vertex in the AAB according to the normal vector of a clip plane 00328 * 00329 * @param[in] vClipPlaneNormal 00330 * Clip plane normal 00331 * 00332 * @return 00333 * Index of the furthest vertex in the AAB according to the normal vector of a clip plane 00334 */ 00335 PLMATH_API PLCore::uint32 GetFurthestVertexIndex(const Vector3 &vClipPlaneNormal) const; 00336 00337 /** 00338 * @brief 00339 * Ensures that the minimum is really the minimum and the maximum is really the maximum 00340 */ 00341 PLMATH_API void ValidateMinMax(); 00342 00343 /** 00344 * @brief 00345 * Per component addition 00346 * 00347 * @param[in] vV 00348 * Vector to add 00349 * 00350 * @return 00351 * The resulting axis aligned bounding box 00352 */ 00353 inline AABoundingBox operator +(const Vector3 &vV) const; 00354 00355 /** 00356 * @brief 00357 * Per component addition 00358 * 00359 * @param[in] fS 00360 * Scalar to add 00361 * 00362 * @return 00363 * The resulting axis aligned bounding box 00364 */ 00365 inline AABoundingBox operator +(float fS) const; 00366 00367 /** 00368 * @brief 00369 * Per component addition 00370 * 00371 * @param[in] vV 00372 * Vector to add 00373 * 00374 * @return 00375 * Reference to this instance 00376 */ 00377 inline AABoundingBox &operator +=(const Vector3 &vV); 00378 00379 /** 00380 * @brief 00381 * Per component addition 00382 * 00383 * @param[in] fS 00384 * Scalar to add 00385 * 00386 * @return 00387 * Reference to this instance 00388 */ 00389 inline AABoundingBox &operator +=(float fS); 00390 00391 /** 00392 * @brief 00393 * Per component subtraction 00394 * 00395 * @param[in] vV 00396 * Vector to subtract 00397 * 00398 * @return 00399 * The resulting axis aligned bounding box 00400 */ 00401 inline AABoundingBox operator -(const Vector3 &vV) const; 00402 00403 /** 00404 * @brief 00405 * Per component subtraction 00406 * 00407 * @param[in] fS 00408 * Scalar to subtract 00409 * 00410 * @return 00411 * The resulting axis aligned bounding box 00412 */ 00413 inline AABoundingBox operator -(float fS) const; 00414 00415 /** 00416 * @brief 00417 * Per component subtraction 00418 * 00419 * @param[in] vV 00420 * Vector to subtract 00421 * 00422 * @return 00423 * Reference to this instance 00424 */ 00425 inline AABoundingBox &operator -=(const Vector3 &vV); 00426 00427 /** 00428 * @brief 00429 * Per component subtraction 00430 * 00431 * @param[in] fS 00432 * Scalar to subtract 00433 * 00434 * @return 00435 * Reference to this instance 00436 */ 00437 inline AABoundingBox &operator -=(float fS); 00438 00439 /** 00440 * @brief 00441 * Per component multiplication 00442 * 00443 * @param[in] vV 00444 * Vector to multiplicate with 00445 * 00446 * @return 00447 * The resulting axis aligned bounding box 00448 */ 00449 inline AABoundingBox operator *(const Vector3 &vV) const; 00450 00451 /** 00452 * @brief 00453 * Per component multiplication 00454 * 00455 * @param[in] fS 00456 * Scalar to multiplicate with 00457 * 00458 * @return 00459 * The resulting axis aligned bounding box 00460 */ 00461 inline AABoundingBox operator *(float fS) const; 00462 00463 /** 00464 * @brief 00465 * Per component multiplication 00466 * 00467 * @param[in] vV 00468 * Vector to multiplicate with 00469 * 00470 * @return 00471 * Reference to this instance 00472 */ 00473 inline AABoundingBox &operator *=(const Vector3 &vV); 00474 00475 /** 00476 * @brief 00477 * Per component multiplication 00478 * 00479 * @param[in] fS 00480 * Scalar to multiplicate with 00481 * 00482 * @return 00483 * Reference to this instance 00484 */ 00485 inline AABoundingBox &operator *=(float fS); 00486 00487 /** 00488 * @brief 00489 * Per component division 00490 * 00491 * @param[in] vV 00492 * Vector to divide through 00493 * 00494 * @return 00495 * The resulting axis aligned bounding box 00496 */ 00497 inline AABoundingBox operator /(const Vector3 &vV) const; 00498 00499 /** 00500 * @brief 00501 * Per component division 00502 * 00503 * @param[in] fS 00504 * Scalar to divide through 00505 * 00506 * @return 00507 * The resulting axis aligned bounding box 00508 */ 00509 inline AABoundingBox operator /(float fS) const; 00510 00511 /** 00512 * @brief 00513 * Per component division 00514 * 00515 * @param[in] vV 00516 * Vector to divide through 00517 * 00518 * @return 00519 * Reference to this instance 00520 */ 00521 inline AABoundingBox &operator /=(const Vector3 &vV); 00522 00523 /** 00524 * @brief 00525 * Per component division 00526 * 00527 * @param[in] fS 00528 * Scalar to divide through 00529 * 00530 * @return 00531 * Reference to this instance 00532 */ 00533 inline AABoundingBox &operator /=(float fS); 00534 00535 00536 }; 00537 00538 00539 //[-------------------------------------------------------] 00540 //[ Namespace ] 00541 //[-------------------------------------------------------] 00542 } // PLMath 00543 00544 00545 //[-------------------------------------------------------] 00546 //[ Implementation ] 00547 //[-------------------------------------------------------] 00548 #include "PLMath/AABoundingBox.inl" 00549 00550 00551 #endif // __PLMATH_AABOUNDINGBOX_H__
|