I am thinking of a rasterization triangle algorithm. ( triangle_rasterization_lesson )
I am using 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 correctly. But if I change the coordinates of X (xa, ya) and Z (xc, yc), so as not to fill my square.
With triangle(70, 50, 200, 100, 20, 150, image, red); he draws a triangle, but the filling goes beyond.
Where is the problem?