-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuadTreeOccupant.cpp
59 lines (47 loc) · 1.03 KB
/
QuadTreeOccupant.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "QuadTreeOccupant.h"
#include "QuadTreeNode.h"
#include "QuadTree.h"
#include "Vec2f.h"
#include <assert.h>
namespace qdt
{
QuadTreeOccupant::QuadTreeOccupant()
: m_aabb(Vec2f(0.0f, 0.0f), Vec2f(1.0f, 1.0f)),
m_pQuadTreeNode(NULL), m_pQuadTree(NULL)
{
}
void QuadTreeOccupant::TreeUpdate()
{
if(m_pQuadTree == NULL)
return;
if(m_pQuadTreeNode == NULL)
{
// If fits in the root now, add it
QuadTreeNode* pRootNode = m_pQuadTree->m_pRootNode.get();
if(pRootNode->m_region.Contains(m_aabb))
{
// Remove from outside root and add to tree
m_pQuadTree->m_outsideRoot.erase(this);
pRootNode->Add(this);
}
}
else
m_pQuadTreeNode->Update(this);
}
void QuadTreeOccupant::RemoveFromTree()
{
if(m_pQuadTreeNode == NULL)
{
// Not in a node, should be outside root then
assert(m_pQuadTree != NULL);
m_pQuadTree->m_outsideRoot.erase(this);
m_pQuadTree->OnRemoval();
}
else
m_pQuadTreeNode->Remove(this);
}
const AABB &QuadTreeOccupant::GetAABB()
{
return m_aabb;
}
}