Slightly optimized cube.
This commit is contained in:
parent
f642221028
commit
aae737d17d
1 changed files with 35 additions and 15 deletions
|
@ -97,10 +97,22 @@ int32_t SIN[] = { 0, 6, 12, 18, 25, 31, 37, 43, 50, 56, 62, 68, 75, 81, 87, 93,
|
||||||
509, 510, 510, 511, 511, 511, 511, 511
|
509, 510, 510, 511, 511, 511, 511, 511
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct lineS {
|
||||||
|
int16_t x1;
|
||||||
|
int16_t y1;
|
||||||
|
int16_t x2;
|
||||||
|
int16_t y2;
|
||||||
|
} lineT;
|
||||||
|
|
||||||
int32_t *COS = SIN + COS_OFF;
|
int32_t *COS = SIN + COS_OFF;
|
||||||
|
uint16_t width;
|
||||||
|
uint16_t height;
|
||||||
|
int32_t a = TO_FIX(4);
|
||||||
|
int32_t scale = TO_FIX(40);
|
||||||
|
lineT past[24][2];
|
||||||
|
|
||||||
|
|
||||||
void draw_cube(int16_t t) {
|
void draw_cube(byte p, int16_t t) {
|
||||||
|
|
||||||
static const int16_t edges[] = {
|
static const int16_t edges[] = {
|
||||||
0, 1, 1, 3, 3, 2, 2, 0,
|
0, 1, 1, 3, 3, 2, 2, 0,
|
||||||
|
@ -128,18 +140,13 @@ void draw_cube(int16_t t) {
|
||||||
int32_t cubeProjX[8];
|
int32_t cubeProjX[8];
|
||||||
int32_t cubeProjY[8];
|
int32_t cubeProjY[8];
|
||||||
int16_t i;
|
int16_t i;
|
||||||
|
byte l;
|
||||||
int16_t e1;
|
int16_t e1;
|
||||||
int16_t e2;
|
int16_t e2;
|
||||||
int16_t x1;
|
int16_t x1;
|
||||||
int16_t y1;
|
int16_t y1;
|
||||||
int16_t x2;
|
int16_t x2;
|
||||||
int16_t y2;
|
int16_t y2;
|
||||||
uint16_t width;
|
|
||||||
uint16_t height;
|
|
||||||
int32_t a = TO_FIX(4);
|
|
||||||
int32_t scale = TO_FIX(40);
|
|
||||||
|
|
||||||
bitmapGetResolution(&width, &height);
|
|
||||||
|
|
||||||
for (i=0; i<8; ++i) {
|
for (i=0; i<8; ++i) {
|
||||||
// Rotation around Y
|
// Rotation around Y
|
||||||
|
@ -158,23 +165,34 @@ void draw_cube(int16_t t) {
|
||||||
cubeProjY[i] = fix_div(fix_mul(a, cubeRotY[i]), cubeRotZ[i]);
|
cubeProjY[i] = fix_div(fix_mul(a, cubeRotY[i]), cubeRotZ[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
l = 0;
|
||||||
for (i=0; i<24; i += 2) {
|
for (i=0; i<24; i += 2) {
|
||||||
e1 = edges[i];
|
e1 = edges[i];
|
||||||
e2 = edges[i + 1];
|
e2 = edges[i + 1];
|
||||||
x1 = TO_LONG(fix_mul(cubeProjX[e1], scale)) + (width >> 1);
|
x1 = TO_LONG(fix_mul(cubeProjX[e1], scale)) + width;
|
||||||
y1 = TO_LONG(fix_mul(cubeProjY[e1], scale)) + (height >> 1);
|
y1 = TO_LONG(fix_mul(cubeProjY[e1], scale)) + height;
|
||||||
x2 = TO_LONG(fix_mul(cubeProjX[e2], scale)) + (width >> 1);
|
x2 = TO_LONG(fix_mul(cubeProjX[e2], scale)) + width;
|
||||||
y2 = TO_LONG(fix_mul(cubeProjY[e2], scale)) + (height >> 1);
|
y2 = TO_LONG(fix_mul(cubeProjY[e2], scale)) + height;
|
||||||
|
past[l][p].x1 = x1;
|
||||||
|
past[l][p].y1 = y1;
|
||||||
|
past[l][p].x2 = x2;
|
||||||
|
past[l][p].y2 = y2;
|
||||||
|
l++;
|
||||||
bitmapLine(x1, y1, x2, y2);
|
bitmapLine(x1, y1, x2, y2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
int16_t t = 0;
|
byte i;
|
||||||
byte p = 0;
|
int16_t t = 0;
|
||||||
|
byte p = 0;
|
||||||
|
|
||||||
f256Init();
|
f256Init();
|
||||||
|
|
||||||
|
bitmapGetResolution(&width, &height);
|
||||||
|
width = width >> 1;
|
||||||
|
height = height >> 1;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
if (p) {
|
if (p) {
|
||||||
p = 0;
|
p = 0;
|
||||||
|
@ -186,9 +204,11 @@ int main(void) {
|
||||||
bitmapShowPage(1);
|
bitmapShowPage(1);
|
||||||
}
|
}
|
||||||
bitmapSetColor(0);
|
bitmapSetColor(0);
|
||||||
bitmapClear();
|
for (i=0; i<12; i++) {
|
||||||
|
bitmapLine(past[i][p].x1, past[i][p].y1, past[i][p].x2, past[i][p].y2);
|
||||||
|
}
|
||||||
bitmapSetColor(255);
|
bitmapSetColor(255);
|
||||||
draw_cube(t);
|
draw_cube(p, t);
|
||||||
t += 2;
|
t += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue