Skip to content

Commit 622f250

Browse files
committed
Fixes for bvh_node
Add default constructor. It shouldn't be used, but some compilers barf if it doesn't exist. I'm also normalizing toward the pointer and reference style that leaves the identifier separate -- the decorator immediately follows the type. Finally, some changes in theNextWeek didn't make it into the copy in theRestOfYourLife.
1 parent 5e39873 commit 622f250

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

books/RayTracingTheNextWeek.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,17 +692,20 @@
692692
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
693693
class bvh_node : public hittable {
694694
public:
695+
bvh_node();
696+
695697
bvh_node(hittable_list& list, double time0, double time1)
696-
: bvh_node(list.objects, 0, 0, time0, time1)
698+
: bvh_node(list.objects, 0, list.objects.size(), time0, time1)
697699
{}
698700

699701
bvh_node(
700-
std::vector<hittable*> &objects,
702+
std::vector<hittable*>& objects,
701703
size_t start, size_t end, double time0, double time1);
702704

703705
virtual bool hit(const ray& r, double tmin, double tmax, hit_record& rec) const;
704706
virtual bool bounding_box(double t0, double t1, aabb& output_box) const;
705707

708+
public:
706709
hittable *left;
707710
hittable *right;
708711
aabb box;
@@ -767,7 +770,9 @@
767770
#include <algorithm>
768771
...
769772

770-
bvh_node::bvh_node(std::vector<hittable*>& objects, int n, double time0, double time1) {
773+
bvh_node::bvh_node(
774+
std::vector<hittable*>& objects, size_t start, size_t end, double time0, double time1
775+
) {
771776
int axis = random_int(0,2);
772777
auto comparator = (axis == 0) ? box_x_compare
773778
: (axis == 1) ? box_y_compare

src/TheNextWeek/bvh.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
class bvh_node : public hittable {
2020
public:
21-
bvh_node::bvh_node(hittable_list& list, double time0, double time1)
21+
bvh_node();
22+
23+
bvh_node(hittable_list& list, double time0, double time1)
2224
: bvh_node(list.objects, 0, list.objects.size(), time0, time1)
2325
{}
2426

src/TheRestOfYourLife/bvh.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,27 @@
1818

1919
class bvh_node : public hittable {
2020
public:
21-
bvh_node::bvh_node(hittable_list &list, double time0, double time1)
22-
: bvh_node(list.objects, 0, 0, time0, time1)
21+
bvh_node();
22+
23+
bvh_node(hittable_list& list, double time0, double time1)
24+
: bvh_node(list.objects, 0, list.objects.size(), time0, time1)
2325
{}
2426

2527
bvh_node(
26-
std::vector<hittable*> &objects,
28+
std::vector<hittable*>& objects,
2729
size_t start, size_t end, double time0, double time1);
2830

2931
virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const;
3032
virtual bool bounding_box(double t0, double t1, aabb& output_box) const;
3133

34+
public:
3235
hittable *left;
3336
hittable *right;
3437
aabb box;
3538
};
3639

3740

38-
inline bool box_compare(const hittable *a, const hittable *b, int axis) {
41+
inline bool box_compare(const hittable* a, const hittable* b, int axis) {
3942
aabb box_a;
4043
aabb box_b;
4144

@@ -46,9 +49,9 @@ inline bool box_compare(const hittable *a, const hittable *b, int axis) {
4649
}
4750

4851

49-
bool box_x_compare (const hittable *a, const hittable *b) { return box_compare(a, b, 0); }
50-
bool box_y_compare (const hittable *a, const hittable *b) { return box_compare(a, b, 1); }
51-
bool box_z_compare (const hittable *a, const hittable *b) { return box_compare(a, b, 2); }
52+
bool box_x_compare (const hittable* a, const hittable* b) { return box_compare(a, b, 0); }
53+
bool box_y_compare (const hittable* a, const hittable* b) { return box_compare(a, b, 1); }
54+
bool box_z_compare (const hittable* a, const hittable* b) { return box_compare(a, b, 2); }
5255

5356

5457
bvh_node::bvh_node(

0 commit comments

Comments
 (0)