From bbe2ec049a812155c75da5ecc303bf3793c9cca8 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sun, 18 Apr 2021 06:28:37 +0300 Subject: [PATCH] curved tunnel --- src/gamescr.c | 11 +++++----- tools/tungen.c | 66 ++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/src/gamescr.c b/src/gamescr.c index 70991e8..30ae380 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -52,12 +52,13 @@ void gamescr(void) __attribute__((noinline, target("arm"), section(".iwram"))) static void draw_tunnel(void) { - int i, j, tx, ty, angle, depth, zoffs; + int i, j, tx, ty, angle, depth, zoffs, uoffs; uint16_t pptop, ppbot; uint16_t *top, *bot; uint32_t tun, *tunptr; zoffs = nframes; + uoffs = 0; top = vram[backbuf]; bot = vram[backbuf] + 159 * 240 / 2; @@ -71,18 +72,18 @@ static void draw_tunnel(void) angle = tun & 0xff; depth = (tun >> 8) & 0xff; - tx = ((angle >> 1) + zoffs) & 0x1f; + tx = ((angle >> 1) + uoffs) & 0x1f; ty = ((depth >> 1) + zoffs) & 0x1f; pptop = tex[(ty << 5) + tx]; - tx = ((angle >> 1) - zoffs) & 0x1f; + tx = ((angle >> 1) - uoffs) & 0x1f; ppbot = tex[(ty << 5) + tx]; angle = (tun >> 16) & 0xff; depth = (tun >> 24) & 0xff; - tx = ((angle >> 1) + zoffs) & 0x1f; + tx = ((angle >> 1) + uoffs) & 0x1f; ty = ((depth >> 1) + zoffs) & 0x1f; pptop |= (uint16_t)tex[(ty << 5) + tx] << 8; - tx = ((angle >> 1) - zoffs) & 0x1f; + tx = ((angle >> 1) - uoffs) & 0x1f; ppbot |= (uint16_t)tex[(ty << 5) + tx] << 8; *top++ = pptop; diff --git a/tools/tungen.c b/tools/tungen.c index 8122c95..4148b26 100644 --- a/tools/tungen.c +++ b/tools/tungen.c @@ -3,11 +3,16 @@ #include #include +struct vec2 { + float x, y; +}; + int main(int argc, char **argv) { - int i, j, xsz = 240, ysz = 160, texsz = 128; + int i, j, imgrad, xsz = 240, ysz = 160, texsz = 128; struct vec2 *tunbuf, *tun; - float aspect; + float aspect, prev_r; + struct vec2 *buf, *ptr; for(i=1; i= 0 && x < xsz && y >= 0 && y < ysz) { + ptr = buf + y * xsz + x; + ptr->x = u; + ptr->y = v * 8; + } + } + prev_r = r; + } + FILE *fp = fopen("tun_preview.ppm", "wb"); if(fp) { fprintf(fp, "P6\n%d %d\n255\n", xsz, ysz); @@ -43,32 +81,24 @@ invalopt: fprintf(stderr, "invalid argument: %s\n", argv[i]); aspect = (float)xsz / (float)ysz; - tun = tunbuf; + ptr = buf; for(i=0; ix; + float v = ptr->y; + int r = (int)(u * 8.0 * 255.0f) & 0xff; + int b = (int)(v * 8.0 * 255.0f) & 0xff; - float u = 0.5f * theta / M_PI + 0.5f; - float v = 0.8f / r; + ptr++; - /* - uint32_t out = ((uint32_t)(u * 65535.0f) & 0xffff) | - (((uint32_t)(v * 65535.0f) & 0xffff) << 16); - */ uint16_t out = ((uint16_t)(u * 255.0f) & 0xff) | (((uint16_t)(v * 255.0f) & 0xff) << 8); fwrite(&out, sizeof out, 1, stdout); if(fp) { - int cr = (int)(u * 2048.0f) & 0xff; - int cb = (int)(r * 2048.0f) & 0xff; - fputc(cr, fp); + fputc(r, fp); fputc(0, fp); - fputc(cb, fp); + fputc(b, fp); } } } -- 1.7.10.4