fix long standing grind bug
[carveJwlIkooP6JGAAIwe30JlM.git] / world_volumes.c
1 #ifndef WORLD_VOLUMES_C
2 #define WORLD_VOLUMES_C
3
4 #include "world_volumes.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 #endif /* WORLD_VOLUMES_H */