12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- /*
- * 3D Engine
- * triangle.c:
- * Based on pikuma.com 3D software renderer in C
- * Copyright (c) 2021 986-Studio. All rights reserved.
- *
- * Created by Manoël Trapier on 04/03/2021.
- */
- #include <display.h>
- #include <triangle.h>
- void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour)
- {
- drawLine(x0, y0, x1, y1, colour);
- drawLine(x1, y1, x2, y2, colour);
- drawLine(x2, y2, x0, y0, colour);
- }
- static void drawFillBottomFlatTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour)
- {
- }
- static void drawFillTopFlatTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour)
- {
- }
- void drawFilledTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour)
- {
- int32_t My, Mx;
- if (y0 > y1)
- {
- intSwap(&x0, &x1); intSwap(&y0, &y1);
- }
- if (y1 > y2)
- {
- intSwap(&x1, &x2); intSwap(&y1, &y2);
- }
- if (y0 > y1)
- {
- intSwap(&x0, &x1); intSwap(&y0, &y1);
- }
- /* 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);
- /* Fill bottom */
- drawFillTopFlatTriangle(x1, y1, Mx, My, x2, y2, colour);
- }
|