This repository has been archived by the owner on Mar 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.h
43 lines (35 loc) · 1.3 KB
/
box.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
//
// Created by lex on 4/13/18.
//
#ifndef RAYTRACER_BOX_H
#define RAYTRACER_BOX_H
#include "hitable_list.h"
#include "rect.h"
class box : public hitable {
public:
box() {}
box(const vec3& p0, const vec3& p1, material *mat_ptr);
virtual bool hit(const ray& r, float t0, float t1, hit_record& rec) const;
virtual bool bounding_box(float t0, float t1, aabb& box) const {
box = aabb(pmin, pmax);
return true;
}
vec3 pmin, pmax;
hitable *list_ptr;
};
box::box(const vec3 &p0, const vec3 &p1, material *mat_ptr) {
pmin = p0;
pmax = p1;
hitable **list = new hitable*[6];
list[0] = new xy_rect(p0.x(), p1.x(), p0.y(), p1.y(), p1.z(), mat_ptr);
list[1] = new flip_normals( new xy_rect(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), mat_ptr) );
list[2] = new xz_rect(p0.x(), p1.x(), p0.z(), p1.z(), p1.y(), mat_ptr);
list[3] = new flip_normals( new xz_rect(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), mat_ptr) );
list[4] = new yz_rect(p0.y(), p1.y(), p0.z(), p1.z(), p1.x(), mat_ptr);
list[5] = new flip_normals( new yz_rect(p0.y(), p1.y(), p0.z(), p1.z(), p1.x(), mat_ptr) );
list_ptr = new hitable_list(list, 6);
}
bool box::hit(const ray &r, float t0, float t1, hit_record &rec) const {
return list_ptr->hit(r, t0, t1, rec);
}
#endif //RAYTRACER_BOX_H