|
466 | 466 | }
|
467 | 467 |
|
468 | 468 | int main() {
|
469 |
| - const int image_width = 768; |
470 |
| - const auto aspect_ratio = 9.0 / 16.0; |
471 |
| - const int image_height = static_cast<int>(aspect_ratio * image_width); |
| 469 | + const auto aspect_ratio = 16.0 / 9.0; |
| 470 | + const int image_width = 384; |
| 471 | + const int image_height = static_cast<int>(image_width / aspect_ratio); |
472 | 472 |
|
473 | 473 | std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";
|
474 | 474 |
|
|
1180 | 1180 | }
|
1181 | 1181 |
|
1182 | 1182 | int main() {
|
1183 |
| - const int image_width = 200; |
1184 |
| - const int image_height = 100; |
| 1183 | + const auto aspect_ratio = 16.0 / 9.0; |
| 1184 | + const int image_width = 384; |
| 1185 | + const int image_height = static_cast<int>(image_width / aspect_ratio); |
1185 | 1186 |
|
1186 | 1187 | std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
|
1187 | 1188 |
|
|
1373 | 1374 |
|
1374 | 1375 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1375 | 1376 | int main() {
|
1376 |
| - const int image_width = 200; |
1377 |
| - const int image_height = 100; |
| 1377 | + const auto aspect_ratio = 16.0 / 9.0; |
| 1378 | + const int image_width = 384; |
| 1379 | + const int image_height = static_cast<int>(image_width / aspect_ratio); |
1378 | 1380 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1379 | 1381 | const int samples_per_pixel = 100;
|
1380 | 1382 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
|
1553 | 1555 | ...
|
1554 | 1556 |
|
1555 | 1557 | int main() {
|
1556 |
| - const int image_width = 200; |
1557 |
| - const int image_height = 100; |
| 1558 | + const auto aspect_ratio = 16.0 / 9.0; |
| 1559 | + const int image_width = 384; |
| 1560 | + const int image_height = static_cast<int>(image_width / aspect_ratio); |
1558 | 1561 | const int samples_per_pixel = 100;
|
1559 | 1562 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1560 | 1563 | const int max_depth = 50;
|
|
2076 | 2079 |
|
2077 | 2080 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2078 | 2081 | int main() {
|
2079 |
| - const int image_width = 200; |
2080 |
| - const int image_height = 100; |
| 2082 | + const auto aspect_ratio = 16.0 / 9.0; |
| 2083 | + const int image_width = 384; |
| 2084 | + const int image_height = static_cast<int>(image_width / aspect_ratio); |
2081 | 2085 | const int samples_per_pixel = 100;
|
2082 | 2086 | const int max_depth = 50;
|
2083 | 2087 |
|
|
2563 | 2567 | public:
|
2564 | 2568 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
2565 | 2569 | camera(
|
2566 |
| - double vfov, // top to bottom, in degrees |
2567 |
| - double aspect |
| 2570 | + double vfov, // vertical field-of-view in degrees |
| 2571 | + double aspect_ratio |
2568 | 2572 | ) {
|
2569 | 2573 | origin = point3(0.0, 0.0, 0.0);
|
2570 | 2574 |
|
2571 | 2575 | auto theta = degrees_to_radians(vfov);
|
2572 | 2576 | auto half_height = tan(theta/2);
|
2573 |
| - auto half_width = aspect * half_height; |
| 2577 | + auto half_width = aspect_ratio * half_height; |
2574 | 2578 |
|
2575 | 2579 | lower_left_corner = point3(-half_width, -half_height, -1.0);
|
2576 | 2580 |
|
|
2646 | 2650 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
2647 | 2651 | point3 lookfrom, point3 lookat, vec3 vup,
|
2648 | 2652 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2649 |
| - double vfov, // top to bottom, in degrees |
2650 |
| - double aspect |
| 2653 | + double vfov, // vertical field-of-view in degrees |
| 2654 | + double aspect_ratio |
2651 | 2655 | ) {
|
2652 | 2656 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
2653 | 2657 | origin = lookfrom;
|
|
2656 | 2660 |
|
2657 | 2661 | auto theta = degrees_to_radians(vfov);
|
2658 | 2662 | auto half_height = tan(theta/2);
|
2659 |
| - auto half_width = aspect * half_height; |
| 2663 | + auto half_width = aspect_ratio * half_height; |
2660 | 2664 |
|
2661 | 2665 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
2662 | 2666 | w = unit_vector(lookfrom - lookat);
|
|
2687 | 2691 | This allows us to change the viewpoint:
|
2688 | 2692 |
|
2689 | 2693 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2690 |
| - const auto aspect_ratio = double(image_width) / image_height; |
2691 |
| - ... |
2692 | 2694 | camera cam(point3(-2,2,1), point3(0,0,-1), vup, 90, aspect_ratio);
|
2693 | 2695 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2694 | 2696 | [Listing [scene-free-view]: <kbd>[main.cc]</kbd> Scene with alternate viewpoint]
|
|
2781 | 2783 | public:
|
2782 | 2784 | camera(
|
2783 | 2785 | point3 lookfrom, point3 lookat, vec3 vup,
|
2784 |
| - double vfov, // top to bottom, in degrees |
| 2786 | + double vfov, // vertical field-of-view in degrees |
2785 | 2787 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
2786 |
| - double aspect, double aperture, double focus_dist |
| 2788 | + double aspect_ratio, double aperture, double focus_dist |
2787 | 2789 | ) {
|
2788 | 2790 | origin = lookfrom;
|
2789 | 2791 | lens_radius = aperture / 2;
|
2790 | 2792 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2791 | 2793 |
|
2792 | 2794 | auto theta = degrees_to_radians(vfov);
|
2793 | 2795 | auto half_height = tan(theta/2);
|
2794 |
| - auto half_width = aspect * half_height; |
| 2796 | + auto half_width = aspect_ratio * half_height; |
2795 | 2797 |
|
2796 | 2798 | w = unit_vector(lookfrom - lookat);
|
2797 | 2799 | u = unit_vector(cross(vup, w));
|
|
2837 | 2839 | Using a big aperture:
|
2838 | 2840 |
|
2839 | 2841 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2840 |
| - const auto aspect_ratio = double(image_width) / image_height; |
2841 |
| - ... |
2842 | 2842 | point3 lookfrom(3,3,2);
|
2843 | 2843 | point3 lookat(0,0,-1);
|
2844 | 2844 | vec3 vup(0,1,0);
|
|
0 commit comments