X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world_volumes.c;fp=world_volumes.c;h=c08fe43155de12533c5e106b8779f72a6bfc9895;hb=342fcbf6fda017bdd38d56ce0fa7c9e59e589f3b;hp=0000000000000000000000000000000000000000;hpb=63b5ac44f74599b21c4b9b18398c29b797337bea;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world_volumes.c b/world_volumes.c new file mode 100644 index 0000000..c08fe43 --- /dev/null +++ b/world_volumes.c @@ -0,0 +1,55 @@ +#ifndef WORLD_VOLUMES_C +#define WORLD_VOLUMES_C + +#include "world_volumes.h" + +/* + * BVH implementation + * ---------------------------------------------------------------------------- + */ + +VG_STATIC void volume_vg_expand_bound( void *user, boxf bound, u32 item_index ) +{ + world_instance *world = user; + + ent_volume *volume = mdl_arritm( &world->ent_volume, item_index ); + + m4x3_expand_aabb_point( volume->to_world, bound, (v3f){ 1.0f, 1.0f, 1.0f} ); + m4x3_expand_aabb_point( volume->to_world, bound, (v3f){ 1.0f, 1.0f,-1.0f} ); + m4x3_expand_aabb_point( volume->to_world, bound, (v3f){ 1.0f,-1.0f, 1.0f} ); + m4x3_expand_aabb_point( volume->to_world, bound, (v3f){ 1.0f,-1.0f,-1.0f} ); + m4x3_expand_aabb_point( volume->to_world, bound, (v3f){-1.0f, 1.0f, 1.0f} ); + m4x3_expand_aabb_point( volume->to_world, bound, (v3f){-1.0f, 1.0f,-1.0f} ); + m4x3_expand_aabb_point( volume->to_world, bound, (v3f){-1.0f,-1.0f, 1.0f} ); + m4x3_expand_aabb_point( volume->to_world, bound, (v3f){-1.0f,-1.0f,-1.0f} ); +} + +VG_STATIC float volume_vg_centroid( void *user, u32 item_index, int axis ) +{ + world_instance *world = user; + ent_volume *volume = mdl_arritm( &world->ent_volume, item_index ); + return volume->to_world[3][axis]; +} + +VG_STATIC void volume_vg_swap( void *user, u32 ia, u32 ib ) +{ + world_instance *world = user; + ent_volume *a = mdl_arritm( &world->ent_volume, ia ), + *b = mdl_arritm( &world->ent_volume, ib ), + temp; + + temp = *a; + *a = *b; + *b = temp; +} + +VG_STATIC void volume_vg_debug( void *user, u32 item_index ) +{ + world_instance *world = user; + ent_volume *volume = mdl_arritm( &world->ent_volume, item_index ); + vg_line_boxf_transformed( volume->to_world, (boxf){{-1.0f,-1.0f,-1.0f}, + { 1.0f, 1.0f, 1.0f}}, + 0xff00ff00 ); +} + +#endif /* WORLD_VOLUMES_H */