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);
}
struct triangle *faces;
int num_faces;
- struct bvhnode *next;
- struct bvhnode *sub;
- int num_sub;
+ struct bvhnode *left, *right;
};
struct rayhit {
struct material *curmtl;
float color[4] = {0, 0, 0, 1};
+ if(!bn) return;
+
if(bn->faces) {
tri = bn->faces;
curmtl = tri->mtl;
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)
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;