X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fvoxscape.c;h=ef11974b10ac7e2c3171e1c285c47403258694b8;hb=d98ff7c2912943650e17a4c6caf94998f0b0640b;hp=462ed75d06560d8cdd8c18a5a88ab72120bbf0db;hpb=a4b392b15da0d7da367b1121ec5949f26e10628a;p=gbajam22 diff --git a/src/voxscape.c b/src/voxscape.c index 462ed75..ef11974 100644 --- a/src/voxscape.c +++ b/src/voxscape.c @@ -7,6 +7,9 @@ #include "voxscape.h" #include "debug.h" +#define FBWIDTH 240 +#define FBHEIGHT 160 + #define XLERP(a, b, t, fp) \ ((((a) << (fp)) + ((b) - (a)) * (t)) >> fp) @@ -226,7 +229,8 @@ void vox_begin(struct voxscape *vox) { int i; - memset(vox->coltop, 0, vox->fbwidth * sizeof *vox->coltop); + memset(vox->fb, 0, FBWIDTH * FBHEIGHT); + memset(vox->coltop, 0, FBWIDTH * sizeof *vox->coltop); if(!(vox->valid & SLICELEN)) { float theta = (float)vox->fov * M_PI / 360.0f; /* half angle */ @@ -239,7 +243,7 @@ void vox_begin(struct voxscape *vox) void vox_render_slice(struct voxscape *vox, int n) { - int i, j, hval, colstart, colheight, z; + int i, j, hval, colstart, colheight, col, z; int32_t x, y, len, xstep, ystep; uint8_t color; uint16_t *fbptr; @@ -247,29 +251,48 @@ void vox_render_slice(struct voxscape *vox, int n) z = vox->znear + n; len = vox->slicelen[n] >> 8; - xstep = ((COS(vox->angle) >> 8) * len) / vox->fbwidth; - ystep = ((SIN(vox->angle) >> 8) * len) / vox->fbwidth; + xstep = (((COS(vox->angle) >> 4) * len) >> 4) / FBWIDTH; + ystep = (((SIN(vox->angle) >> 4) * len) >> 4) / FBWIDTH; + + x = vox->x - SIN(vox->angle) * z - xstep * (FBWIDTH / 2); + y = vox->y + COS(vox->angle) * z - ystep * (FBWIDTH / 2); - x = vox->x - SIN(vox->angle) * z - xstep * (vox->fbwidth >> 1); - y = vox->y + COS(vox->angle) * z - ystep * (vox->fbwidth >> 1); - /* TODO double column */ - for(i=0; ifbwidth/2; i++) { + for(i=0; ivheight; - hval = hval * 160 / (vox->znear + n) + vox->horizon; - if(hval > vox->fbheight) hval = vox->fbheight; - if(hval > vox->coltop[i]) { + hval = hval * 40 / (vox->znear + n) + vox->horizon; + if(hval > FBHEIGHT) hval = FBHEIGHT; + if(hval > vox->coltop[col]) { color = vox_color(vox, x, y); - colstart = vox->fbheight - hval; - colheight = hval - vox->coltop[i]; - fbptr = vox->fb + colstart * vox->fbwidth / 2 + i / 2; + colstart = FBHEIGHT - hval; + colheight = hval - vox->coltop[col]; + fbptr = vox->fb + colstart * (FBWIDTH / 2) + i; for(j=0; jfbwidth >> 1; + *fbptr |= color; + fbptr += FBWIDTH / 2; } - vox->coltop[i] = hval; + vox->coltop[col] = hval; } + x += xstep; + y += ystep; + col++; + hval = vox_height(vox, x, y) - vox->vheight; + hval = hval * 40 / (vox->znear + n) + vox->horizon; + if(hval > FBHEIGHT) hval = FBHEIGHT; + if(hval > vox->coltop[col]) { + color = vox_color(vox, x, y); + colstart = FBHEIGHT - hval; + colheight = hval - vox->coltop[col]; + fbptr = vox->fb + colstart * (FBWIDTH / 2) + i; + + for(j=0; jcoltop[col] = hval; + } x += xstep; y += ystep; } @@ -277,44 +300,70 @@ void vox_render_slice(struct voxscape *vox, int n) void vox_sky_solid(struct voxscape *vox, uint8_t color) { - int i, j, colheight; + int i, j, colh0, colh1, colhboth; uint16_t *fbptr; - /* TODO double columns */ - for(i=0; ifbwidth/2; i++) { + for(i=0; ifb + i; - colheight = vox->fbheight - vox->coltop[i]; - for(j=0; jcoltop[i << 1]; + colh1 = FBHEIGHT - vox->coltop[(i << 1) + 1]; + colhboth = colh0 < colh1 ? colh0 : colh1; + + for(j=0; jfbwidth >> 1; + fbptr += FBWIDTH / 2; + } + + if(colh0 > colh1) { + for(j=colhboth; jfbheight - vox->horizon; - uint8_t *grad; + int i, j, colh0, colh1, colhboth, t; + int d = FBHEIGHT - vox->horizon; + uint8_t grad[FBHEIGHT]; uint16_t *fbptr; - grad = alloca(vox->fbheight * sizeof *grad); - for(i=0; ifbheight; i++) { + for(i=d; ifbwidth/2; i++) { - fbptr = vox->fb + i / 2; - colheight = vox->fbheight - vox->coltop[i]; - for(j=0; jfb + i; + colh0 = FBHEIGHT - vox->coltop[i << 1]; + colh1 = FBHEIGHT - vox->coltop[(i << 1) + 1]; + colhboth = colh0 < colh1 ? colh0 : colh1; + + for(j=0; jfbwidth >> 1; + fbptr += FBWIDTH / 2; + } + + if(colh0 > colh1) { + for(j=colhboth; j