mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-23 20:59:58 +01:00
Continue triangle
This commit is contained in:
parent
15c28205ac
commit
9cbe9a0823
2 changed files with 30 additions and 8 deletions
4
s3l.h
4
s3l.h
|
@ -193,7 +193,7 @@ void S3L_drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2
|
|||
v##Dx = p2##PointX - p1##PointX;\
|
||||
v##Dy = p2##PointY - p1##PointY;\
|
||||
v##Inc = v##Dx >= 0 ? 1 : -1;\
|
||||
v##Err = 2 * v##Dx - v##Dy;\
|
||||
v##Err = 2 * v##Dx - v##Dy; \
|
||||
v##ErrAdd = 2 * S3L_abs(v##Dx);\
|
||||
v##ErrSub = 2 * S3L_abs(v##Dy);
|
||||
|
||||
|
@ -214,6 +214,8 @@ void S3L_drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2
|
|||
{
|
||||
p.y = currentY;
|
||||
|
||||
// draw the line
|
||||
|
||||
for (S3L_COORD x = lX; x <= rX; ++x)
|
||||
{
|
||||
p.x = x;
|
||||
|
|
34
testSDL.c
34
testSDL.c
|
@ -21,30 +21,50 @@ void clearScreen()
|
|||
static inline void setPixel(int x, int y, uint8_t red, uint8_t green, uint8_t blue)
|
||||
{
|
||||
uint32_t r = red & 0x000000FF;
|
||||
r = r << 16;
|
||||
r = r << 24;
|
||||
|
||||
uint32_t g = green & 0x000000FF;
|
||||
g = g << 8;
|
||||
g = g << 16;
|
||||
|
||||
uint32_t b = blue & 0x000000FF;
|
||||
b = b << 8;
|
||||
|
||||
pixels[y * SCREEN_WIDTH + x] = r | g | b;
|
||||
}
|
||||
|
||||
void drawPixel(S3L_PixelInfo *p)
|
||||
{
|
||||
setPixel(p->x,p->y,255,255,0);
|
||||
setPixel(p->x,p->y,255,255,255);
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
void draw()
|
||||
{
|
||||
clearScreen();
|
||||
|
||||
setPixel(90,50,255,0,0);
|
||||
setPixel(100,10,255,0,0);
|
||||
setPixel(300,80,255,0,0);
|
||||
int c = 0;
|
||||
|
||||
S3L_drawTriangle(90,50,100,10,300,80);
|
||||
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);
|
||||
|
||||
/*
|
||||
setPixel(x0,y0,255,0,0);
|
||||
setPixel(x1,y1,255,0,0);
|
||||
setPixel(x2,y2,255,0,0);
|
||||
*/
|
||||
}
|
||||
|
||||
int main()
|
||||
|
|
Loading…
Reference in a new issue