fix: semi works but fundamentally flawed reasoning

This commit is contained in:
violette 2025-09-01 03:09:45 -04:00
parent 044d31fa47
commit 326f6a894c

View file

@ -47,7 +47,6 @@ RGB15(uint16_t r, uint16_t g, uint16_t b)
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
#include <stdio.h>
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
@ -91,13 +90,13 @@ volatile FIXED_POINT K2 = (2 * CUBE_WIDTH) + 20;
#define COORD2INDEX(x, y) (y * VWIDTH + x) #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 = (a) ; \
struct Quaternions q = {}; q.w = FLOAT2FIXED(cos(_a * .5)); \ struct Quaternions q = {}; q.w = FLOAT2FIXED(cos(_a * .5)); \
q.x = FLOAT2FIXED(sin(_a * .5)); q; }) q.x = FLOAT2FIXED(sin(_a * .5)); q; })
#define GET_ROTATE_Y_Q(a) ({ float _a = (FIXED2FLOAT(a)) ; \ #define GET_ROTATE_Y_Q(a) ({ float _a = (a) ; \
struct Quaternions q = {}; q.w = FLOAT2FIXED(cos(_a * .5)); \ struct Quaternions q = {}; q.w = FLOAT2FIXED(cos(_a * .5)); \
q.y = FLOAT2FIXED(sin(_a * .5)); q; }) q.y = FLOAT2FIXED(sin(_a * .5)); q; })
#define GET_ROTATE_Z_Q(a) ({ float _a = (FIXED2FLOAT(a)) ; \ #define GET_ROTATE_Z_Q(a) ({ float _a = (a) ; \
struct Quaternions q = {}; q.w = FLOAT2FIXED(cos(_a * .5)); \ struct Quaternions q = {}; q.w = FLOAT2FIXED(cos(_a * .5)); \
q.z = FLOAT2FIXED(sin(_a * .5)); q; }) q.z = FLOAT2FIXED(sin(_a * .5)); q; })
@ -279,30 +278,26 @@ void
fill_quads(char current_face, char top[2], char left[2], fill_quads(char current_face, char top[2], char left[2],
char right[2], char bot[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 y = top[1] ; y < bot[1] ; ++y) {
for (int x = left[0] ; x < right[0] ; ++x) { for (int x = left[0] ; x < right[0] ; ++x) {
char curr[2] = {x, y}; char curr[2] = {x, y};
if (isInQuad(curr, top, left, right, bot)) if (isInQuad(curr, top, left, right, bot))
//zbuffer issue //zbuffer issue
{} output[COORD2INDEX(x, y)] = current_face;
//output[COORD2INDEX(x, y)] = current_face;
} }
} }
} }
float
dist(char a[2], char b[2]) {
return (a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]);
}
void 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 last_top [2] = {VWIDTH, VHEIGHT};
char last_left[2] = {VWIDTH, 0};
char last_right [2] = {0, 0};
char last_bot[2] = {0, 0};
char top [2] = {VWIDTH, VHEIGHT}; char top [2] = {VWIDTH, VHEIGHT};
char left[2] = {VWIDTH, 0}; char left[2] = {VWIDTH, 0};
char right [2] = {0, 0}; char right [2] = {0, 0};
@ -311,19 +306,19 @@ detect_and_fill_quads()
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 <= left[0]) { if (y < top[1]) {
left[0] = x;
left[1] = y;
}
if (y <= top[1]) {
top[0] = x; top[0] = x;
top[1] = y; top[1] = y;
} }
if (x >= right[0]) { if (x > right[0] && (x != top[0] || y != top [1])) {
right[0] = x; right[0] = x;
right[1] = y; right[1] = y;
} }
if (y >= bot[1]) { if (x <= left[0] && (x != top[0] || y != top [1])) { // <= to force it bot
left[0] = x;
left[1] = y;
}
if (y >= bot[1] && (x != right[0] || y != right [1]) && (x != left[0] || y != left[1])) {
bot[0] = x; bot[0] = x;
bot[1] = y; bot[1] = y;
} }
@ -442,27 +437,27 @@ handleAngle(char input)
switch (input) { switch (input) {
case 'w': case 'w':
case 'W': case 'W':
Target = multQ(GET_ROTATE_X_Q(FLOAT2FIXED(M_PI_2)), Current); Target = multQ(GET_ROTATE_X_Q(M_PI_2), Current);
break; break;
case 'a': case 'a':
case 'A': case 'A':
Target = multQ(GET_ROTATE_Y_Q(-FLOAT2FIXED(M_PI_2)), Current); Target = multQ(GET_ROTATE_Y_Q(-M_PI_2), Current);
break; break;
case 's': case 's':
case 'S': case 'S':
Target = multQ(GET_ROTATE_X_Q(-FLOAT2FIXED(M_PI_2)), Current); Target = multQ(GET_ROTATE_X_Q(-M_PI_2), Current);
break; break;
case 'd': case 'd':
case 'D': case 'D':
Target = multQ(GET_ROTATE_Y_Q(FLOAT2FIXED(M_PI_2)), Current); Target = multQ(GET_ROTATE_Y_Q(M_PI_2), Current);
break; break;
case 'q': case 'q':
case 'Q': case 'Q':
Target = multQ(GET_ROTATE_Z_Q(-FLOAT2FIXED(M_PI_2)), Current); Target = multQ(GET_ROTATE_Z_Q(-M_PI_2), Current);
break; break;
case 'e': case 'e':
case 'E': case 'E':
Target = multQ(GET_ROTATE_Z_Q(FLOAT2FIXED(M_PI_2)), Current); Target = multQ(GET_ROTATE_Z_Q(M_PI_2), Current);
break; break;
default: default:
currentlyMoving = 0; currentlyMoving = 0;
@ -507,7 +502,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 (FACE_FRONT) { switch (frontFacingFace) {
case FACE_FRONT: case FACE_FRONT:
rotateCube(cubeX, cubeY, -CUBE_WIDTH_FP, FACE_FRONT); rotateCube(cubeX, cubeY, -CUBE_WIDTH_FP, FACE_FRONT);
break; break;