X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=scene.h;fp=scene.h;h=cee7e699f6f570831ddaad9cca143095d1471706;hb=35b57a341eb37d863ec69e4f011a88b7bfba5c01;hp=83badb2fbca423444213dc3825af14e633bf25a3;hpb=8a31c1ffcb632b9b6d1702332f0d75d609c0a87b;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/scene.h b/scene.h index 83badb2..cee7e69 100644 --- a/scene.h +++ b/scene.h @@ -17,7 +17,8 @@ struct scene_vert v3f co; /* 3*32 */ v2f uv; /* 2*32 */ i8 norm[4]; /* 4*8 */ - u16 unused[4]; + u16 flags; /* only for the cpu. its junk on the gpu */ + u16 unused[3]; }; #pragma pack(pop) @@ -204,6 +205,12 @@ VG_STATIC void scene_copy_slice( scene_context *ctx, mdl_submesh *sm ) ctx->submesh.vertex_start = ctx->vertex_count; } +VG_STATIC void scene_set_vertex_flags( scene_context *ctx, + u32 start, u32 count, u16 flags ){ + for( u32 i=0; iarrvertices[ start + i ].flags = flags; +} + struct scene_upload_info{ scene_context *ctx; glmesh *mesh; @@ -364,6 +371,7 @@ VG_STATIC void scene_bh_debug( void *user, u32 item_index ) vg_line( pc->co, pa->co, 0xff0000ff ); } +#if 0 VG_STATIC int scene_bh_ray( void *user, u32 index, v3f co, v3f dir, ray_hit *hit ) { @@ -386,6 +394,7 @@ VG_STATIC int scene_bh_ray( void *user, u32 index, v3f co, return 0; } +#endif VG_STATIC void scene_bh_closest( void *user, u32 index, v3f point, v3f closest ) { @@ -406,18 +415,39 @@ VG_STATIC bh_system bh_system_scene = .item_closest = scene_bh_closest, .item_swap = scene_bh_swap, .item_debug = scene_bh_debug, - .cast_ray = scene_bh_ray }; /* * An extra step is added onto the end to calculate the hit normal */ VG_STATIC int scene_raycast( scene_context *s, bh_tree *bh, - v3f co, v3f dir, ray_hit *hit ) + v3f co, v3f dir, ray_hit *hit, u16 ignore ) { - int count = bh_ray( bh, co, dir, hit ); + hit->tri = NULL; + + bh_iter it; + bh_iter_init_ray( 0, &it, co, dir, hit->dist ); + i32 idx; + + while( bh_next( bh, &it, &idx ) ){ + u32 *tri = &s->arrindices[ idx*3 ]; + + if( s->arrvertices[tri[0]].flags & ignore ) continue; + + v3f vs[3]; + for( u32 i=0; i<3; i++ ) + v3_copy( s->arrvertices[tri[i]].co, vs[i] ); + + f32 t; + if( ray_tri( vs, co, dir, &t ) ){ + if( t < hit->dist ){ + hit->dist = t; + hit->tri = tri; + } + } + } - if( count ){ + if( hit->tri ){ v3f v0, v1; float *pa = s->arrvertices[hit->tri[0]].co, @@ -431,7 +461,7 @@ VG_STATIC int scene_raycast( scene_context *s, bh_tree *bh, v3_muladds( co, dir, hit->dist, hit->pos ); } - return count; + return hit->tri?1:0; } VG_STATIC bh_tree *scene_bh_create( void *lin_alloc, scene_context *s )