entities zones
[carveJwlIkooP6JGAAIwe30JlM.git] / world_volumes.h
1 #ifndef WORLD_VOLUMES_H
2 #define WORLD_VOLUMES_H
3
4 #include "world.h"
5
6 /*
7 * BVH implementation
8 * ----------------------------------------------------------------------------
9 */
10
11 VG_STATIC void volume_vg_expand_bound( void *user, boxf bound, u32 item_index )
12 {
13 world_instance *world = user;
14
15 ent_volume *volume = mdl_arritm( &world->ent_volume, item_index );
16
17 m4x3_expand_aabb_point( volume->to_world, bound, (v3f){ 1.0f, 1.0f, 1.0f} );
18 m4x3_expand_aabb_point( volume->to_world, bound, (v3f){ 1.0f, 1.0f,-1.0f} );
19 m4x3_expand_aabb_point( volume->to_world, bound, (v3f){ 1.0f,-1.0f, 1.0f} );
20 m4x3_expand_aabb_point( volume->to_world, bound, (v3f){ 1.0f,-1.0f,-1.0f} );
21 m4x3_expand_aabb_point( volume->to_world, bound, (v3f){-1.0f, 1.0f, 1.0f} );
22 m4x3_expand_aabb_point( volume->to_world, bound, (v3f){-1.0f, 1.0f,-1.0f} );
23 m4x3_expand_aabb_point( volume->to_world, bound, (v3f){-1.0f,-1.0f, 1.0f} );
24 m4x3_expand_aabb_point( volume->to_world, bound, (v3f){-1.0f,-1.0f,-1.0f} );
25 }
26
27 VG_STATIC float volume_vg_centroid( void *user, u32 item_index, int axis )
28 {
29 world_instance *world = user;
30 ent_volume *volume = mdl_arritm( &world->ent_volume, item_index );
31 return volume->to_world[3][axis];
32 }
33
34 VG_STATIC void volume_vg_swap( void *user, u32 ia, u32 ib )
35 {
36 world_instance *world = user;
37 ent_volume *a = mdl_arritm( &world->ent_volume, ia ),
38 *b = mdl_arritm( &world->ent_volume, ib ),
39 temp;
40
41 temp = *a;
42 *a = *b;
43 *b = temp;
44 }
45
46 VG_STATIC void volume_vg_debug( void *user, u32 item_index )
47 {
48 world_instance *world = user;
49 ent_volume *volume = mdl_arritm( &world->ent_volume, item_index );
50 vg_line_boxf_transformed( volume->to_world, (boxf){{-1.0f,-1.0f,-1.0f},
51 { 1.0f, 1.0f, 1.0f}},
52 0xff00ff00 );
53 }
54
55 VG_STATIC bh_system bh_system_volumes =
56 {
57 .expand_bound = volume_vg_expand_bound,
58 .item_centroid = volume_vg_centroid,
59 .item_closest = NULL,
60 .item_swap = volume_vg_swap,
61 .item_debug = volume_vg_debug,
62 .cast_ray = NULL
63 };
64
65 #endif /* WORLD_VOLUMES_H */