From 87b4a3195e32c211e9910970a96f29083a78458f Mon Sep 17 00:00:00 2001 From: farisawan-2000 Date: Sat, 12 Dec 2020 18:50:26 -0500 Subject: [PATCH] rotation and translation work --- mtx.c | 4 +- s2d_draw.c | 2 +- s2d_parse.c | 41 +++++++++++++++---- x86_testing_ground/atoi.c | 84 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 x86_testing_ground/atoi.c diff --git a/mtx.c b/mtx.c index a3d706ad..af59a1c0 100644 --- a/mtx.c +++ b/mtx.c @@ -42,8 +42,8 @@ void mat2_ident(uObjMtx *dst, int scale) { // cos -sin sin cos void mat2_rotate(uObjMtx *dst, f32 degrees) { dst->m.A = ftoq(cosf(degrees)); - dst->m.B = ftoq(-sinf(degrees)); - dst->m.C = ftoq(sinf(degrees)); + dst->m.B = ftoq(sinf(degrees)); + dst->m.C = ftoq(-sinf(degrees)); dst->m.D = ftoq(cosf(degrees)); } diff --git a/s2d_draw.c b/s2d_draw.c index bdb347f3..3f8a88f0 100644 --- a/s2d_draw.c +++ b/s2d_draw.c @@ -86,7 +86,7 @@ void draw_s2d_glyph(char c, int x, int y, uObjMtx *mt) { setup_font(c); // mtx_pipeline(mt, x, y); - mtx_pipeline2(mt, x, y); + mtx_pipeline(mt, x, y); gSPObjSprite(gDisplayListHead++, &s2d_font); } diff --git a/s2d_parse.c b/s2d_parse.c index 727ce4a7..f5cb2ba7 100644 --- a/s2d_parse.c +++ b/s2d_parse.c @@ -7,37 +7,64 @@ int saved_degrees = 0; +int s2d_atoi(char *s, char **s2) { + int ret = 0; + int isNegative = (*s == '-'); + if (isNegative) { + s++; + (*s2)++; + } + for (; *s != '\0' && *s != ' ' && *s >= '0' && *s <= '9'; s++) { + ret *= 10; + if (*s >= '0' && *s <= '9') + ret += *s - '0'; + else break; + if (!(*(s+1) != '\0' && *(s+1) != ' ' && *(s+1) >= '0' && *(s+1) <= '9')) break; + (*s2)++; + } + if (isNegative) ret *= -1; + return ret; +} + void s2d_print(int x, int y, const char *str, uObjMtx *buf) { char *p = str; + int tx = 0, ty = 0; if (*p == '\0') return; do { char r = *p; - char s, rd, tx, ty; + int s, rd; switch (r) { case CH_SCALE: - s = CH_GET_NEXT(p); + CH_GET_NEXT(p); + s = s2d_atoi(p, &p); myScale = s; break; case CH_ROT: - rd = CH_GET_NEXT(p); + CH_GET_NEXT(p); + rd = s2d_atoi(p, &p); saved_degrees = rd; myDegrees = rd; break; case CH_TRANSLATE: - tx = CH_GET_NEXT(p); - ty = CH_GET_NEXT(p); + CH_GET_NEXT(p); + tx = s2d_atoi(p, &p); + CH_GET_NEXT(p); + CH_GET_NEXT(p); + ty = s2d_atoi(p, &p); break; default: if (myDegrees == 0) - draw_s2d_glyph(r, x += (8 * myScale), y, (buf++)); + draw_s2d_glyph(r, (x += (8 * myScale)) + tx, y + ty, (buf++)); else - draw_s2d_glyph(r, x += ((8 * myScale)), y, (buf++)); + draw_s2d_glyph(r, (x += ((8 * myScale))) + tx, y + ty, (buf++)); } // myDegrees += saved_degrees; } while (*(++p) != '\0'); myScale = 1; myDegrees = 0; saved_degrees = 0; + tx = 0; + ty = 0; } diff --git a/x86_testing_ground/atoi.c b/x86_testing_ground/atoi.c new file mode 100644 index 00000000..1410ff77 --- /dev/null +++ b/x86_testing_ground/atoi.c @@ -0,0 +1,84 @@ +int s2d_atoi(char *s, char **s2) { + int ret = 0; + int isNegative = (*s == '-'); + if (isNegative) {s++; (*s2)++;} + for (; *s != '\0' && *s != ' ' && *s >= '0' && *s <= '9'; s++) { + ret *= 10; + if (*s >= '0' && *s <= '9') + ret += *s - '0'; + else break; + if (!(*(s+1) != '\0' && *(s+1) != ' ' && *(s+1) >= '0' && *(s+1) <= '9')) break; + (*s2)++; + } + if (isNegative) ret *= -1; + return ret; +} +#define SCALE "\x80" // SCALE (some scale) +#define ROTATE "\x81" // ROTATE (degrees) // TODO: maybe add axis? +#define TRANSLATE "\x82" // TRANSLATE (x) (y) + +#define CH_SCALE '\x80' +#define CH_ROT '\x81' +#define CH_TRANSLATE '\x82' + +#define CH_GET_NEXT(x) (*(++x)) + +int saved_degrees = 0; + +int myScale = 1; +int myDegrees = 0; + +char *t = "TEST" TRANSLATE "10 10CRINGE"; + +void s2d_print(int x, int y, const char *str) { + char *p = str; + if (*p == '\0') return; + do { + char r = *p; + int s, rd, tx = 0, ty = 0; + switch (r) { + case CH_SCALE: + s = CH_GET_NEXT(p); + printf("%s\n", p); + s = s2d_atoi(p, &p); + printf("%d\n", s); + myScale = s; + break; + case CH_ROT: + rd = CH_GET_NEXT(p); + saved_degrees = rd; + myDegrees = rd; + break; + case CH_TRANSLATE: + CH_GET_NEXT(p); + tx = s2d_atoi(p, &p); + printf("%d\n", tx); + CH_GET_NEXT(p); + CH_GET_NEXT(p); + ty = s2d_atoi(p, &p); + // CH_GET_NEXT(p); + printf("%d\n", ty); + break; + + default: + printf("%c %d\n",r, myScale); + } + // myDegrees += saved_degrees; + } while (*(++p) != '\0'); + myScale = 1; + myDegrees = 0; + saved_degrees = 0; +} + + +int main(void) { + char *s = t; + s++; + s++; + s++; + s++; + // printf("%d\n", s2d_atoi(s, &s)); + // printf("%s\n", s); + s2d_print(0,0, t); + // printf("%d\n", s2d_atoi("3582932j")); +} \ No newline at end of file