-
Notifications
You must be signed in to change notification settings - Fork 1
/
ObjectList.cpp
43 lines (36 loc) · 990 Bytes
/
ObjectList.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
#include "ObjectList.h"
bool
ObjectList::Intersect(const Ray& ray, float t_min, float t_max, hit_record_t& hit_record) const {
hit_record_t temp_hit;
bool hit = false;
float t_closest = t_max;
for (int i = 0; i < m_size; i++) {
if (m_list[i]->Intersect(ray, t_min, t_closest, temp_hit)) {
hit = true;
t_closest = temp_hit.m_t;
hit_record = temp_hit;
}
}
return hit;
}
bool
ObjectList::CreateBoundingBox(float t_start, float t_end, AABB& aabb) const
{
if(m_size < 1) {
return false;
}
AABB _temp_aabb;
if(m_list[0]->CreateBoundingBox(t_start, t_end, _temp_aabb)) {
aabb = _temp_aabb;
}
else {
return false;
}
for (int i = 1; i < m_size; i++) {
if(!m_list[i]->CreateBoundingBox(t_start, t_end, _temp_aabb)) {
return false;
}
aabb = AABB::Merge(aabb, _temp_aabb);
}
return true;
}