11#ifndef BOX_HPP
22#define BOX_HPP
33
4+ #include < array>
5+
6+ #include " primitives.hpp"
47#include " rectangle.hpp"
5- #include " rtweekend.hpp"
6- #include " visit.hpp"
78
9+ namespace raytracer ::scene {
810// / This class implements a axis aligned cuboid using 6 rectangles
911class box {
1012 public:
@@ -17,39 +19,19 @@ class box {
1719 , box_max { p1 }
1820 , material_type { mat_type } {
1921 // / Add six sides of the box based on box_min and box_max to sides
20- sides[0 ] = xy_rect (p0.x (), p1.x (), p0.y (), p1.y (), p1.z (), mat_type);
21- sides[1 ] = xy_rect (p0.x (), p1.x (), p0.y (), p1.y (), p0.z (), mat_type);
22- sides[2 ] = xz_rect (p0.x (), p1.x (), p0.z (), p1.z (), p1.y (), mat_type);
23- sides[3 ] = xz_rect (p0.x (), p1.x (), p0.z (), p1.z (), p0.y (), mat_type);
24- sides[4 ] = yz_rect (p0.y (), p1.y (), p0.z (), p1.z (), p1.x (), mat_type);
25- sides[5 ] = yz_rect (p0.y (), p1.y (), p0.z (), p1.z (), p0.x (), mat_type);
26- }
27-
28- // / Compute ray interaction with the box
29- bool hit (auto & ctx, const ray& r, real_t min, real_t max, hit_record& rec,
30- material_t & hit_material_type) const {
31- hit_record temp_rec;
32- material_t temp_material_type;
33- auto hit_anything = false ;
34- auto closest_so_far = max;
35- // Checking if the ray hits any of the sides
36- for (const auto & side : sides) {
37- if (dev_visit (hittable_hit_visitor (ctx, r, min, closest_so_far, temp_rec,
38- temp_material_type),
39- side)) {
40- hit_anything = true ;
41- closest_so_far = temp_rec.t ;
42- rec = temp_rec;
43- hit_material_type = temp_material_type;
44- }
45- }
46- return hit_anything;
22+ sides[0 ] = xy_rect (p0.x (), p1.x (), p0.y (), p1.y (), p1.z (), material_type);
23+ sides[1 ] = xy_rect (p0.x (), p1.x (), p0.y (), p1.y (), p0.z (), material_type);
24+ sides[2 ] = xz_rect (p0.x (), p1.x (), p0.z (), p1.z (), p1.y (), material_type);
25+ sides[3 ] = xz_rect (p0.x (), p1.x (), p0.z (), p1.z (), p0.y (), material_type);
26+ sides[4 ] = yz_rect (p0.y (), p1.y (), p0.z (), p1.z (), p1.x (), material_type);
27+ sides[5 ] = yz_rect (p0.y (), p1.y (), p0.z (), p1.z (), p0.x (), material_type);
4728 }
4829
4930 point box_min;
5031 point box_max;
5132 material_t material_type;
5233 std::array<rectangle_t , 6 > sides;
5334};
35+ } // namespace raytracer::scene
5436
5537#endif
0 commit comments