Handle buddy tris

This commit is contained in:
Miloslav Ciz 2025-05-12 20:24:27 +02:00
parent f07a4d3635
commit 0e34b2c52c
3 changed files with 25 additions and 1 deletions

View file

@ -2,6 +2,9 @@
#define SMALL3DLIB_H
/*
NOTE: This is a Licar specific fork of the library. Changes made can be
found e.g. with diff.
Simple realtime 3D software rasterization renderer. It is fast, focused on
resource-limited computers, located in a single C header file, with no
dependencies, using only 32bit integer arithmetics.
@ -2016,6 +2019,25 @@ void S3L_drawTriangle(
p.triangleSize[1] =
(rPointSS->y > lPointSS->y ? rPointSS->y : lPointSS->y) - tPointSS->y;
// Licar modifications below: handle buggy triangles (still imperfect)
if (S3L_abs(p.triangleSize[0]) > (5 * S3L_RESOLUTION_X / 2) ||
S3L_abs(p.triangleSize[1]) > (5 * S3L_RESOLUTION_Y / 2))
return;
lPointSS->x = S3L_clamp(lPointSS->x,
-1 * S3L_RESOLUTION_X,2 * S3L_RESOLUTION_X);
rPointSS->x = S3L_clamp(rPointSS->x,
-1 * S3L_RESOLUTION_X,2 * S3L_RESOLUTION_X);
tPointSS->x = S3L_clamp(tPointSS->x,
-1 * S3L_RESOLUTION_X,2 * S3L_RESOLUTION_X);
lPointSS->y = S3L_clamp(lPointSS->y,
-1 * S3L_RESOLUTION_Y,2 * S3L_RESOLUTION_Y);
rPointSS->y = S3L_clamp(rPointSS->y,
-1 * S3L_RESOLUTION_Y,2 * S3L_RESOLUTION_Y);
tPointSS->y = S3L_clamp(tPointSS->y,
-1 * S3L_RESOLUTION_Y,2 * S3L_RESOLUTION_Y);
// now draw the triangle line by line:
S3L_ScreenCoord splitY; // Y of the vertically middle point of the triangle