X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fvoxscape.c;h=28a02bf44674cb6a6a25da8b89154d5e0342ef09;hb=2c28fb640747244df7009a86df557d22a07ad5b1;hp=2ccb5f9507e8e4bbeb9e04a4a39a432b2e171368;hpb=5e9496165d81a0f9923d67969dcb64a2f81ffdab;p=voxscape diff --git a/src/voxscape.c b/src/voxscape.c index 2ccb5f9..28a02bf 100644 --- a/src/voxscape.c +++ b/src/voxscape.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "voxscape.h" @@ -64,7 +65,8 @@ struct voxscape *vox_create(int xsz, int ysz) vox->xshift++; } - vox->proj_dist = 2; /* TODO */ + vox->vheight = 50; + vox->proj_dist = 4; /* TODO */ return vox; } @@ -187,7 +189,7 @@ void vox_begin(struct voxscape *vox) if(!(vox->valid & SLICELEN)) { float theta = (float)vox->fov * M_PI / 360.0f; /* half angle */ for(i=0; inslices; i++) { - vox->slicelen[i] = (int32_t)((vox->znear + i) * tan(theta) * 2.0f * 65536.0f); + vox->slicelen[i] = (int32_t)((vox->znear + i) * tan(theta) * 10.0f * 65536.0f); } vox->valid |= SLICELEN; } @@ -204,16 +206,17 @@ void vox_render_slice(struct voxscape *vox, int n) xstep = len / vox->fbwidth; x = vox->x - xstep * (vox->fbwidth >> 1); - y = vox->y + (vox->znear << 16); + y = vox->y + ((vox->znear + n) << 16); for(i=0; ifbwidth; i++) { tx = (x >> 16) & vox->xmask; ty = (y >> 16) & vox->ymask; - hval = vox->height[(ty << vox->xshift) + tx]; - hval = (hval - vox->vheight) * vox->proj_dist / (vox->znear + i); + hval = vox->height[(ty << vox->xshift) + tx] - 80; + hval = hval * 80 / (vox->znear + n) + 250; + if(hval > vox->fbheight) hval = vox->fbheight; if(hval > vox->coltop[i]) { color = vox->color[(ty << vox->xshift) + tx]; - colstart = vox->fbheight - 1 - hval; + colstart = vox->fbheight - hval; colheight = hval - vox->coltop[i]; fbptr = vox->fb + colstart * vox->fbwidth + i; @@ -221,8 +224,49 @@ void vox_render_slice(struct voxscape *vox, int n) *fbptr = color; fbptr += vox->fbwidth; } + vox->coltop[i] = hval; } x += xstep; } } + +void vox_sky_grad(struct voxscape *vox, uint32_t chor, uint32_t ctop) +{ + int i, j, colheight, t; + int r0, g0, b0, r1, g1, b1, r, g, b; + int d = vox->fbheight - 250; + uint32_t *grad, *fbptr; + + grad = alloca(vox->fbheight * sizeof *grad); + + r0 = ctop >> 16; + g0 = (ctop >> 8) & 0xff; + b0 = ctop & 0xff; + r1 = chor >> 16; + g1 = (chor >> 8) & 0xff; + b1 = chor & 0xff; + + for(i=0; i> 8; + g = ((g0 << 8) + (g1 - g0) * t) >> 8; + b = ((b0 << 8) + (b1 - b0) * t) >> 8; + assert(r >= 0 && r < 256); + assert(g >= 0 && g < 256); + assert(b >= 0 && b < 256); + grad[i] = (r << 16) | (g << 8) | b; + } + for(i=d; ifbheight; i++) { + grad[i] = chor; + } + + for(i=0; ifbwidth; i++) { + fbptr = vox->fb + i; + colheight = vox->fbheight - vox->coltop[i]; + for(j=0; jfbwidth; + } + } +}