From adf5e6a761fe3e63b7e28eeb5e5dbff7faddf200 Mon Sep 17 00:00:00 2001 From: InventorXtreme Date: Tue, 12 Mar 2024 13:24:38 -0400 Subject: [PATCH] added drawing cuttoffs to triangle functions --- c3d.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/c3d.c b/c3d.c index ab98fba..f13f10f 100644 --- a/c3d.c +++ b/c3d.c @@ -168,7 +168,10 @@ void FillTopFlatZbuffer(Zee *zee, Tri2D *t, Tri2D *tp) { double curx1 = t->c.x; double curx2 = t->c.x; - for (int scanline = t->c.y; scanline >= t->a.y; scanline--) { + int scanbottom = t->c.y; + int scantop = Max(t->a.y, 0); + + for (int scanline = scanbottom; scanline >= scantop; scanline--) { if (0 <= scanline && scanline < RENDERHEIGHT) { DrawScanline(zee, tp, curx1, curx2, scanline); @@ -206,7 +209,10 @@ void FillBottomFlatZbuffer(Zee *zee, Tri2D *t, Tri2D *tp) { double curx1 = t->a.x; double curx2 = t->a.x; - for (int scanline = t->a.y; scanline < t->c.y; + int scantop = t->a.y; // start must always be the true beging of the triangle, otherwise everything will be offset + int scanbottom = Min(t->c.y, RENDERHEIGHT); // we can stop rendering as soon as it goes off screen + + for (int scanline = scantop; scanline < scanbottom; scanline++) { // TODO: Possibly more optimization possible here, use linear correspondance // for y, not just x to get depth if (0 <= scanline && scanline < RENDERHEIGHT) {