mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-21 20:39:57 +01:00
Add clipping to other modes
This commit is contained in:
parent
229c3f465a
commit
6c808f368a
1 changed files with 27 additions and 14 deletions
13
s3l.h
13
s3l.h
|
@ -1219,12 +1219,16 @@ void S3L_drawTriangle(S3L_Vec4 point0, S3L_Vec4 point1, S3L_Vec4 point2,
|
||||||
p.barycentric2 = 0;\
|
p.barycentric2 = 0;\
|
||||||
lineLen = S3L_nonZero(line.steps);\
|
lineLen = S3L_nonZero(line.steps);\
|
||||||
do\
|
do\
|
||||||
|
{\
|
||||||
|
if (line.x >= 0 && line.x < S3L_RESOLUTION_X &&\
|
||||||
|
line.y >= 0 && line.y < S3L_RESOLUTION_Y)\
|
||||||
{\
|
{\
|
||||||
p.x = line.x; p.y = line.y;\
|
p.x = line.x; p.y = line.y;\
|
||||||
p.barycentric##p1 = S3L_interpolateFrom0(\
|
p.barycentric##p1 = S3L_interpolateFrom0(\
|
||||||
S3L_FRACTIONS_PER_UNIT,line.steps,lineLen); \
|
S3L_FRACTIONS_PER_UNIT,line.steps,lineLen); \
|
||||||
p.barycentric##p2 = S3L_FRACTIONS_PER_UNIT - p.barycentric##p1;\
|
p.barycentric##p2 = S3L_FRACTIONS_PER_UNIT - p.barycentric##p1;\
|
||||||
S3L_PIXEL_FUNCTION(&p);\
|
S3L_PIXEL_FUNCTION(&p);\
|
||||||
|
}\
|
||||||
} while (S3L_bresenhamStep(&line));
|
} while (S3L_bresenhamStep(&line));
|
||||||
|
|
||||||
drawLine(0,1)
|
drawLine(0,1)
|
||||||
|
@ -1234,19 +1238,28 @@ void S3L_drawTriangle(S3L_Vec4 point0, S3L_Vec4 point1, S3L_Vec4 point2,
|
||||||
#undef drawLine
|
#undef drawLine
|
||||||
}
|
}
|
||||||
else // point mode
|
else // point mode
|
||||||
|
{
|
||||||
|
if (x0 >= 0 && x0 < S3L_RESOLUTION_X && y0 >= 0 && y0 < S3L_RESOLUTION_Y)
|
||||||
{
|
{
|
||||||
p.x = x0; p.y = y0; p.barycentric0 = S3L_FRACTIONS_PER_UNIT;
|
p.x = x0; p.y = y0; p.barycentric0 = S3L_FRACTIONS_PER_UNIT;
|
||||||
p.barycentric1 = 0; p.barycentric2 = 0;
|
p.barycentric1 = 0; p.barycentric2 = 0;
|
||||||
S3L_PIXEL_FUNCTION(&p);
|
S3L_PIXEL_FUNCTION(&p);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x1 >= 0 && x1 < S3L_RESOLUTION_X && y1 >= 0 && y1 < S3L_RESOLUTION_Y)
|
||||||
|
{
|
||||||
p.x = x1; p.y = y1; p.barycentric0 = 0;
|
p.x = x1; p.y = y1; p.barycentric0 = 0;
|
||||||
p.barycentric1 = S3L_FRACTIONS_PER_UNIT; p.barycentric2 = 0;
|
p.barycentric1 = S3L_FRACTIONS_PER_UNIT; p.barycentric2 = 0;
|
||||||
S3L_PIXEL_FUNCTION(&p);
|
S3L_PIXEL_FUNCTION(&p);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x2 >= 0 && x2 < S3L_RESOLUTION_X && y2 >= 0 && y2 < S3L_RESOLUTION_Y)
|
||||||
|
{
|
||||||
p.x = x2; p.y = y2; p.barycentric0 = 0;
|
p.x = x2; p.y = y2; p.barycentric0 = 0;
|
||||||
p.barycentric1 = 0; p.barycentric2 = S3L_FRACTIONS_PER_UNIT;
|
p.barycentric1 = 0; p.barycentric2 = S3L_FRACTIONS_PER_UNIT;
|
||||||
S3L_PIXEL_FUNCTION(&p);
|
S3L_PIXEL_FUNCTION(&p);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void S3L_rotate2DPoint(S3L_Unit *x, S3L_Unit *y, S3L_Unit angle)
|
static inline void S3L_rotate2DPoint(S3L_Unit *x, S3L_Unit *y, S3L_Unit angle)
|
||||||
|
|
Loading…
Reference in a new issue