1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-12-23 01:26:19 +01:00

Rasterization looks correct

This commit is contained in:
Miloslav Číž 2019-05-05 22:32:52 +02:00
parent 062bbcd4ce
commit e081b9be74
2 changed files with 10 additions and 5 deletions

13
s3l.h
View file

@ -734,8 +734,9 @@ void S3L_drawTriangle(
specifics of this algorithm are among others:
- drawing possibly a NON-CONTINUOUS line
- NOT tracing the line exactly, but rather rasterizing on one (right)
side of it, according to the pixel CENTERS
- NOT tracing the line exactly, but rather rasterizing one the right
side of it, according to the pixel CENTERS, INCLUDING the pixel
centers
The principle is this:
@ -756,6 +757,7 @@ void S3L_drawTriangle(
lDy, rDy, // dy (end point - start point)
lInc, rInc, // direction in which to increment (1 or -1)
lErr, rErr, // current error (Bresenham)
lErrCmp, rErrCmp, // helper for deciding comparison (> vs >=)
lErrAdd, rErrAdd, // error value to add in each Bresenham cycle
lErrSub, rErrSub; // error value to substract when moving in x direction
@ -782,13 +784,16 @@ void S3L_drawTriangle(
s##SideUnitStep *= -1;\
}\
s##Inc = s##Dx >= 0 ? 1 : -1;\
s##Err = (s##Dx < 0) ? 0 : s##Dy;\
if (s##Dx < 0)\
{s##Err = 0; s##ErrCmp = 0;}\
else\
{s##Err = s##Dy; s##ErrCmp = 1;}\
s##ErrAdd = S3L_abs(s##Dx);\
s##ErrSub = s##Dy != 0 ? s##Dy : 1; /* don't allow 0, could lead to an
infinite substracting loop */
#define stepSide(s)\
while (s##Err > s##Dy)\
while (s##Err - s##Dy >= s##ErrCmp)\
{\
s##X += s##Inc;\
s##Err -= s##ErrSub;\

2
test.c
View file

@ -289,7 +289,7 @@ uint16_t testRasterization()
dt(12,12,12);
dt(9,10,10);
dt(1,10,10);
// dt(9,6,1);
dt(9,6,1);
dt(0,6,10);
#undef dt