ssloy/tinyrenderer

I think there might be a 0.5 missing here

LuckyBoy-7 opened this issue · 2 comments

void line(int x0, int y0, int x1, int y1, TGAImage &image, TGAColor color) { 
    bool steep = false; 
    if (std::abs(x0-x1)<std::abs(y0-y1)) { 
        std::swap(x0, y0); 
        std::swap(x1, y1); 
        steep = true; 
    } 
    if (x0>x1) { 
        std::swap(x0, x1); 
        std::swap(y0, y1); 
    } 
    for (int x=x0; x<=x1; x++) { 
        float t = (x-x0)/(float)(x1-x0); 
        // int y = y0*(1.-t) + y1*t; 
        int y = y0*(1.-t) + y1*t + 0.5; // <-----
        if (steep) { 
            image.set(y, x, color); 
        } else { 
            image.set(x, y, color); 
        } 
    } 
}

i'd say rather std::round, no need to add .5 in 2025 :)
It will be there in the facelift for the text that is coming shortly

Thanks for your reply! And appreciate your effort on maintaining this tutorial😃.