-
Notifications
You must be signed in to change notification settings - Fork 25
/
octree.cpp
51 lines (42 loc) · 1.3 KB
/
octree.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
#include "octree.h"
octree::octree(FIntVector position, int depth, int id) : m_position(position), m_depth(depth), m_id(id), m_bFather(false)
{
check(depth <= 19);
}
int octree::size()
{
return 16 << m_depth;
}
FIntVector octree::getMin(int x, int y, int z)
{
return position - FIntVector(size() / 2, size() / 2, size() / 2); // low left corner
}
FIntVector octree::getMax(int x, int y, int z)
{
return position + FIntVector(size() / 2, size() / 2, size() / 2); // top right corner
}
bool octree::bLeaf()
{
return !m_bFather;
}
bool octree::bInTree(int x, int y, int z)
{
return position.X - size() / 2 <= x && x < position.X + size() / 2 && position.X - size() / 2 <= x && x < position.X + size() / 2 && position.X - size() / 2 <= x && x < position.X + size() / 2; // from gamedev.net
}
FIntVector octree::glconvert(int x, int y, int z)
{
return FIntVector(x - (position.X - size() / 2), y - (position.Y - size() / 2), z - (position.Z - size() / 2));
}
FIntVector octree::lgconvert(int x, int y, int z)
{
return FIntVector(x + (position.X + size() / 2), y + (position.Y - size() / 2), z + (position.Z - size() / 2));
}
int octree::depth_id(int depth)
{
check(depth <= 19);
int result_id = 1;
for(int i = 0; i < depth; i++){
result *= 9;
}
return result_id;
}