From a2283732f03deb689790aacee3fd9616989771fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Wed, 12 Jun 2019 23:35:57 +0200 Subject: [PATCH] Use triangle winding function in draw --- small3dlib.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/small3dlib.h b/small3dlib.h index a43f5ca..88d7b6b 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -1652,11 +1652,7 @@ void S3L_drawTriangle( tPointSy = y##t;\ tPointPP = &point##t;\ barycentric2 = &(p.barycentric[t]);\ - int32_t aDx = x##a - x##t;\ - int32_t bDx = x##b - x##t;\ - int32_t aDy = S3L_nonZero(y##a - y##t);\ - int32_t bDy = S3L_nonZero(y##b - y##t);\ - if ((aDx << 8) / aDy < (bDx << 8) / bDy)\ + if (S3L_triangleWinding(x##t,y##t,x##a,y##a,x##b,y##b) >= 0)\ {\ lPointSx = x##a; lPointSy = y##a;\ rPointSx = x##b; rPointSy = y##b;\ @@ -1948,6 +1944,8 @@ void S3L_drawTriangle( if (rXClipped < lXClipped && lXClipped < S3L_RESOLUTION_X && rXClipped >= 0) { + // TODO: After the change to computing the L/R, is this needed anymore? + /* This can sometimes happen because of numerical errors in sorting left vs right triangle point, which are compared based on SLOPE, not x coordinates. Here we swap the values to prevents not drawing the