-
Notifications
You must be signed in to change notification settings - Fork 3
/
PrimitiveList.h
51 lines (40 loc) · 1.08 KB
/
PrimitiveList.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
#pragma once
#include "Ray.h"
#include "RayHit.h"
template<typename PrimitiveType>
struct PrimitiveList {
PrimitiveType * primitives = nullptr;
int primitive_count;
inline PrimitiveList(int count) : primitive_count(count) {
if (primitive_count > 0) {
primitives = new PrimitiveType[primitive_count];
}
}
inline ~PrimitiveList() {
if (primitives) {
delete[] primitives;
}
}
inline void update() const {
for (int i = 0; i < primitive_count; i++) {
primitives[i].update();
}
}
inline void trace(const Ray & ray, RayHit & ray_hit) const {
for (int i = 0; i < primitive_count; i++) {
primitives[i].trace(ray, ray_hit);
}
}
inline SIMD_float intersect(const Ray & ray, SIMD_float max_distance) const {
SIMD_float result(0.0f);
for (int i = 0; i < primitive_count; i++) {
result = result | primitives[i].intersect(ray, max_distance);
if (SIMD_float::all_true(result)) break;
}
return result;
}
inline PrimitiveType & operator[](int index) const {
assert(index >= 0 && index < primitive_count);
return primitives[index];
}
};