idk wip
This commit is contained in:
parent
d8f573c678
commit
4e3e592b7f
1 changed files with 84 additions and 57 deletions
141
source/main.c
141
source/main.c
|
@ -88,7 +88,7 @@ volatile FIXED_POINT K2 = (2 * CUBE_WIDTH) + 20;
|
||||||
#define SQ(n) (n * n)
|
#define SQ(n) (n * n)
|
||||||
#define SQ_FP(n) (MULT_FP(n, n))
|
#define SQ_FP(n) (MULT_FP(n, n))
|
||||||
|
|
||||||
#define COORD2INDEX(x, y) (x * VWIDTH + y)
|
#define COORD2INDEX(x, y) (y * VWIDTH + x)
|
||||||
#define COUPLE2INDEX(x) (COORD2INDEX(x[0], x[1]))
|
#define COUPLE2INDEX(x) (COORD2INDEX(x[0], x[1]))
|
||||||
|
|
||||||
#define GET_ROTATE_X_Q(a) ({ float _a = (FIXED2FLOAT(a)) ; \
|
#define GET_ROTATE_X_Q(a) ({ float _a = (FIXED2FLOAT(a)) ; \
|
||||||
|
@ -117,7 +117,7 @@ struct Quaternions {
|
||||||
FIXED_POINT x;
|
FIXED_POINT x;
|
||||||
FIXED_POINT y;
|
FIXED_POINT y;
|
||||||
FIXED_POINT z;
|
FIXED_POINT z;
|
||||||
} Target, Current, Last;
|
} Target, Current;
|
||||||
|
|
||||||
FIXED_POINT interpolationStep = 0;
|
FIXED_POINT interpolationStep = 0;
|
||||||
FIXED_POINT zBuffer[VHEIGHT * VWIDTH];
|
FIXED_POINT zBuffer[VHEIGHT * VWIDTH];
|
||||||
|
@ -235,38 +235,62 @@ chooseMainFace()
|
||||||
return frontFacingFace;
|
return frontFacingFace;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
char
|
||||||
fill_quads(char current_face, char top_left[2], char top_right[2],
|
isInQuad(char curr[2], char top[2], char left[2],
|
||||||
char bot_left[2], char bot_right[2])
|
char right[2], char bot[2])
|
||||||
{
|
{
|
||||||
// calc slope foreach side
|
char *points[4] = {top, left, bot, right};
|
||||||
float slope_top = 0;
|
|
||||||
float slope_bot = 0;
|
|
||||||
float slope_left = INFINITY;
|
|
||||||
float slope_right = -INFINITY;
|
|
||||||
|
|
||||||
if (top_left[0] != top_right[0])
|
char pos = 0, neg = 0;
|
||||||
slope_top = (float)(top_right[1] - top_left[1]) /
|
char x = curr[0];
|
||||||
(float)(top_right[0] - top_left[0]);
|
char y = curr[1];;
|
||||||
if (bot_left[0] == bot_right[0])
|
int d;
|
||||||
slope_bot = (float)(bot_right[1] - bot_left[1]) /
|
|
||||||
(float)(bot_right[0] - bot_left[0]);
|
|
||||||
if (top_left[0] == bot_left[0])
|
|
||||||
slope_left = (float)(bot_left[1] - top_left[1]) /
|
|
||||||
(float)(bot_left[0] - top_left[0]);
|
|
||||||
if (top_right[0] == bot_right[0])
|
|
||||||
slope_right = (float)(bot_right[1] - top_right[1]) /
|
|
||||||
(float)(bot_right[0] - top_right[0]);
|
|
||||||
|
|
||||||
int top = top_right[1] > top_left[1] ? top_right[1]: top_left[1];
|
for (char i = 0; i < 4; ++i) {
|
||||||
int bot = bot_right[1] > bot_left[1] ? bot_right[1]: bot_left[1];
|
if (points[i][0] == curr[0] && points[i][1] == curr[1])
|
||||||
int left = top_left[0] > bot_left[0] ? top_left[0]: bot_left[0];
|
return 1;
|
||||||
int right = top_right[0] > bot_right[0] ? top_right[0]: bot_right[0];
|
|
||||||
for (int y = top ; y <= bot ; ++y) {
|
//Form a segment between the i'th point
|
||||||
for (int x = left ; x <= right ; ++x) {
|
char x1 = points[i][0];
|
||||||
if (slope_top * x + top <= y)
|
char y1 = points[i][1];
|
||||||
// TODO side check
|
|
||||||
output[COORD2INDEX(x, y)] = current_face;
|
//And the i+1'th, or if i is the last, with the first point
|
||||||
|
char i2 = (i + 1) % 4;
|
||||||
|
|
||||||
|
char x2 = points[i2][0];
|
||||||
|
char y2 = points[i2][1];
|
||||||
|
|
||||||
|
|
||||||
|
//Compute the cross product
|
||||||
|
d = (x - x1) * (y2 - y1) - (y - y1) * (x2 - x1);
|
||||||
|
|
||||||
|
if (d > 0) ++pos;
|
||||||
|
if (d < 0) ++neg;
|
||||||
|
|
||||||
|
//If the sign changes, then point is outside
|
||||||
|
if (pos > 0 && neg > 0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
fill_quads(char current_face, char top[2], char left[2],
|
||||||
|
char right[2], char bot[2])
|
||||||
|
{
|
||||||
|
if (current_face != 0) return;
|
||||||
|
output[COUPLE2INDEX(top)] = RGB15(0, 0, 15);
|
||||||
|
output[COUPLE2INDEX(left)] = RGB15(0, 0, 15);
|
||||||
|
output[COUPLE2INDEX(right)] = RGB15(0, 0, 15);
|
||||||
|
|
||||||
|
for (int y = top[1] ; y < bot[1] ; ++y) {
|
||||||
|
for (int x = left[0] ; x < right[0] ; ++x) {
|
||||||
|
char curr[2] = {x, y};
|
||||||
|
if (isInQuad(curr, top, left, right, bot))
|
||||||
|
//zbuffer issue
|
||||||
|
{}
|
||||||
|
//output[COORD2INDEX(x, y)] = current_face;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -275,33 +299,37 @@ void
|
||||||
detect_and_fill_quads()
|
detect_and_fill_quads()
|
||||||
{
|
{
|
||||||
for (int current_face = 0 ; current_face < NUM_FACES ; ++current_face) {
|
for (int current_face = 0 ; current_face < NUM_FACES ; ++current_face) {
|
||||||
char top_left [2] = {VWIDTH, VHEIGHT};
|
char last_top [2] = {VWIDTH, VHEIGHT};
|
||||||
char top_right[2] = {0, VHEIGHT};
|
char last_left[2] = {VWIDTH, 0};
|
||||||
char bot_left [2] = {VWIDTH, 0};
|
char last_right [2] = {0, 0};
|
||||||
char bot_right[2] = {0, 0};
|
char last_bot[2] = {0, 0};
|
||||||
|
char top [2] = {VWIDTH, VHEIGHT};
|
||||||
|
char left[2] = {VWIDTH, 0};
|
||||||
|
char right [2] = {0, 0};
|
||||||
|
char bot[2] = {0, 0};
|
||||||
for (char y = 0; y < VHEIGHT; ++y) {
|
for (char y = 0; y < VHEIGHT; ++y) {
|
||||||
for (char x = 0; x < VWIDTH; ++x) {
|
for (char x = 0; x < VWIDTH; ++x) {
|
||||||
if (output[COORD2INDEX(x, y)] != current_face)
|
if (output[COORD2INDEX(x, y)] != current_face)
|
||||||
continue;
|
continue;
|
||||||
if (x <= top_left[0] && y <= top_left[1]){
|
if (x <= left[0]) {
|
||||||
top_left[0] = x;
|
left[0] = x;
|
||||||
top_left[1] = y;
|
left[1] = y;
|
||||||
}
|
}
|
||||||
if (x >= top_right[0] && y <= top_right[1]){
|
if (y <= top[1]) {
|
||||||
top_right[0] = x;
|
top[0] = x;
|
||||||
top_right[1] = y;
|
top[1] = y;
|
||||||
}
|
}
|
||||||
if (x <= bot_left[0] && y >= bot_left[1]){
|
if (x >= right[0]) {
|
||||||
bot_left[0] = x;
|
right[0] = x;
|
||||||
bot_left[1] = y;
|
right[1] = y;
|
||||||
}
|
}
|
||||||
if (x >= bot_right[0] && y >= bot_right[1]){
|
if (y >= bot[1]) {
|
||||||
bot_right[0] = x;
|
bot[0] = x;
|
||||||
bot_right[1] = y;
|
bot[1] = y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fill_quads(current_face, top_left, top_right, bot_left, bot_right);
|
fill_quads(current_face, top, left, right, bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -315,7 +343,7 @@ printAscii()
|
||||||
MEM_VRAM_MODE3_FB[120 + 96 * GBA_SCREEN_W] = RGB15(currentCountR, 31 - currentCountR, 0);
|
MEM_VRAM_MODE3_FB[120 + 96 * GBA_SCREEN_W] = RGB15(currentCountR, 31 - currentCountR, 0);
|
||||||
currentCountR = currentCountR == 31 ? 0 : 31;
|
currentCountR = currentCountR == 31 ? 0 : 31;
|
||||||
|
|
||||||
//detect_and_fill_quads();
|
detect_and_fill_quads();
|
||||||
|
|
||||||
for (int i = 0; i < VHEIGHT; ++i) {
|
for (int i = 0; i < VHEIGHT; ++i) {
|
||||||
for (int j = 0; j < VWIDTH; ++j) {
|
for (int j = 0; j < VWIDTH; ++j) {
|
||||||
|
@ -411,31 +439,30 @@ handleAngle(char input)
|
||||||
// TODO
|
// TODO
|
||||||
if (currentlyMoving == 0) {
|
if (currentlyMoving == 0) {
|
||||||
currentlyMoving = input;
|
currentlyMoving = input;
|
||||||
Last = Current;
|
|
||||||
switch (input) {
|
switch (input) {
|
||||||
case 'w':
|
case 'w':
|
||||||
case 'W':
|
case 'W':
|
||||||
Target = multQ(GET_ROTATE_X_Q(FLOAT2FIXED(M_PI_2)), Target);
|
Target = multQ(GET_ROTATE_X_Q(FLOAT2FIXED(M_PI_2)), Current);
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'A':
|
case 'A':
|
||||||
Target = multQ(GET_ROTATE_Y_Q(-FLOAT2FIXED(M_PI_2)), Target);
|
Target = multQ(GET_ROTATE_Y_Q(-FLOAT2FIXED(M_PI_2)), Current);
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
case 'S':
|
case 'S':
|
||||||
Target = multQ(GET_ROTATE_X_Q(-FLOAT2FIXED(M_PI_2)), Target);
|
Target = multQ(GET_ROTATE_X_Q(-FLOAT2FIXED(M_PI_2)), Current);
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'D':
|
case 'D':
|
||||||
Target = multQ(GET_ROTATE_Y_Q(FLOAT2FIXED(M_PI_2)), Target);
|
Target = multQ(GET_ROTATE_Y_Q(FLOAT2FIXED(M_PI_2)), Current);
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
case 'Q':
|
case 'Q':
|
||||||
Target = multQ(GET_ROTATE_Z_Q(-FLOAT2FIXED(M_PI_2)), Target);
|
Target = multQ(GET_ROTATE_Z_Q(-FLOAT2FIXED(M_PI_2)), Current);
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E':
|
case 'E':
|
||||||
Target = multQ(GET_ROTATE_Z_Q(FLOAT2FIXED(M_PI_2)), Target);
|
Target = multQ(GET_ROTATE_Z_Q(FLOAT2FIXED(M_PI_2)), Current);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
currentlyMoving = 0;
|
currentlyMoving = 0;
|
||||||
|
@ -480,7 +507,7 @@ main()
|
||||||
cubeX <= CUBE_WIDTH_FP - STEP_FP; cubeX += STEP_FP) {
|
cubeX <= CUBE_WIDTH_FP - STEP_FP; cubeX += STEP_FP) {
|
||||||
for (FIXED_POINT cubeY = -CUBE_WIDTH_FP + STEP_FP;
|
for (FIXED_POINT cubeY = -CUBE_WIDTH_FP + STEP_FP;
|
||||||
cubeY <= CUBE_WIDTH_FP - STEP_FP; cubeY += STEP_FP) {
|
cubeY <= CUBE_WIDTH_FP - STEP_FP; cubeY += STEP_FP) {
|
||||||
switch (frontFacingFace) {
|
switch (FACE_FRONT) {
|
||||||
case FACE_FRONT:
|
case FACE_FRONT:
|
||||||
rotateCube(cubeX, cubeY, -CUBE_WIDTH_FP, FACE_FRONT);
|
rotateCube(cubeX, cubeY, -CUBE_WIDTH_FP, FACE_FRONT);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue