forked from kbladin/Monte_Carlo_Ray_Tracer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOctTreeAABB.h
61 lines (50 loc) · 1.12 KB
/
OctTreeAABB.h
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
60
61
#ifndef OCT_TREE_AABB
#define OCT_TREE_AABB
#include <vector>
#include <glm/glm.hpp>
#include "utils.h"
class Mesh;
// Axis aligned bounding box.
struct AABB
{
bool intersect(Ray r) const;
bool intersectTriangle(glm::vec3 p0, glm::vec3 p1, glm::vec3 p2) const;
glm::vec3 min_;
glm::vec3 max_;
};
// A node of an octree. Has eight child nodes
class OctNodeAABB
{
public:
OctNodeAABB(
OctNodeAABB* parent,
int depth,
Mesh* mesh,
glm::vec3 aabb_min,
glm::vec3 aabb_max);
~OctNodeAABB();
bool intersect(IntersectionData* id, Ray r) const;
protected:
Mesh* mesh_;
AABB aabb_;
std::vector<unsigned int> triangle_indices_;
OctNodeAABB* children_[8]; // Child nodes
// In order:
// children_[0] = left bottom far
// children_[1] = right bottom far
// children_[2] = left top far
// children_[3] = right top far
// children_[4] = left bottom near
// children_[5] = right bottom near
// children_[6] = left top near
// children_[7] = right top near
};
// An octree containing axis aligned bounding boxes
class OctTreeAABB : public OctNodeAABB
{
public:
OctTreeAABB(Mesh* mesh);
~OctTreeAABB();
private:
};
#endif