mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-21 20:39:57 +01:00
Move triangle code to the top
This commit is contained in:
parent
cf7b6494f8
commit
55ebaef41c
1 changed files with 235 additions and 244 deletions
93
s3l.h
93
s3l.h
|
@ -634,58 +634,8 @@ void S3L_drawTriangle(
|
|||
S3L_initPixelInfo(&p);
|
||||
p.triangleID = triangleID;
|
||||
|
||||
// point mode
|
||||
|
||||
if (config.mode == S3L_MODE_POINTS)
|
||||
if (config.mode == S3L_MODE_TRIANGLES) // triangle mode
|
||||
{
|
||||
p.x = x0; p.y = y0; p.barycentric0 = S3L_FRACTIONS_PER_UNIT;
|
||||
p.barycentric1 = 0; p.barycentric2 = 0;
|
||||
S3L_PIXEL_FUNCTION(&p);
|
||||
|
||||
p.x = x1; p.y = y1; p.barycentric0 = 0;
|
||||
p.barycentric1 = S3L_FRACTIONS_PER_UNIT; p.barycentric2 = 0;
|
||||
S3L_PIXEL_FUNCTION(&p);
|
||||
|
||||
p.x = x2; p.y = y2; p.barycentric0 = 0;
|
||||
p.barycentric1 = 0; p.barycentric2 = S3L_FRACTIONS_PER_UNIT;
|
||||
S3L_PIXEL_FUNCTION(&p);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// line mode
|
||||
|
||||
if (config.mode == S3L_MODE_LINES)
|
||||
{
|
||||
S3L_BresenhamState line;
|
||||
S3L_Unit lineLen;
|
||||
|
||||
#define drawLine(p1,p2)\
|
||||
S3L_bresenhamInit(&line,x##p1,y##p1,x##p2,y##p2);\
|
||||
p.barycentric0 = 0;\
|
||||
p.barycentric1 = 0;\
|
||||
p.barycentric2 = 0;\
|
||||
lineLen = S3L_nonZero(line.steps);\
|
||||
do\
|
||||
{\
|
||||
p.x = line.x; p.y = line.y;\
|
||||
p.barycentric##p1 = S3L_interpolateFrom0(\
|
||||
S3L_FRACTIONS_PER_UNIT,line.steps,lineLen); \
|
||||
p.barycentric##p2 = S3L_FRACTIONS_PER_UNIT - p.barycentric##p1;\
|
||||
S3L_PIXEL_FUNCTION(&p);\
|
||||
} while (S3L_bresenhamStep(&line));
|
||||
|
||||
drawLine(0,1)
|
||||
drawLine(2,0)
|
||||
drawLine(1,2)
|
||||
|
||||
#undef drawLine
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// triangle mode -- TODO: maybe move to the top as this is most common?
|
||||
|
||||
S3L_ScreenCoord
|
||||
tPointX, tPointY, // top triangle point coords
|
||||
lPointX, lPointY, // left triangle point coords
|
||||
|
@ -909,6 +859,47 @@ void S3L_drawTriangle(
|
|||
|
||||
#undef initSide
|
||||
#undef stepSide
|
||||
}
|
||||
else if (config.mode == S3L_MODE_LINES) // line mode
|
||||
{
|
||||
S3L_BresenhamState line;
|
||||
S3L_Unit lineLen;
|
||||
|
||||
#define drawLine(p1,p2)\
|
||||
S3L_bresenhamInit(&line,x##p1,y##p1,x##p2,y##p2);\
|
||||
p.barycentric0 = 0;\
|
||||
p.barycentric1 = 0;\
|
||||
p.barycentric2 = 0;\
|
||||
lineLen = S3L_nonZero(line.steps);\
|
||||
do\
|
||||
{\
|
||||
p.x = line.x; p.y = line.y;\
|
||||
p.barycentric##p1 = S3L_interpolateFrom0(\
|
||||
S3L_FRACTIONS_PER_UNIT,line.steps,lineLen); \
|
||||
p.barycentric##p2 = S3L_FRACTIONS_PER_UNIT - p.barycentric##p1;\
|
||||
S3L_PIXEL_FUNCTION(&p);\
|
||||
} while (S3L_bresenhamStep(&line));
|
||||
|
||||
drawLine(0,1)
|
||||
drawLine(2,0)
|
||||
drawLine(1,2)
|
||||
|
||||
#undef drawLine
|
||||
}
|
||||
else // point mode
|
||||
{
|
||||
p.x = x0; p.y = y0; p.barycentric0 = S3L_FRACTIONS_PER_UNIT;
|
||||
p.barycentric1 = 0; p.barycentric2 = 0;
|
||||
S3L_PIXEL_FUNCTION(&p);
|
||||
|
||||
p.x = x1; p.y = y1; p.barycentric0 = 0;
|
||||
p.barycentric1 = S3L_FRACTIONS_PER_UNIT; p.barycentric2 = 0;
|
||||
S3L_PIXEL_FUNCTION(&p);
|
||||
|
||||
p.x = x2; p.y = y2; p.barycentric0 = 0;
|
||||
p.barycentric1 = 0; p.barycentric2 = S3L_FRACTIONS_PER_UNIT;
|
||||
S3L_PIXEL_FUNCTION(&p);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void S3L_rotate2DPoint(S3L_Unit *x, S3L_Unit *y, S3L_Unit angle)
|
||||
|
|
Loading…
Reference in a new issue