projects
/
carveJwlIkooP6JGAAIwe30JlM.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rework scene format
[carveJwlIkooP6JGAAIwe30JlM.git]
/
bvh.h
diff --git
a/bvh.h
b/bvh.h
index c841939d0cab9d40f7c0741bc637eac5711d8314..27e23b5af516dd0fc8ae809b7c6844400741cf7d 100644
(file)
--- a/
bvh.h
+++ b/
bvh.h
@@
-13,7
+13,9
@@
* user: a pointer back the base of the data you are ordering
* system: the system we created above which will deal with the data
*
* user: a pointer back the base of the data you are ordering
* system: the system we created above which will deal with the data
*
- * call bh_create( bh_tree *bh, u32 item_count, u32 item_size )
+ * call bh_create( bh_tree *bh, u32 item_count )
+ * static int bh_ray( bh_tree *bh, u32 inode, v3f co, v3f dir, ray_hit *hit )
+ * static int bh_select( bh_tree *bh, boxf box, u32 *buffer, int len )
*/
typedef struct bh_node bh_node;
*/
typedef struct bh_node bh_node;
@@
-43,7
+45,6
@@
struct bh_system
void (*expand_bound)( void *user, boxf bound, u32 item_index );
float (*item_centroid)( void *user, u32 item_index, int axis );
void (*item_swap)( void *user, u32 ia, u32 ib );
void (*expand_bound)( void *user, boxf bound, u32 item_index );
float (*item_centroid)( void *user, u32 item_index, int axis );
void (*item_swap)( void *user, u32 ia, u32 ib );
- u32 item_size;
/*
* Optional:
/*
* Optional:
@@
-53,7
+54,7
@@
struct bh_system
*/
void (*item_debug)( void *user, u32 item_index );
*/
void (*item_debug)( void *user, u32 item_index );
- int (*cast_ray)( void *user, v3f co, v3f dir, ray_hit *hit );
+ int (*cast_ray)( void *user,
u32 index,
v3f co, v3f dir, ray_hit *hit );
};
static void bh_update_bounds( bh_tree *bh, u32 inode )
};
static void bh_update_bounds( bh_tree *bh, u32 inode )
@@
-130,10
+131,11
@@
static void bh_subdivide( bh_tree *bh, u32 inode )
bh_subdivide( bh, ir );
}
bh_subdivide( bh, ir );
}
-static void bh_create( bh_tree *bh, bh_system *sys, u32 item_count )
+static void bh_create( bh_tree *bh, bh_system *sys,
void *user,
u32 item_count )
{
bh->system = sys;
{
bh->system = sys;
- bh->nodes = malloc( sys->item_size * (item_count*2-1) );
+ bh->user = user;
+ bh->nodes = malloc( sizeof(bh_node) * (item_count*2-1) );
bh_node *root = &bh->nodes[0];
bh->node_count = 1;
bh_node *root = &bh->nodes[0];
bh->node_count = 1;
@@
-146,7
+148,7
@@
static void bh_create( bh_tree *bh, bh_system *sys, u32 item_count )
bh_update_bounds( bh, 0 );
bh_subdivide( bh, 0 );
bh_update_bounds( bh, 0 );
bh_subdivide( bh, 0 );
- bh->nodes = realloc( bh->nodes, s
ys->item_size
* bh->node_count );
+ bh->nodes = realloc( bh->nodes, s
izeof(bh_node)
* bh->node_count );
vg_success( "BVH done, size: %u/%u\n", bh->node_count, (item_count*2-1) );
}
vg_success( "BVH done, size: %u/%u\n", bh->node_count, (item_count*2-1) );
}
@@
-202,7
+204,7
@@
static int bh_ray( bh_tree *bh, u32 inode, v3f co, v3f dir, ray_hit *hit )
u32 idx = inode->start+i;
if( bh->system->cast_ray )
u32 idx = inode->start+i;
if( bh->system->cast_ray )
- count += bh->system->cast_ray( bh->user, co, dir, hit );
+ count += bh->system->cast_ray( bh->user,
idx,
co, dir, hit );
else
count ++;
}
else
count ++;
}
@@
-249,10
+251,7
@@
static int bh_select( bh_tree *bh, boxf box, u32 *buffer, int len )
if( inode->count )
{
if( count + inode->count >= len )
if( inode->count )
{
if( count + inode->count >= len )
- {
- vg_error( "Maximum buffer reached!\n" );
return count;
return count;
- }
for( u32 i=0; i<inode->count; i++ )
buffer[ count ++ ] = inode->start+i;
for( u32 i=0; i<inode->count; i++ )
buffer[ count ++ ] = inode->start+i;