diff --git a/polygon_draw.hh b/polygon_draw.hh index 5bd02b5..8538447 100644 --- a/polygon_draw.hh +++ b/polygon_draw.hh @@ -24,10 +24,10 @@ void DrawPolygon(auto&& points, auto&& Plot) requires std::ranges::input_range= Yindex); // Number of steps = number of scanlines - auto a = std::get(*from), b = std::get(*to); - if constexpr(i == Xindex || !PerspectiveCorrected) return Slope(a, b, num_steps); - else if constexpr(i == Zindex) return Slope(1/a, 1/b, num_steps); - else return Slope(a / std::get(*from), b / std::get(*to), num_steps); + auto a = std::get(*from), b = std::get(*to); // Y coordinate for begin and end + if constexpr(i == Xindex || !PerspectiveCorrected) return Slope(a, b, num_steps, .5f); // Affine interp: X + else if constexpr(i == Zindex) return Slope(1/a, 1/b, num_steps, .5f); // Z interp + else return Slope(a / std::get(*from), b / std::get(*to), num_steps, .5f); // Perspective interp }); }, // Scanline function @@ -37,7 +37,7 @@ void DrawPolygon(auto&& points, auto&& Plot) requires std::ranges::input_range(std::index_sequence, auto&& GetSlope) @@ -49,7 +49,7 @@ void DrawPolygon(auto&& points, auto&& Plot) requires std::ranges::input_range(left).get(), std::get(right).get(), num_steps, rounding_error ); }); // Using those slopes, render each pixel. After each pixel, update the slopes by their step-sizes. - for(int x = leftx, e = endx; x < e; ++x) + for(int x = intleftx, e = endx+.5f; x < e; ++x) { [&](std::index_sequence, auto&& GetValue) {