From 34a5a35c6ba9aff4ae92475bfa8d3b398633d835 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sun, 16 Oct 2022 19:44:10 +0300 Subject: [PATCH] autoheight --- src/main.c | 5 ++--- src/voxscape.c | 20 ++++++++++++++++---- src/voxscape.h | 5 ++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index e05118b..2a5459a 100644 --- a/src/main.c +++ b/src/main.c @@ -77,8 +77,7 @@ int init(void) return -1; } vox_framebuf(vox, FB_W, FB_H, fb); - vox_proj(vox, 45, 1, 200); - vox_view(vox, pos[0], pos[1], angle); + vox_proj(vox, 45, 1, 300); glfb_setup(FB_W, FB_H, GLFB_RGBA32, FB_W * 4); return 0; @@ -121,7 +120,7 @@ void update(void) pos[1] -= right[1]; } - vox_view(vox, pos[0], pos[1], angle); + vox_view(vox, pos[0], pos[1], -30, angle); } void display(void) diff --git a/src/voxscape.c b/src/voxscape.c index 0ea8f06..a23a851 100644 --- a/src/voxscape.c +++ b/src/voxscape.c @@ -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]) { diff --git a/src/voxscape.h b/src/voxscape.h index c0e386f..1bbb03a 100644 --- a/src/voxscape.h +++ b/src/voxscape.h @@ -9,8 +9,11 @@ struct voxscape *vox_create(int xsz, int ysz); struct voxscape *vox_open(const char *hfile, const char *cfile); void vox_free(struct voxscape *vox); +int vox_height(struct voxscape *vox, int32_t x, int32_t y); + void vox_framebuf(struct voxscape *vox, int xres, int yres, uint32_t *fb); -void vox_view(struct voxscape *vox, int32_t x, int32_t y, int32_t angle); +/* negative height for auto at -h above terrain */ +void vox_view(struct voxscape *vox, int32_t x, int32_t y, int h, int32_t angle); void vox_proj(struct voxscape *vox, int fov, int znear, int zfar); void vox_render(struct voxscape *vox); -- 1.7.10.4