mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-24 21:09:57 +01:00
Fix redundancy
This commit is contained in:
parent
469368530b
commit
20ec0693a7
1 changed files with 23 additions and 10 deletions
31
s3l.h
31
s3l.h
|
@ -3,12 +3,22 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef int16_t S3L_UNIT;
|
||||||
|
#define S3L_FRACTIONS_PER_UNIT 1024
|
||||||
typedef int16_t S3L_COORD;
|
typedef int16_t S3L_COORD;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int16_t x;
|
S3L_COORD x; ///< Screen X coordinate.
|
||||||
int16_t y;
|
S3L_COORD y; ///< Screen Y coordinate.
|
||||||
|
|
||||||
|
S3L_UNIT barycentricA; /**< Barycentric coord A. Together with B and C coords
|
||||||
|
these serve to locate the pixel on a triangle and
|
||||||
|
interpolate values between it's three points. The
|
||||||
|
sum of the three coordinates will always be
|
||||||
|
exactly S3L_FRACTIONS_PER_UNIT. */
|
||||||
|
S3L_UNIT barycentricB; ///< Baryc. coord B, same semantics as barycentricA.
|
||||||
|
S3L_UNIT barycentricC; ///< Baryc. coord C, same semantics as barycentricA.
|
||||||
} S3L_PixelInfo;
|
} S3L_PixelInfo;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -188,22 +198,20 @@ 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
|
lErrAdd, rErrAdd, // error value to add in each Bresenham cycle
|
||||||
lErrSub, rErrSub; // error value to substract when moving in x direction
|
lErrSub, rErrSub; // error value to substract when moving in x direction
|
||||||
|
|
||||||
int16_t helperDxAbs, helperDyAbs;
|
int16_t helperDxAbs;
|
||||||
|
|
||||||
#define initSide(v,p1,p2)\
|
#define initSide(v,p1,p2)\
|
||||||
v##X = p1##PointX;\
|
v##X = p1##PointX;\
|
||||||
v##Dx = p2##PointX - p1##PointX;\
|
v##Dx = p2##PointX - p1##PointX;\
|
||||||
v##Dy = p2##PointY - p1##PointY;\
|
v##Dy = p2##PointY - p1##PointY;\
|
||||||
helperDxAbs = S3L_abs(v##Dx);\
|
helperDxAbs = S3L_abs(v##Dx);\
|
||||||
helperDyAbs = S3L_abs(v##Dy);\
|
|
||||||
v##Inc = v##Dx >= 0 ? 1 : -1;\
|
v##Inc = v##Dx >= 0 ? 1 : -1;\
|
||||||
v##Err = 2 * helperDxAbs - helperDyAbs;\
|
v##Err = 2 * helperDxAbs - v##Dy;\
|
||||||
v##ErrAdd = 2 * helperDxAbs;\
|
v##ErrAdd = 2 * helperDxAbs;\
|
||||||
v##ErrSub = 2 * (helperDyAbs != 0 ? helperDyAbs : 1);\
|
v##ErrSub = 2 * v##Dy;\
|
||||||
v##ErrSub = v##ErrSub != 0 ? v##ErrSub : 1; /* don't allow 0, could lead
|
v##ErrSub = v##ErrSub != 0 ? v##ErrSub : 1; /* don't allow 0, could lead
|
||||||
to an infinite substracting
|
to an infinite substracting
|
||||||
loop */
|
loop */
|
||||||
|
|
||||||
#define stepSide(s)\
|
#define stepSide(s)\
|
||||||
while (s##Err > 0)\
|
while (s##Err > 0)\
|
||||||
{\
|
{\
|
||||||
|
@ -217,6 +225,13 @@ void S3L_drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2
|
||||||
|
|
||||||
S3L_PixelInfo p;
|
S3L_PixelInfo p;
|
||||||
|
|
||||||
|
p.barycentricA = 0;
|
||||||
|
p.barycentricB = 0;
|
||||||
|
p.barycentricC = 0;
|
||||||
|
|
||||||
|
//lBarStep = S3L_FRACTIONS_PER_UNIT
|
||||||
|
//rBarStep = S3L_FRACTIONS_PER_UNIT
|
||||||
|
|
||||||
while (currentY <= endY)
|
while (currentY <= endY)
|
||||||
{
|
{
|
||||||
if (currentY == splitY)
|
if (currentY == splitY)
|
||||||
|
@ -249,8 +264,6 @@ void S3L_drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2
|
||||||
|
|
||||||
#undef initSide
|
#undef initSide
|
||||||
#undef stepSide
|
#undef stepSide
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue