-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccel.cpp
executable file
·49 lines (41 loc) · 1.17 KB
/
Accel.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
#include "Accel.h"
#include "Ray.h"
#include "Console.h"
#include "BBox.h"
void
Accel::build(Objects * objs)
{
// construct the bounding volume hierarchy
m_objects = objs;
const clock_t begin_time = std::clock();
BBox initBBox = BBox();
initBBox.expandBBox(*m_objects);
//initBBox.print();
kdroot = new KdNode(*m_objects, initBBox, 0);
kdroot->build();
float cost = float (clock() - begin_time) / CLOCKS_PER_SEC;
printf("%.5f s to construct Kd-Tree.\n", cost);
printf("Number of kdnodes: %d\n", KdNode::getNodeNumbers());
printf("Number of leave: %d\n", KdNode::getLeafNumbers());
}
bool
Accel::intersect(HitInfo& minHit, const Ray& ray, float tMin, float tMax) const
{
// Here you would need to traverse the acceleration data structure to perform ray-intersection
// acceleration. For now we just intersect every object.
bool hit = false;
minHit.t = MIRO_TMAX;
/*
for (size_t i = 0; i < m_objects->size(); ++i)
{
if ((*m_objects)[i]->intersect(tempMinHit, ray, tMin, tMax))
{
hit = true;
if (tempMinHit.t < minHit.t)
minHit = tempMinHit;
}
}
*/
hit = kdroot->traverse(minHit, ray, tMin, tMax);
return hit;
}