-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaabb.h
More file actions
46 lines (38 loc) · 1.43 KB
/
Copy pathaabb.h
File metadata and controls
46 lines (38 loc) · 1.43 KB
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
#ifndef AABH
#define AABH
#include "ray.h"
#include "hittable.h"
inline float ffmin(float a, float b) {return a < b ? a : b; }
inline float ffmax(float a, float b) {return a > b ? a : b; }
class aabb {
public:
aabb() {}
aabb(const vec3 &a, const vec3 &b) { _min=a; _max=b; }
vec3 min() const { return _min; }
vec3 max() const { return _max; }
bool hit(const ray &r, float tmin, float tmax) const {
for (int a = 0; a < 3; a++) {
float t0 = ffmin((_min[a] - r.origin()[a]) / r.direction()[a],
(_max[a] - r.origin()[a]) / r.direction()[a]);
float t1 = ffmax((_min[a] - r.origin()[a]) / r.direction()[a],
(_max[a] - r.origin()[a]) / r.direction()[a]);
tmin = ffmax(t0, tmin);
tmax = ffmin(t1, tmax);
if (tmax <= tmin)
return false;
}
return true;
}
vec3 _min;
vec3 _max;
};
aabb surrounding_box(aabb box0, aabb box1) {
vec3 small( ffmin(box0.min().x(), box1.min().x()),
ffmin(box0.min().y(), box1.min().y()),
ffmin(box0.min().z(), box1.min().z()));
vec3 big ( ffmax(box0.max().x(), box1.max().x()),
ffmax(box0.max().y(), box1.max().y()),
ffmax(box0.max().z(), box1.max().z()));
return aabb(small,big);
}
#endif