added drawing cuttoffs to triangle functions

This commit is contained in:
InventorXtreme 2024-03-12 13:24:38 -04:00
parent 129c84d43e
commit adf5e6a761

10
c3d.c
View file

@ -168,7 +168,10 @@ void FillTopFlatZbuffer(Zee *zee, Tri2D *t, Tri2D *tp) {
double curx1 = t->c.x; double curx1 = t->c.x;
double curx2 = 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) { if (0 <= scanline && scanline < RENDERHEIGHT) {
DrawScanline(zee, tp, curx1, curx2, scanline); DrawScanline(zee, tp, curx1, curx2, scanline);
@ -206,7 +209,10 @@ void FillBottomFlatZbuffer(Zee *zee, Tri2D *t, Tri2D *tp) {
double curx1 = t->a.x; double curx1 = t->a.x;
double curx2 = 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 scanline++) { // TODO: Possibly more optimization possible here, use linear correspondance
// for y, not just x to get depth // for y, not just x to get depth
if (0 <= scanline && scanline < RENDERHEIGHT) { if (0 <= scanline && scanline < RENDERHEIGHT) {