|
@@ -17,9 +17,30 @@ void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, in
|
|
|
drawLine(x2, y2, x0, y0, colour);
|
|
|
}
|
|
|
|
|
|
+/* This function expect Point 0 to be the top, 1 to be the bottom left, 2 to be the bottom right */
|
|
|
static void drawFillBottomFlatTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour)
|
|
|
{
|
|
|
+ int i;
|
|
|
+ int32_t deltaXL = x1 - x0;
|
|
|
+ int32_t deltaXR = x2 - x0;
|
|
|
+ int32_t deltaY = y1 - y0;
|
|
|
+ int32_t sideLength = abs(deltaY);
|
|
|
|
|
|
+ double incrementXL = deltaXL / (double)sideLength;
|
|
|
+ double incrementXR = deltaXR / (double)sideLength;
|
|
|
+ double incrementY = deltaY / (double)sideLength;
|
|
|
+
|
|
|
+ double currentXL = x0;
|
|
|
+ double currentXR = x0;
|
|
|
+ double currentY = y0;
|
|
|
+
|
|
|
+ for(i = 0; i < sideLength; i++)
|
|
|
+ {
|
|
|
+ drawHLine(round(currentXL), round(currentY), round(currentXR), colour);
|
|
|
+ currentXL += incrementXL;
|
|
|
+ currentXR += incrementXR;
|
|
|
+ currentY += incrementY;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
static void drawFillTopFlatTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour)
|
|
@@ -46,7 +67,7 @@ void drawFilledTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t
|
|
|
/* Determine the mid intersection and point */
|
|
|
My = y1;
|
|
|
Mx = x0 + (double)((x2 - x0) * (y1 - y0)) / (double)(y2 - y0);
|
|
|
-
|
|
|
+
|
|
|
/* Fill top */
|
|
|
drawFillBottomFlatTriangle(x0, y0, x1, y1, Mx, My,colour);
|
|
|
|