"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSPhysicsLib/Src/SpatialPartitions/LSPQuadTree.h

00001 
00017 #ifndef __LSP_QUADTREE_H__
00018 #define __LSP_QUADTREE_H__
00019 
00020 #include "../LSPPhysicsLib.h"
00021 #include "LSPQuadTreeNode.h"
00022 #include "Vector/LSTLVector.h"
00023 
00024 namespace lsp {
00025 
00033         class CQuadTree {
00034         public :
00035                 // == Various constructors.
00036                 LSE_CALLCTOR                                                    CQuadTree();
00037                 LSE_CALLCTOR                                                    ~CQuadTree();
00038 
00039 
00040                 // == Functions.
00047                 LSBOOL LSE_CALL                                                 CreateQuadTree( LSREAL _fSize );
00048 
00052                 LSVOID LSE_CALL                                                 Reset();
00053 
00059                 const CQuadTreeNode * LSE_CALL                  Root() const;
00060 
00068                 LSBOOL LSE_CALL                                                 InsertObject( CQuadTreeObject * _pqtoObject );
00069 
00078                 LSBOOL LSE_CALL                                                 FindObjects( const CAabb2d &_a2Box, CVector<CQuadTreeObject *, LSUINT32> &_vReturn );
00079 
00080 
00081         protected :
00082                 // == Members.
00087                 LSUINT8 *                                                               m_pui8Nodes;
00088 
00092                 CQuadTreeNode *                                                 m_pqtnLevels[8];
00093 
00097                 LSREAL                                                                  m_fRadius;
00098 
00102                 LSREAL                                                                  m_fInvRadius;
00103 
00104 
00105                 // == Functions.
00111                 LSE_INLINE CQuadTreeNode * LSE_CALL             Root();
00112 
00120                 static LSE_INLINE LSBOOL LSE_CALL               NodeIsInBounds( const CQuadTreeNode * _pqtnNode, const CAabb2d &_a2Box );
00121 
00130                 static LSBOOL LSE_CALL                                  GatherObjectsInNode( const CQuadTreeNode * _pqtnNode, const CAabb2d &_a2Box, CVector<CQuadTreeObject *, LSUINT32> &_vReturn );
00131         };
00132 
00133 
00134         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00135         // DEFINITIONS
00136         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00137         // == Functions.
00143         LSE_INLINE const CQuadTreeNode * LSE_CALL CQuadTree::Root() const { return reinterpret_cast<CQuadTreeNode *>(m_pui8Nodes); }
00144 
00150         LSE_INLINE CQuadTreeNode * LSE_CALL CQuadTree::Root() { return reinterpret_cast<CQuadTreeNode *>(m_pui8Nodes); }
00151 
00159         LSE_INLINE LSBOOL LSE_CALL CQuadTree::NodeIsInBounds( const CQuadTreeNode * _pqtnNode, const CAabb2d &_a2Box ) {
00160                 LSREAL fRad = _pqtnNode->GetRadius();
00161                 // TODO: Try to vectorize this.
00162                 return (_pqtnNode->GetCenter().x - fRad <= _a2Box.m_vMax.x) && (_pqtnNode->GetCenter().y - fRad <= _a2Box.m_vMax.y) &&
00163                         (_pqtnNode->GetCenter().x + fRad >= _a2Box.m_vMin.x) && (_pqtnNode->GetCenter().y + fRad >= _a2Box.m_vMin.y);
00164         }
00165 
00166 }       // namespace lsp
00167 
00168 #endif  // __LSP_QUADTREE_H__
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator