From d2894c1a2380cee76476d63e4800188dcbc121f8 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Mon, 21 Jun 2021 23:07:12 +0300 Subject: [PATCH] fixed missing last tile, and changed bvh node to binary --- src/geom.c | 9 ++------- src/geom.h | 4 +--- src/level.c | 9 ++++----- src/rt.c | 4 ++-- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/geom.c b/src/geom.c index 3751286..ef15156 100644 --- a/src/geom.c +++ b/src/geom.c @@ -7,13 +7,8 @@ void free_bvh_tree(struct bvhnode *tree) free(tree->faces); - node = tree->sub; - while(node) { - tmp = node; - node = node->next; - free_bvh_tree(tmp); - } - + free_bvh_tree(tree->left); + free_bvh_tree(tree->right); free(tree); } diff --git a/src/geom.h b/src/geom.h index 50784a4..7f71094 100644 --- a/src/geom.h +++ b/src/geom.h @@ -26,9 +26,7 @@ struct bvhnode { struct triangle *faces; int num_faces; - struct bvhnode *next; - struct bvhnode *sub; - int num_sub; + struct bvhnode *left, *right; }; struct rayhit { diff --git a/src/level.c b/src/level.c index fcdc405..21a82f9 100644 --- a/src/level.c +++ b/src/level.c @@ -119,6 +119,8 @@ static void draw_level_rec(struct bvhnode *bn) struct material *curmtl; float color[4] = {0, 0, 0, 1}; + if(!bn) return; + if(bn->faces) { tri = bn->faces; curmtl = tri->mtl; @@ -145,11 +147,8 @@ static void draw_level_rec(struct bvhnode *bn) glEnd(); } - bn = bn->sub; - while(bn) { - draw_level_rec(bn); - bn = bn->next; - } + draw_level_rec(bn->left); + draw_level_rec(bn->right); } void draw_level(struct level *lvl) diff --git a/src/rt.c b/src/rt.c index 18b7f17..020c51f 100644 --- a/src/rt.c +++ b/src/rt.c @@ -33,8 +33,8 @@ int fbsize(int width, int height) if(!(fbptr = malloc(width * height * sizeof *fb.pixels))) { return -1; } - xtiles = width / TILESZ; - ytiles = height / TILESZ; + xtiles = (width + TILESZ - 1) / TILESZ; + ytiles = (height + TILESZ - 1) / TILESZ; if(!(tileptr = malloc(xtiles * ytiles * sizeof *tiles))) { free(fbptr); return -1; -- 1.7.10.4