Skip to content

Commit e097b1c

Browse files
committed
Synchronize book 3 with source
In addition, in book 2 we use `objects` to build up the scene, where book 3 and source still used the old `world`. This change also synchronizes between these two versions.
1 parent 6eda475 commit e097b1c

File tree

3 files changed

+47
-57
lines changed

3 files changed

+47
-57
lines changed

books/RayTracingTheRestOfYourLife.html

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -757,35 +757,35 @@
757757

758758
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
759759
...
760-
color ray_color(
760+
color ray_color(...)
761761
...
762762

763763
hittable_list cornell_box() {
764-
hittable_list world;
764+
hittable_list objects;
765765

766766
auto red = make_shared<lambertian>(color(.65, .05, .05));
767767
auto white = make_shared<lambertian>(color(.73, .73, .73));
768768
auto green = make_shared<lambertian>(color(.12, .45, .15));
769769
auto light = make_shared<diffuse_light>(color(15, 15, 15));
770770

771-
world.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
772-
world.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
773-
world.add(make_shared<xz_rect>(213, 343, 227, 332, 554, light));
774-
world.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
775-
world.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
776-
world.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
771+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
772+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
773+
objects.add(make_shared<xz_rect>(213, 343, 227, 332, 554, light));
774+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
775+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
776+
objects.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
777777

778778
shared_ptr<hittable> box1 = make_shared<box>(point3(0,0,0), point3(165,330,165), white);
779779
box1 = make_shared<rotate_y>(box1, 15);
780780
box1 = make_shared<translate>(box1, vec3(265,0,295));
781-
world.add(box1);
781+
objects.add(box1);
782782

783783
shared_ptr<hittable> box2 = make_shared<box>(point3(0,0,0), point3(165,165,165), white);
784784
box2 = make_shared<rotate_y>(box2, -18);
785785
box2 = make_shared<translate>(box2, vec3(130,0,65));
786-
world.add(box2);
786+
objects.add(box2);
787787

788-
return world;
788+
return objects;
789789
}
790790

791791
int main() {
@@ -1524,21 +1524,21 @@
15241524

15251525
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
15261526
hittable_list cornell_box() {
1527-
hittable_list world;
1527+
hittable_list objects;
15281528

15291529
auto red = make_shared<lambertian>(color(.65, .05, .05));
15301530
auto white = make_shared<lambertian>(color(.73, .73, .73));
15311531
auto green = make_shared<lambertian>(color(.12, .45, .15));
15321532
auto light = make_shared<diffuse_light>(color(15, 15, 15));
15331533

1534-
world.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
1535-
world.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
1534+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
1535+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
15361536
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1537-
world.add(make_shared<flip_face>(make_shared<xz_rect>(213, 343, 227, 332, 554, light)));
1537+
objects.add(make_shared<flip_face>(make_shared<xz_rect>(213, 343, 227, 332, 554, light)));
15381538
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1539-
world.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
1540-
world.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
1541-
world.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
1539+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
1540+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
1541+
objects.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
15421542

15431543
...
15441544
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -2227,23 +2227,23 @@
22272227
</div>
22282228

22292229
<div class='together'>
2230-
We also need to change the block to metal.
2230+
We also need to change the block to metal. We'll also swap out the short block for a glass sphere.
22312231

22322232
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2233-
hittable_list cornell_box(camera& cam, double aspect) {
2234-
hittable_list world;
2233+
hittable_list cornell_box() {
2234+
hittable_list objects;
22352235

22362236
auto red = make_shared<lambertian>(color(.65, .05, .05));
22372237
auto white = make_shared<lambertian>(color(.73, .73, .73));
22382238
auto green = make_shared<lambertian>(color(.12, .45, .15));
22392239
auto light = make_shared<diffuse_light>(color(15, 15, 15));
22402240

2241-
world.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
2242-
world.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
2243-
world.add(make_shared<xz_rect>(213, 343, 227, 332, 554, light));
2244-
world.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
2245-
world.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
2246-
world.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
2241+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
2242+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
2243+
objects.add(make_shared<flip_face>(make_shared<xz_rect>(213, 343, 227, 332, 554, light)));
2244+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
2245+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
2246+
objects.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
22472247

22482248

22492249
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
@@ -2252,25 +2252,14 @@
22522252
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
22532253
box1 = make_shared<rotate_y>(box1, 15);
22542254
box1 = make_shared<translate>(box1, vec3(265,0,295));
2255-
world.add(box1);
2256-
2257-
shared_ptr<hittable> box2 = make_shared<box>(point3(0,0,0), point3(165,165,165), white);
2258-
box2 = make_shared<rotate_y>(box2, -18);
2259-
box2 = make_shared<translate>(box2, vec3(130,0,65);
2260-
world.add(box2);
2261-
2262-
point3 lookfrom(278, 278, -800);
2263-
point3 lookat(278, 278, 0);
2264-
vec3 vup(0, 1, 0);
2265-
auto dist_to_focus = 10.0;
2266-
auto aperture = 0.0;
2267-
auto vfov = 40.0;
2268-
auto time0 = 0.0;
2269-
auto time1 = 1.0;
2255+
objects.add(box1);
22702256

2271-
cam = camera(lookfrom, lookat, vup, vfov, aspect, aperture, dist_to_focus, time0, time1);
2257+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
2258+
auto glass = make_shared<dielectric>(1.5);
2259+
objects.add(make_shared<sphere>(point3(190,90,190), 90 , glass));
2260+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
22722261

2273-
return world;
2262+
return objects;
22742263
}
22752264
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22762265
[Listing [scene-cornell-al]: <kbd>[main.cc]</kbd> Cornell box scene with aluminum material]

src/TheNextWeek/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ hittable_list cornell_box() {
150150
auto red = make_shared<lambertian>(color(.65, .05, .05));
151151
auto white = make_shared<lambertian>(color(.73, .73, .73));
152152
auto green = make_shared<lambertian>(color(.12, .45, .15));
153-
auto light = make_shared<diffuse_light>(color(15,15,15));
153+
auto light = make_shared<diffuse_light>(color(15, 15, 15));
154154

155155
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
156156
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));

src/TheRestOfYourLife/main.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,30 @@ color ray_color(
6363

6464

6565
hittable_list cornell_box() {
66-
hittable_list world;
66+
hittable_list objects;
6767

6868
auto red = make_shared<lambertian>(color(.65, .05, .05));
6969
auto white = make_shared<lambertian>(color(.73, .73, .73));
7070
auto green = make_shared<lambertian>(color(.12, .45, .15));
7171
auto light = make_shared<diffuse_light>(color(15, 15, 15));
7272

73-
world.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
74-
world.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
75-
world.add(make_shared<flip_face>(make_shared<xz_rect>(213, 343, 227, 332, 554, light)));
76-
world.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
77-
world.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
78-
world.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
73+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 555, green));
74+
objects.add(make_shared<yz_rect>(0, 555, 0, 555, 0, red));
75+
objects.add(make_shared<flip_face>(make_shared<xz_rect>(213, 343, 227, 332, 554, light)));
76+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 555, white));
77+
objects.add(make_shared<xz_rect>(0, 555, 0, 555, 0, white));
78+
objects.add(make_shared<xy_rect>(0, 555, 0, 555, 555, white));
7979

80-
shared_ptr<hittable> box1 = make_shared<box>(point3(0,0,0), point3(165,330,165), white);
80+
shared_ptr<material> aluminum = make_shared<metal>(color(0.8, 0.85, 0.88), 0.0);
81+
shared_ptr<hittable> box1 = make_shared<box>(point3(0,0,0), point3(165,330,165), aluminum);
8182
box1 = make_shared<rotate_y>(box1, 15);
8283
box1 = make_shared<translate>(box1, vec3(265,0,295));
83-
world.add(box1);
84+
objects.add(box1);
8485

8586
auto glass = make_shared<dielectric>(1.5);
86-
world.add(make_shared<sphere>(point3(190,90,190), 90 , glass));
87+
objects.add(make_shared<sphere>(point3(190,90,190), 90 , glass));
8788

88-
return world;
89+
return objects;
8990
}
9091

9192

@@ -120,7 +121,7 @@ int main() {
120121
auto time1 = 1.0;
121122

122123
camera cam(lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, time0, time1);
123-
124+
124125
// Render
125126

126127
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";

0 commit comments

Comments
 (0)