Skip to content

Commit 571f816

Browse files
committed
Make world ref const in ray_color() function
1 parent f7432bf commit 571f816

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@
10731073
#include <iostream>
10741074

10751075
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1076-
vec3 ray_color(const ray& r, hittable& world) {
1076+
vec3 ray_color(const ray& r, const hittable& world) {
10771077
hit_record rec;
10781078
if (world.hit(r, 0.0, infinity, rec)) {
10791079
return 0.5 * (rec.normal + vec3(1,1,1));
@@ -1395,7 +1395,7 @@
13951395
Then update the `ray_color()` function to use the new random direction generator:
13961396

13971397
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1398-
vec3 ray_color(const ray& r, hittable& world) {
1398+
vec3 ray_color(const ray& r, const hittable& world) {
13991399
hit_record rec;
14001400
if (world.hit(r, 0.0, infinity, rec)) {
14011401
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
@@ -1419,7 +1419,7 @@
14191419
depth, returning no light contribution at the maximum depth:
14201420

14211421
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1422-
vec3 ray_color(const ray& r, hittable& world, int depth) {
1422+
vec3 ray_color(const ray& r, const hittable& world, int depth) {
14231423
hit_record rec;
14241424
if (world.hit(r, 0.0, infinity, rec)) {
14251425
// If we've exceeded the ray bounce limit, no more light is gathered.
@@ -1558,7 +1558,7 @@
15581558
function.
15591559

15601560
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1561-
vec3 ray_color(const ray& r, hittable& world, int depth) {
1561+
vec3 ray_color(const ray& r, const hittable& world, int depth) {
15621562
hit_record rec;
15631563
if (world.hit(r, 0.0, infinity, rec)) {
15641564
// If we've exceeded the ray bounce limit, no more light is gathered.
@@ -1634,7 +1634,7 @@
16341634
Plugging the new formula into the `ray_color()` function:
16351635

16361636
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1637-
vec3 ray_color(const ray& r, hittable& world, int depth) {
1637+
vec3 ray_color(const ray& r, const hittable& world, int depth) {
16381638
hit_record rec;
16391639
if (world.hit(r, 0.0, infinity, rec)) {
16401640
// If we've exceeded the ray bounce limit, no more light is gathered.
@@ -1879,7 +1879,7 @@
18791879
We need to modify the color function to use this:
18801880

18811881
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1882-
vec3 ray_color(const ray& r, hittable& world, int depth) {
1882+
vec3 ray_color(const ray& r, const hittable& world, int depth) {
18831883
hit_record rec;
18841884
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
18851885
if (world.hit(r, 0.001, infinity, rec)) {

books/RayTracingTheNextWeek.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@
17411741
the new `emitted` value.
17421742

17431743
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1744-
vec3 ray_color(const ray& r, const vec3& background, hittable& world, int depth) {
1744+
vec3 ray_color(const ray& r, const vec3& background, const hittable& world, int depth) {
17451745
hit_record rec;
17461746

17471747
// If we've exceeded the ray bounce limit, no more light is gathered.

books/RayTracingTheRestOfYourLife.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@
842842
And the color function gets a minor modification:
843843

844844
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
845-
vec3 ray_color(const ray& r, const vec3& background, hittable& world, int depth) {
845+
vec3 ray_color(const ray& r, const vec3& background, const hittable& world, int depth) {
846846
hit_record rec;
847847

848848
// If we've exceeded the ray bounce limit, no more light is gathered.
@@ -1304,7 +1304,7 @@
13041304
that math and get the concept, we can add it (see the highlighted region):
13051305

13061306
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1307-
vec3 ray_color(const ray& r, const vec3& background, hittable& world, int depth) {
1307+
vec3 ray_color(const ray& r, const vec3& background, const hittable& world, int depth) {
13081308
hit_record rec;
13091309

13101310
// If we've exceeded the ray bounce limit, no more light is gathered.
@@ -1486,7 +1486,7 @@
14861486
change variable `pdf` to some other variable name to avoid a name conflict with the new `pdf` class.
14871487

14881488
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1489-
vec3 ray_color(const ray& r, const vec3& background, hittable& world, int depth) {
1489+
vec3 ray_color(const ray& r, const vec3& background, const hittable& world, int depth) {
14901490
hit_record rec;
14911491

14921492
// If we've exceeded the ray bounce limit, no more light is gathered.
@@ -1627,7 +1627,7 @@
16271627
And then change `ray_color()`:
16281628

16291629
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1630-
vec3 ray_color(const ray& r, const vec3& background, hittable& world, int depth) {
1630+
vec3 ray_color(const ray& r, const vec3& background, const hittable& world, int depth) {
16311631
hit_record rec;
16321632

16331633
// If we've exceeded the ray bounce limit, no more light is gathered.
@@ -1708,7 +1708,7 @@
17081708
vec3 ray_color(
17091709
const ray& r,
17101710
const vec3& background,
1711-
hittable& world,
1711+
const hittable& world,
17121712
shared_ptr<hittable> lights,
17131713
int depth
17141714
) {
@@ -1908,7 +1908,7 @@
19081908
vec3 ray_color(
19091909
const ray& r,
19101910
const vec3& background,
1911-
hittable& world,
1911+
const hittable& world,
19121912
shared_ptr<hittable> lights,
19131913
int depth
19141914
) {
@@ -1984,7 +1984,7 @@
19841984
vec3 ray_color(
19851985
const ray& r,
19861986
const vec3& background,
1987-
hittable& world,
1987+
const hittable& world,
19881988
shared_ptr<hittable> lights,
19891989
int depth
19901990
) {

src/InOneWeekend/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <iostream>
1818

1919

20-
vec3 ray_color(const ray& r, hittable& world, int depth) {
20+
vec3 ray_color(const ray& r, const hittable& world, int depth) {
2121
hit_record rec;
2222

2323
// If we've exceeded the ray bounce limit, no more light is gathered.

src/TheNextWeek/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <iostream>
2424

2525

26-
vec3 ray_color(const ray& r, const vec3& background, hittable& world, int depth) {
26+
vec3 ray_color(const ray& r, const vec3& background, const hittable& world, int depth) {
2727
hit_record rec;
2828

2929
// If we've exceeded the ray bounce limit, no more light is gathered.

src/TheRestOfYourLife/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
vec3 ray_color(
2323
const ray& r,
2424
const vec3& background,
25-
hittable& world,
25+
const hittable& world,
2626
shared_ptr<hittable> lights,
2727
int depth
2828
) {

0 commit comments

Comments
 (0)