Skip to content

Commit 90a5bf0

Browse files
committed
Move aspect_ratio to image parameters
1 parent fc08f65 commit 90a5bf0

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,7 +2452,8 @@
24522452
This allows us to change the viewpoint:
24532453

24542454
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2455-
auto aspect_ratio = double(image_width) / image_height;
2455+
const auto aspect_ratio = double(image_width) / image_height;
2456+
...
24562457
camera cam(vec3(-2,2,1), vec3(0,0,-1), vup, 90, aspect_ratio);
24572458
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24582459
[Listing [scene-free-view]: <kbd>[main.cc]</kbd> Scene with alternate viewpoint]
@@ -2586,13 +2587,14 @@
25862587
Using a big aperture:
25872588

25882589
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2590+
const auto aspect_ratio = double(image_width) / image_height;
2591+
...
25892592
vec3 lookfrom(3,3,2);
25902593
vec3 lookat(0,0,-1);
25912594
vec3 vup(0,1,0);
25922595
auto dist_to_focus = (lookfrom-lookat).length();
25932596
auto aperture = 2.0;
25942597

2595-
auto aspect_ratio = double(image_width) / image_height;
25962598
camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus);
25972599
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25982600
[Listing [scene-camera-dof]: <kbd>[main.cc]</kbd> Scene camera with depth-of-field]

books/RayTracingTheNextWeek.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,14 @@
318318
And with these viewing parameters:
319319

320320
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
321+
const auto aspect_ratio = double(image_width) / image_height;
322+
...
321323
vec3 lookfrom(13,2,3);
322324
vec3 lookat(0,0,0);
323325
vec3 vup(0,1,0);
324326
auto dist_to_focus = 10.0;
325327
auto aperture = 0.0;
326328

327-
auto aspect_ratio = double(image_width) / image_height;
328329
camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
329330
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
330331
[Listing [scene-spheres-moving-camera]: <kbd>[main.cc]</kbd> Viewing parameters]
@@ -1009,13 +1010,14 @@
10091010
With camera:
10101011

10111012
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1013+
const auto aspect_ratio = double(image_width) / image_height;
1014+
...
10121015
vec3 lookfrom(13,2,3);
10131016
vec3 lookat(0,0,0);
10141017
vec3 vup(0,1,0);
10151018
auto dist_to_focus = 10.0;
10161019
auto aperture = 0.0;
10171020

1018-
auto aspect_ratio = double(image_width) / image_height;
10191021
camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
10201022
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10211023
[Listing [scene-two-checker-view]: <kbd>[main.cc]</kbd> Viewing parameters]
@@ -1165,13 +1167,14 @@
11651167
With the same camera as before:
11661168

11671169
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1170+
const auto aspect_ratio = double(image_width) / image_height;
1171+
...
11681172
vec3 lookfrom(13,2,3);
11691173
vec3 lookat(0,0,0);
11701174
vec3 vup(0,1,0);
11711175
auto dist_to_focus = 10.0;
11721176
auto aperture = 0.0;
11731177

1174-
auto aspect_ratio = double(image_width) / image_height;
11751178
camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
11761179
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11771180
[Listing [scene-perlin-view]: <kbd>[main.cc]</kbd> Viewing parameters]
@@ -1989,16 +1992,16 @@
19891992
And the view info:
19901993

19911994
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1995+
const auto aspect_ratio = double(image_width) / image_height;
1996+
...
19921997
vec3 lookfrom(278, 278, -800);
19931998
vec3 lookat(278,278,0);
19941999
vec3 vup(0,1,0);
19952000
auto dist_to_focus = 10.0;
19962001
auto aperture = 0.0;
19972002
auto vfov = 40.0;
19982003

1999-
auto aspect_ratio = double(image_width) / image_height;
2000-
camera cam(
2001-
lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
2004+
camera cam(lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
20022005
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20032006
[Listing [cornell-box-view]: <kbd>[main.cc]</kbd> Viewing parameters]
20042007
</div>

src/InOneWeekend/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ int main() {
8686
const int image_height = 800;
8787
const int samples_per_pixel = 10;
8888
const int max_depth = 50;
89+
const auto aspect_ratio = double(image_width) / image_height;
8990

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

@@ -97,7 +98,6 @@ int main() {
9798
auto dist_to_focus = 10.0;
9899
auto aperture = 0.1;
99100

100-
auto aspect_ratio = double(image_width) / image_height;
101101
camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus);
102102

103103
for (int j = image_height-1; j >= 0; --j) {

src/TheNextWeek/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ int main() {
350350
const int image_height = 600;
351351
const int samples_per_pixel = 100;
352352
const int max_depth = 50;
353+
const auto aspect_ratio = double(image_width) / image_height;
353354

354355
hittable_list world;
355356

@@ -363,7 +364,6 @@ int main() {
363364
auto aperture = 0.0;
364365
auto vfov = 40.0;
365366

366-
auto aspect_ratio = double(image_width) / image_height;
367367
camera cam(lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
368368

369369
switch (0) {

src/TheRestOfYourLife/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ int main() {
9595
const int image_height = 600;
9696
const int samples_per_pixel = 100;
9797
const int max_depth = 50;
98+
const auto aspect_ratio = double(image_width) / image_height;
9899

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

101102
camera cam;
102-
auto aspect_ratio = double(image_width) / image_height;
103103
auto world = cornell_box(cam, aspect_ratio);
104104

105105
auto lights = make_shared<hittable_list>();

0 commit comments

Comments
 (0)