Skip to content

Commit 024ad46

Browse files
committed
triangle drawing routine
1 parent 75d1efe commit 024ad46

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ void triangle(Vec2i t0, Vec2i t1, Vec2i t2, TGAImage &image, TGAColor color) {
3939
int total_height = t2.y-t0.y;
4040
for (int i=0; i<total_height; i++) {
4141
bool second_half = i>t1.y-t0.y || t1.y==t0.y;
42-
int seg_height = second_half ? t2.y-t1.y : t1.y-t0.y;
42+
int segment_height = second_half ? t2.y-t1.y : t1.y-t0.y;
4343
float alpha = (float)i/total_height;
44-
float beta = (float)(i-(second_half ? t1.y-t0.y : 0))/seg_height; // be careful: with above conditions no division by zero here
44+
float beta = (float)(i-(second_half ? t1.y-t0.y : 0))/segment_height; // be careful: with above conditions no division by zero here
4545
Vec2i A = t0 + (t2-t0)*alpha;
4646
Vec2i B = second_half ? t1 + (t2-t1)*beta : t0 + (t1-t0)*beta;
4747
if (A.x>B.x) std::swap(A, B);

0 commit comments

Comments
 (0)