i'm thinking about rasterization triangle algorithm. ( triangle_rasterization_lesson )
I wtote the following code:
void triangle(int xa, int ya, int xb, int yb, int xc, int yc, TGAImage &image, TGAColor color)
{
line(xa, ya, xb, yb, image, color);
line(xa, ya, xc, yc, image, color);
line(xb, yb, xc, yc, image, color);
for (int x = xa; x<=xb; x++)
{
for (int y = ya; y<=yb; y++)
{
line(xc, yc, x, y, image, white);
}
}
}
With triangle(100, 100, 100, 400, 400, 100, image, red);
it works properly.
But if i swap X(xa, ya) and Z(xc, yc) coordinates to doesn't fill my square.
With triangle(70, 50, 200, 100, 20, 150, image, red);
it draws triangle, but filling comes out of bounds.
Where is the problem?
Question&Answers:
os