PixelLightAPI  .
Octree.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Octree.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_OCTREE_H__
00024 #define __PLMATH_OCTREE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLMath/BoundingBox.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Forward declarations                                  ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038     class Bitset;
00039 }
00040 namespace PLMath {
00041     class PlaneSet;
00042 }
00043 
00044 
00045 //[-------------------------------------------------------]
00046 //[ Namespace                                             ]
00047 //[-------------------------------------------------------]
00048 namespace PLMath {
00049 
00050 
00051 //[-------------------------------------------------------]
00052 //[ Classes                                               ]
00053 //[-------------------------------------------------------]
00054 /**
00055 *  @brief
00056 *    Base octree class
00057 *
00058 *  @remarks
00059 *    Visualization of the coordinate system and were the octree
00060 *    sectors are:
00061 *    @code
00062 *                             top _\                  back
00063 *       y               ____________\__________________|
00064 *       |                           |\ 0  \ 1  \       |
00065 *       |                           | \----\----\
00066 *       |                           |  \_3__\_2__\_____|
00067 *       |________ x     ____________|  | 3  | 2  |     |
00068 *       \                   bottom _\  |____|____|    front
00069 *        \                           \ |    |    |
00070 *         \                           \|_7__|_6__|
00071 *         z                           ||         ||
00072 *                                     ||         ||
00073 *                                 left |         | right
00074 *                                      |         |
00075 *
00076 *    Sector position description:
00077 *           x       y         z
00078 *     0.  left     top       back
00079 *     1.  right    top       back
00080 *     2.  right    top       front
00081 *     3.  left     top       front
00082 *     4.  left     bottom    back
00083 *     5.  right    bottom    back
00084 *     6.  right    bottom    front
00085 *     7.  left     bottom    front
00086 *
00087 *    -x = left     +x = right
00088 *    -y = bottom   +y = top
00089 *    -z = back     +z = front
00090 *    @endcode
00091 */
00092 class Octree {
00093 
00094 
00095     //[-------------------------------------------------------]
00096     //[ Public functions                                      ]
00097     //[-------------------------------------------------------]
00098     public:
00099         /**
00100         *  @brief
00101         *    Constructor
00102         */
00103         PLMATH_API Octree();
00104 
00105         /**
00106         *  @brief
00107         *    Destructor
00108         */
00109         PLMATH_API virtual ~Octree();
00110 
00111         /**
00112         *  @brief
00113         *    Returns whether the octree is build or not
00114         *
00115         *  @return
00116         *    'true' if the octree is build, else 'false'
00117         */
00118         PLMATH_API bool IsBuild() const;
00119 
00120         /**
00121         *  @brief
00122         *    Initializes the octree
00123         *
00124         *  @param[in] pParent
00125         *    Parent octree, can be a null pointer
00126         *  @param[in] nSubdivide
00127         *    Subdivide
00128         *  @param[in] nMinGeometries
00129         *    Minimum geometries per octree
00130         *  @param[in] nIDOffset
00131         *    ID offset
00132         *
00133         *  @note
00134         *    - You should destroy the old octree before you initialize the new one!
00135         */
00136         PLMATH_API void Init(Octree *pParent = nullptr, int nSubdivide = -1, PLCore::uint32 nMinGeometries = 0, PLCore::uint32 nIDOffset = 0);
00137 
00138         /**
00139         *  @brief
00140         *    Destroys the octree
00141         */
00142         PLMATH_API void Destroy();
00143 
00144         /**
00145         *  @brief
00146         *    Returns the subdivision level
00147         *
00148         *  @return
00149         *    Subdivision level
00150         */
00151         PLMATH_API PLCore::uint32 GetLevel() const;
00152 
00153         /**
00154         *  @brief
00155         *    Returns whether the octree is currently visible or not
00156         *
00157         *  @return
00158         *    'true' if the octree is visible, else 'false'
00159         */
00160         PLMATH_API bool IsVisible() const;
00161 
00162         /**
00163         *  @brief
00164         *    Sets whether the octree is currently visible or not
00165         *
00166         *  @param[in] bVisible
00167         *    Should the octree be visible?
00168         */
00169         PLMATH_API void SetVisible(bool bVisible = true);
00170 
00171         /**
00172         *  @brief
00173         *    Returns the octrees bounding box
00174         *
00175         *  @return
00176         *    Bounding box
00177         */
00178         PLMATH_API const BoundingBox &GetBoundingBox() const;
00179 
00180         /**
00181         *  @brief
00182         *    Returns the subdivide
00183         *
00184         *  @return
00185         *    Subdivide
00186         */
00187         PLMATH_API int GetSubdivide() const;
00188 
00189         /**
00190         *  @brief
00191         *    Returns the minimum number of geometries per octree
00192         *
00193         *  @return
00194         *    Minimum number of geometries per octree
00195         */
00196         PLMATH_API PLCore::uint32 GetMinGeometries() const;
00197 
00198         /**
00199         *  @brief
00200         *    Returns the current position
00201         *
00202         *  @return
00203         *    Current position
00204         */
00205         PLMATH_API const Vector3 &GetPos() const;
00206 
00207         /**
00208         *  @brief
00209         *    Set the current position
00210         *
00211         *  @param[in] vPos
00212         *    New position
00213         */
00214         PLMATH_API void SetPos(const Vector3 &vPos);
00215 
00216         /**
00217         *  @brief
00218         *    Returns the current scale
00219         *
00220         *  @return
00221         *    Current scale
00222         */
00223         PLMATH_API const Vector3 &GetScale() const;
00224 
00225         /**
00226         *  @brief
00227         *    Set the current scale
00228         *
00229         *  @param[in] vScale
00230         *    New scale
00231         */
00232         PLMATH_API void SetScale(const Vector3 &vScale);
00233 
00234         /**
00235         *  @brief
00236         *    Returns the current rotation matrix
00237         *
00238         *  @return
00239         *    Current rotation matrix
00240         */
00241         PLMATH_API const Matrix3x3 &GetRot() const;
00242 
00243         /**
00244         *  @brief
00245         *    Set the current rotation matrix
00246         *
00247         *  @param[in] mRot
00248         *    New rotation matrix
00249         */
00250         PLMATH_API void SetRot(const Matrix3x3 &mRot);
00251 
00252         /**
00253         *  @brief
00254         *    Updates the visibility information of the octree
00255         *
00256         *  @param[in]  cPlaneSet
00257         *    Plane set to check
00258         *  @param[out] pBitset
00259         *    Optional (can be a null pointer) bit set which can for instance be filled in CustomVisible() and
00260         *    CustomInvisible() with current visibility information
00261         *
00262         *  @remarks
00263         *    The result must be handled in the derived octree class.
00264         *    The function it will call CustomVisible()/CustomInvisible()
00265         *    to mark an octree as visible or invisible.
00266         */
00267         PLMATH_API void UpdateVisibility(const PlaneSet &cPlaneSet, PLCore::Bitset *pBitset = nullptr);
00268 
00269         /**
00270         *  @brief
00271         *    Check whether a sphere intersects with this octree
00272         *
00273         *  @param[in] vPos
00274         *    Center of the sphere
00275         *  @param[in] fRadius
00276         *    Radius of the sphere
00277         *
00278         *  @see
00279         *    - UpdateVisibility()
00280         */
00281         PLMATH_API void CheckSphere(const Vector3 &vPos, float fRadius);
00282 
00283         /**
00284         *  @brief
00285         *    Check whether a box intersects with this octree
00286         *
00287         *  @param[in] cBox
00288         *    Box to test
00289         *
00290         *  @see
00291         *    - UpdateVisibility()
00292         */
00293         PLMATH_API void CheckBox(const BoundingBox &cBox);
00294 
00295 
00296     //[-------------------------------------------------------]
00297     //[ Protected data                                        ]
00298     //[-------------------------------------------------------]
00299     protected:
00300         PLCore::uint32   m_nIDOffset;       /**< ID offset from parent (0-7) */
00301         PLCore::uint32   m_nID;             /**< Octree ID */
00302         Octree          *m_pTopmost;        /**< Topmost octree (always valid!) */
00303         Octree          *m_pParent;         /**< Octree parent, can be a null pointer */
00304         PLCore::uint32   m_nLevel;          /**< Node level (0 = topmost) */
00305         PLCore::uint32   m_nNumOfChildren;  /**< Number of children */
00306         Octree         **m_ppChild;         /**< The children, can be a null pointer */
00307         BoundingBox      m_cBoundingBox;    /**< Octree bounding box */
00308         Vector3          m_vPos;            /**< World position (m_vPos+m_vBBCenter = real world position) */
00309         Vector3          m_vBBCenter;       /**< Original bounding box center */
00310         bool             m_bVisible;        /**< Is the octree visible? */
00311         bool             m_bBuild;          /**< is the octree build? */
00312         int              m_nSubdivide;      /**< Subdivide */
00313         PLCore::uint32   m_nMinGeometries;  /**< Minimum number of geometries per octree */
00314 
00315 
00316     //[-------------------------------------------------------]
00317     //[ Private functions                                     ]
00318     //[-------------------------------------------------------]
00319     private:
00320         /**
00321         *  @brief
00322         *    Copy constructor
00323         *
00324         *  @param[in] cSource
00325         *    Source to copy from
00326         */
00327         Octree(const Octree &cSource);
00328 
00329         /**
00330         *  @brief
00331         *    Copy operator
00332         *
00333         *  @param[in] cSource
00334         *    Source to copy from
00335         *
00336         *  @return
00337         *    Reference to this instance
00338         */
00339         Octree &operator =(const Octree &cSource);
00340 
00341 
00342     //[-------------------------------------------------------]
00343     //[ Private virtual Octree functions                      ]
00344     //[-------------------------------------------------------]
00345     private:
00346         /**
00347         *  @brief
00348         *    Custom visible function
00349         *
00350         *  @param[out] pBitset
00351         *    Optional bit set, can be a null pointer
00352         *
00353         *  @note
00354         *    - Is called during UpdateVisibility() if the octree is visible
00355         */
00356         PLMATH_API virtual void CustomVisible(PLCore::Bitset *pBitset = nullptr);
00357 
00358         /**
00359         *  @brief
00360         *    Destructor
00361         *
00362         *  @param[out] pBitset
00363         *    Optional bit set, can be a null pointer
00364         *
00365         *  @note
00366         *    - Is called during UpdateVisibility() if the octree is invisible
00367         */
00368         PLMATH_API virtual void CustomInvisible(PLCore::Bitset *pBitset = nullptr);
00369 
00370 
00371 };
00372 
00373 
00374 //[-------------------------------------------------------]
00375 //[ Namespace                                             ]
00376 //[-------------------------------------------------------]
00377 } // PLMath
00378 
00379 
00380 #endif // __PLMATH_OCTREE_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:50:58
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported