Skip to content

Commit a673abb

Browse files
committed
Refactor: define & use camera up vector
1 parent 6812beb commit a673abb

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,7 +2450,7 @@
24502450

24512451
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
24522452
auto aspect_ratio = double(image_width) / image_height;
2453-
camera cam(vec3(-2,2,1), vec3(0,0,-1), vec3(0,1,0), 90, aspect_ratio);
2453+
camera cam(vec3(-2,2,1), vec3(0,0,-1), vup, 90, aspect_ratio);
24542454
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24552455
[Listing [scene-free-view]: <kbd>[main.cc]</kbd> Scene with alternate viewpoint]
24562456

@@ -2585,11 +2585,12 @@
25852585
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
25862586
vec3 lookfrom(3,3,2);
25872587
vec3 lookat(0,0,-1);
2588+
vec3 vup(0,1,0);
25882589
auto dist_to_focus = (lookfrom-lookat).length();
25892590
auto aperture = 2.0;
25902591

25912592
auto aspect_ratio = double(image_width) / image_height;
2592-
camera cam(lookfrom, lookat, vec3(0,1,0), 20, aspect_ratio, aperture, dist_to_focus);
2593+
camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus);
25932594
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25942595
[Listing [scene-camera-dof]: <kbd>[main.cc]</kbd> Scene camera with depth-of-field]
25952596

books/RayTracingTheNextWeek.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,12 @@
320320
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
321321
vec3 lookfrom(13,2,3);
322322
vec3 lookat(0,0,0);
323+
vec3 vup(0,1,0);
323324
auto dist_to_focus = 10.0;
324325
auto aperture = 0.0;
325326

326327
auto aspect_ratio = double(image_width) / image_height;
327-
camera cam(lookfrom, lookat, vec3(0,1,0), 20, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
328+
camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
328329
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
329330
[Listing [scene-spheres-moving-camera]: <kbd>[main.cc]</kbd> Viewing parameters]
330331

@@ -1010,11 +1011,12 @@
10101011
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
10111012
vec3 lookfrom(13,2,3);
10121013
vec3 lookat(0,0,0);
1014+
vec3 vup(0,1,0);
10131015
auto dist_to_focus = 10.0;
10141016
auto aperture = 0.0;
10151017

10161018
auto aspect_ratio = double(image_width) / image_height;
1017-
camera cam(lookfrom, lookat, vec3(0,1,0), 20, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
1019+
camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
10181020
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10191021
[Listing [scene-two-checker-view]: <kbd>[main.cc]</kbd> Viewing parameters]
10201022

@@ -1165,11 +1167,12 @@
11651167
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
11661168
vec3 lookfrom(13,2,3);
11671169
vec3 lookat(0,0,0);
1170+
vec3 vup(0,1,0);
11681171
auto dist_to_focus = 10.0;
11691172
auto aperture = 0.0;
11701173

11711174
auto aspect_ratio = double(image_width) / image_height;
1172-
camera cam(lookfrom, lookat, vec3(0,1,0), 20, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
1175+
camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
11731176
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11741177
[Listing [scene-perlin-view]: <kbd>[main.cc]</kbd> Viewing parameters]
11751178
</div>
@@ -1988,13 +1991,14 @@
19881991
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
19891992
vec3 lookfrom(278, 278, -800);
19901993
vec3 lookat(278,278,0);
1994+
vec3 vup(0,1,0);
19911995
auto dist_to_focus = 10.0;
19921996
auto aperture = 0.0;
19931997
auto vfov = 40.0;
19941998

19951999
auto aspect_ratio = double(image_width) / image_height;
19962000
camera cam(
1997-
lookfrom, lookat, vec3(0,1,0), vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
2001+
lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
19982002
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19992003
[Listing [cornell-box-view]: <kbd>[main.cc]</kbd> Viewing parameters]
20002004
</div>

books/RayTracingTheRestOfYourLife.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,14 +755,14 @@
755755

756756
vec3 lookfrom(278, 278, -800);
757757
vec3 lookat(278, 278, 0);
758-
vec3 up(0, 1, 0);
758+
vec3 vup(0, 1, 0);
759759
auto dist_to_focus = 10.0;
760760
auto aperture = 0.0;
761761
auto vfov = 40.0;
762762
auto t0 = 0.0;
763763
auto t1 = 1.0;
764764

765-
cam = camera(lookfrom, lookat, up, vfov, aspect, aperture, dist_to_focus, t0, t1);
765+
cam = camera(lookfrom, lookat, vup, vfov, aspect, aperture, dist_to_focus, t0, t1);
766766

767767
return world;
768768
}
@@ -2029,14 +2029,14 @@
20292029

20302030
vec3 lookfrom(278, 278, -800);
20312031
vec3 lookat(278, 278, 0);
2032-
vec3 up(0, 1, 0);
2032+
vec3 vup(0, 1, 0);
20332033
auto dist_to_focus = 10.0;
20342034
auto aperture = 0.0;
20352035
auto vfov = 40.0;
20362036
auto t0 = 0.0;
20372037
auto t1 = 1.0;
20382038

2039-
cam = camera(lookfrom, lookat, up, vfov, aspect, aperture, dist_to_focus, t0, t1);
2039+
cam = camera(lookfrom, lookat, vup, vfov, aspect, aperture, dist_to_focus, t0, t1);
20402040

20412041
return world;
20422042
}

src/InOneWeekend/main.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ int main() {
9393

9494
vec3 lookfrom(13,2,3);
9595
vec3 lookat(0,0,0);
96+
vec3 vup(0,1,0);
9697
auto dist_to_focus = 10.0;
9798
auto aperture = 0.1;
9899

99100
auto aspect_ratio = double(image_width) / image_height;
100-
camera cam(lookfrom, lookat, vec3(0,1,0), 20, aspect_ratio, aperture, dist_to_focus);
101+
camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus);
101102

102103
for (int j = image_height-1; j >= 0; --j) {
103104
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;

src/TheNextWeek/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,16 +374,16 @@ int main() {
374374

375375
vec3 lookfrom(278, 278, -800);
376376
//vec3 lookfrom(478, 278, -600);
377-
vec3 lookat(278,278,0);
378377
//vec3 lookfrom(0, 0, 6);
378+
vec3 lookat(278,278,0);
379379
//vec3 lookat(0,0,0);
380+
vec3 vup(0,1,0);
380381
auto dist_to_focus = 10.0;
381382
auto aperture = 0.0;
382383
auto vfov = 40.0;
383384

384385
auto aspect_ratio = double(image_width) / image_height;
385-
camera cam(
386-
lookfrom, lookat, vec3(0,1,0), vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
386+
camera cam(lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
387387

388388
for (int j = image_height-1; j >= 0; --j) {
389389
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;

0 commit comments

Comments
 (0)