Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Book 1] [4.2] Traversal of rays starts at the upper left corner #766

@patrick-han

Description

@patrick-han

In section 4.2 of RayTracingInOneWeekend it is stated:

"I will traverse the screen from the lower left hand corner, and use two offset vectors along the screen sides to move the ray endpoint across the screen."

which refers to this piece of code in Listing 9:

 for (int j = image_height-1; j >= 0; --j) {
        std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
        for (int i = 0; i < image_width; ++i) {
            auto u = double(i) / (image_width-1);
            auto v = double(j) / (image_height-1);
            ray r(origin, lower_left_corner + u*horizontal + v*vertical - origin);
            color pixel_color = ray_color(r);
            write_color(std::cout, pixel_color);
        }
    }

While the offset vectors are relative to the lower_left_corner, it seems to me that the rays actually start in the upper left hand corner and traverse to the lower right. For each j, starting at image_height - 1 and decreasing to 0, we increase i from 0 by image_width times.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions