1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-21 20:39:57 +01:00

Fix a bug

This commit is contained in:
Miloslav Číž 2018-11-17 17:18:55 +01:00
parent 9cbe9a0823
commit d20eaa1427
2 changed files with 26 additions and 20 deletions

10
s3l.h
View file

@ -188,14 +188,18 @@ void S3L_drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2
lErrAdd, rErrAdd, // error value to add in each Bresenham cycle
lErrSub, rErrSub; // error value to substract when moving in x direction
int16_t helperDxAbs, helperDyAbs;
#define initSide(v,p1,p2)\
v##X = p1##PointX;\
v##Dx = p2##PointX - p1##PointX;\
v##Dy = p2##PointY - p1##PointY;\
helperDxAbs = S3L_abs(v##Dx);\
helperDyAbs = S3L_abs(v##Dy);\
v##Inc = v##Dx >= 0 ? 1 : -1;\
v##Err = 2 * v##Dx - v##Dy; \
v##ErrAdd = 2 * S3L_abs(v##Dx);\
v##ErrSub = 2 * S3L_abs(v##Dy);
v##Err = 2 * helperDxAbs - helperDyAbs;\
v##ErrAdd = 2 * helperDxAbs;\
v##ErrSub = 2 * helperDyAbs;
#define stepSide(s)\
while (s##Err > 0)\

View file

@ -40,31 +40,33 @@ void drawPixel(S3L_PixelInfo *p)
const int16_t test_coords[] =
{
100,100, 99,101, 101,101, // 0, small triangle
90,50, 100,10, 300,80, // 1, arbitrary
100,30, 20,50, 40,80 // 2, arbitrary
190,50, 200,10, 400,80, // 1, arbitrary
40,80, 20,50, 100,30, // 2, arbitrary
300,300, 290,400, 310,400, // 3, regular
105,300, 120,300, 201,300, // 4, horizontal line
400,300, 400,320, 400,400 // 5, vertical line
};
void draw()
{
clearScreen();
int c = 0;
for (int c = 0; c < 4; ++c)
{
int
x0 = test_coords[6 * c],
y0 = test_coords[6 * c + 1],
x1 = test_coords[6 * c + 2],
y1 = test_coords[6 * c + 3],
x2 = test_coords[6 * c + 4],
y2 = test_coords[6 * c + 5];
int
x0 = test_coords[6 * c],
y0 = test_coords[6 * c + 1],
x1 = test_coords[6 * c + 2],
y1 = test_coords[6 * c + 3],
x2 = test_coords[6 * c + 4],
y2 = test_coords[6 * c + 5];
S3L_drawTriangle(x0,y0,x1,y1,x2,y2);
S3L_drawTriangle(x0,y0,x1,y1,x2,y2);
/*
setPixel(x0,y0,255,0,0);
setPixel(x1,y1,255,0,0);
setPixel(x2,y2,255,0,0);
*/
setPixel(x0,y0,255,0,0);
setPixel(x1,y1,255,0,0);
setPixel(x2,y2,255,0,0);
}
}
int main()