+typedef struct bh_iter bh_iter;
+struct bh_iter
+{
+ struct
+ {
+ int id, depth;
+ }
+ stack[64];
+
+ int depth, i;
+};
+
+VG_STATIC void bh_iter_init( int root, bh_iter *it )
+{
+ it->stack[0].id = root;
+ it->stack[0].depth = 0;
+ it->depth = 0;
+ it->i = 0;
+}
+
+VG_STATIC int bh_next( bh_tree *bh, bh_iter *it, boxf box, int *em )
+{
+ while( it->depth >= 0 ){
+ bh_node *inode = &bh->nodes[ it->stack[it->depth].id ];
+
+ /* Only process overlapping nodes */
+ if( !box_overlap( inode->bbx, box ) ){
+ it->depth --;
+ continue;
+ }
+
+ if( inode->count ){
+ if( it->i < inode->count ){
+ *em = inode->start+it->i;
+ it->i ++;
+ return 1;
+ }
+ else{
+ it->depth --;
+ it->i = 0;
+ }
+ }
+ else{
+ if( it->depth+1 >= vg_list_size(it->stack) ){
+ vg_error( "Maximum stack reached!\n" );
+ return 0;
+ }
+
+ it->stack[it->depth ].id = inode->il;
+ it->stack[it->depth+1].id = inode->ir;
+ it->depth ++;
+ it->i = 0;
+ }
+ }
+
+ return 0;
+}
+
+VG_STATIC int bh_closest_point( bh_tree *bh, v3f pos,
+ v3f closest, float max_dist )