From d20eaa1427e3b6b0584c49ce0e86185bb594d06b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 17 Nov 2018 17:18:55 +0100 Subject: [PATCH] Fix a bug --- s3l.h | 10 +++++++--- testSDL.c | 36 +++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/s3l.h b/s3l.h index 6ee95b5..d983ec2 100644 --- a/s3l.h +++ b/s3l.h @@ -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)\ diff --git a/testSDL.c b/testSDL.c index eaddf2a..a6fce61 100644 --- a/testSDL.c +++ b/testSDL.c @@ -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()