autoheight
[voxscape] / src / voxscape.c
index 0ea8f06..a23a851 100644 (file)
@@ -66,7 +66,7 @@ struct voxscape *vox_create(int xsz, int ysz)
                vox->xshift++;
        }
 
-       vox->vheight = 50;
+       vox->vheight = 80;
        vox->proj_dist = 4;     /* TODO */
 
        return vox;
@@ -120,6 +120,14 @@ void vox_free(struct voxscape *vox)
        free(vox);
 }
 
+int vox_height(struct voxscape *vox, int32_t x, int32_t y)
+{
+       int tx = (x >> 16) & vox->xmask;
+       int ty = (y >> 16) & vox->ymask;
+
+       return vox->height[(ty << vox->xshift) + tx];
+}
+
 void vox_framebuf(struct voxscape *vox, int xres, int yres, uint32_t *fb)
 {
        if(xres != vox->fbwidth) {
@@ -134,12 +142,16 @@ void vox_framebuf(struct voxscape *vox, int xres, int yres, uint32_t *fb)
        vox->fbheight = yres;
 }
 
-void vox_view(struct voxscape *vox, int32_t x, int32_t y, int32_t angle)
+void vox_view(struct voxscape *vox, int32_t x, int32_t y, int h, int32_t angle)
 {
+       if(h < 0) {
+               h = vox_height(vox, x, y) - h;
+       }
+
        vox->x = x;
        vox->y = y;
+       vox->vheight = h;
        vox->angle = angle;
-       /* TODO precalc stuff */
 
        vox->valid &= ~SLICELEN;
 }
@@ -210,7 +222,7 @@ void vox_render_slice(struct voxscape *vox, int n)
                tx = (x >> 16) & vox->xmask;
                ty = (y >> 16) & vox->ymask;
 
-               hval = vox->height[(ty << vox->xshift) + tx] - 80;
+               hval = vox->height[(ty << vox->xshift) + tx] - vox->vheight;
                hval = hval * 160 / (vox->znear + n) + 250;
                if(hval > vox->fbheight) hval = vox->fbheight;
                if(hval > vox->coltop[i]) {