.
This commit is contained in:
111
Draw.c
111
Draw.c
@@ -25,36 +25,85 @@
|
||||
#define ST_ONE (1 << SST_ST_FRACBITS)
|
||||
#define W_ONE (1 << SST_W_FRACBITS)
|
||||
|
||||
void
|
||||
drawSquare( const SstRegs *sst,
|
||||
const int x,
|
||||
const int y,
|
||||
const int tSize)
|
||||
typedef struct _def_sPoint
|
||||
{
|
||||
ISET(sst->vA.x,x);
|
||||
ISET(sst->vA.y,y);
|
||||
ISET(sst->vB.x,x+XY_ONE*tSize);
|
||||
ISET(sst->vB.y,y);
|
||||
ISET(sst->vC.x,x);
|
||||
ISET(sst->vC.y,y+XY_ONE*tSize);
|
||||
ISET(sst->s,0);
|
||||
ISET(sst->t,0);
|
||||
ISET(sst->w,W_ONE);
|
||||
ISET(sst->dsdx,ST_ONE);
|
||||
ISET(sst->dtdx,0);
|
||||
ISET(sst->dwdx,0);
|
||||
ISET(sst->dsdy,0);
|
||||
ISET(sst->dtdy,ST_ONE);
|
||||
ISET(sst->dwdy,0);
|
||||
ISET(sst->triangleCMD,0);
|
||||
ISET(sst->vA.x,x);
|
||||
ISET(sst->vA.y,y+XY_ONE*tSize);
|
||||
ISET(sst->vB.x,x+XY_ONE*tSize);
|
||||
ISET(sst->vB.y,y);
|
||||
ISET(sst->vC.x, x+XY_ONE*tSize);
|
||||
ISET(sst->vC.y, y+XY_ONE*tSize);
|
||||
ISET(sst->s,0);
|
||||
ISET(sst->t,ST_ONE*tSize);
|
||||
ISET(sst->w,W_ONE);
|
||||
ISET(sst->triangleCMD, 0xFFFFFFFF);
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
}def_sPoint;
|
||||
|
||||
typedef struct _def_sTriangle
|
||||
{
|
||||
def_sPoint vA;
|
||||
def_sPoint vB;
|
||||
def_sPoint vC;
|
||||
int32_t s;
|
||||
int32_t t;
|
||||
int32_t w;
|
||||
int32_t dsdx;
|
||||
int32_t dtdx;
|
||||
int32_t dwdx;
|
||||
int32_t dsdy;
|
||||
int32_t dtdy;
|
||||
int32_t dwdy;
|
||||
}def_sTriangle;
|
||||
|
||||
static inline uint32_t v2_triangle_cmd_from_abc(const def_sPoint A,
|
||||
const def_sPoint B,
|
||||
const def_sPoint C)
|
||||
{
|
||||
const int32_t abx = (int32_t)B.x - (int32_t)A.x;
|
||||
const int32_t aby = (int32_t)B.y - (int32_t)A.y;
|
||||
const int32_t acx = (int32_t)C.x - (int32_t)A.x;
|
||||
const int32_t acy = (int32_t)C.y - (int32_t)A.y;
|
||||
const int64_t s = (int64_t )abx * (int64_t )acy - (int64_t )aby * (int64_t )acx;
|
||||
return (s < 0) ? 0x80000000u : 0u;
|
||||
}
|
||||
static void inline drawTriangle(const SstRegs * const sst, const def_sTriangle * const sTri)
|
||||
{
|
||||
ISET(sst->vA.x, sTri->vA.x*XY_ONE); ISET(sst->vA.y, sTri->vA.y*XY_ONE);
|
||||
ISET(sst->vB.x, sTri->vB.x*XY_ONE); ISET(sst->vB.y, sTri->vB.y*XY_ONE);
|
||||
ISET(sst->vC.x, sTri->vC.x*XY_ONE); ISET(sst->vC.y, sTri->vC.y*XY_ONE);
|
||||
ISET(sst->s, sTri->s*ST_ONE);
|
||||
ISET(sst->t, sTri->t*ST_ONE);
|
||||
ISET(sst->w, sTri->w*W_ONE);
|
||||
ISET(sst->dsdx, sTri->dsdx*ST_ONE);
|
||||
ISET(sst->dtdx, sTri->dtdx*ST_ONE);
|
||||
ISET(sst->dwdx, sTri->dwdx*W_ONE);
|
||||
ISET(sst->dsdy, sTri->dsdy*ST_ONE);
|
||||
ISET(sst->dtdy, sTri->dtdy*ST_ONE);
|
||||
ISET(sst->dwdy, sTri->dwdy*W_ONE);
|
||||
ISET(sst->triangleCMD,v2_triangle_cmd_from_abc(sTri->vA, sTri->vB, sTri->vC));
|
||||
}
|
||||
|
||||
void
|
||||
drawSquare( const SstRegs * const sst,
|
||||
const int16_t x,
|
||||
const int16_t y,
|
||||
const int16_t tSize)
|
||||
{
|
||||
const def_sTriangle tri1 = {
|
||||
.vA = {.x= (x+0), .y = (y+0)},
|
||||
.vB = {.x= (x+tSize), .y = (y+0)},
|
||||
.vC = {.x= (x+0), .y = (y+tSize)},
|
||||
.s = 0,
|
||||
.t = 0,
|
||||
.w = 1,
|
||||
.dsdx = 1, .dtdx = 0,
|
||||
.dwdx = 0
|
||||
.dsdy = 0, .dtdy = 1,
|
||||
.dwdy = 0};
|
||||
drawTriangle(sst, &tri1);
|
||||
|
||||
const def_sTriangle tri2 = {
|
||||
.vA = {.x= (x+0), .y = (y+tSize)},
|
||||
.vB = {.x= (x+tSize), .y = (y+0)},
|
||||
.vC = {.x= (x+tSize), .y = (y+tSize)},
|
||||
.s = 0,
|
||||
.t = tSize,
|
||||
.w = 1,
|
||||
.dsdx = 1, .dtdx = 0,
|
||||
.dwdx = 0
|
||||
.dsdy = 0, .dtdy = 1,
|
||||
.dwdy = 0 };
|
||||
drawTriangle(sst, &tri2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user