1 #ifndef WORLD_VOLUMES_C
2 #define WORLD_VOLUMES_C
4 #include "world_volumes.h"
6 static void world_volumes_update( world_instance
*world
, v3f pos
){
7 /* filter and check the existing ones */
9 for( u32 i
=0; i
<world_static
.active_trigger_volume_count
; i
++ ){
10 i32 idx
= world_static
.active_trigger_volumes
[i
];
11 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, idx
);
14 m4x3_mulv( volume
->to_local
, pos
, local
);
15 if( (fabsf(local
[0]) <= 1.0f
) &&
16 (fabsf(local
[1]) <= 1.0f
) &&
17 (fabsf(local
[2]) <= 1.0f
) )
19 world_static
.active_trigger_volumes
[ j
++ ] = idx
;
20 boxf cube
= {{-1.0f
,-1.0f
,-1.0f
},{1.0f
,1.0f
,1.0f
}};
21 vg_line_boxf_transformed( volume
->to_world
, cube
, 0xff00ccff );
22 /* triggr on stay ..... */
25 /* trigger on exit...... */
28 world_static
.active_trigger_volume_count
= j
;
30 static float random_accum
= 0.0f
;
31 random_accum
+= vg
.time_delta
;
35 while( random_accum
> 0.1f
){
41 boxf volume_proximity
;
42 v3_add( pos
, (v3f
){ radius
, radius
, radius
}, volume_proximity
[1] );
43 v3_sub( pos
, (v3f
){ radius
, radius
, radius
}, volume_proximity
[0] );
46 bh_iter_init_box( 0, &it
, volume_proximity
);
49 while( bh_next( world
->volume_bh
, &it
, &idx
) ){
50 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, idx
);
52 boxf cube
= {{-1.0f
,-1.0f
,-1.0f
},{1.0f
,1.0f
,1.0f
}};
54 if( volume
->type
== k_volume_subtype_trigger
){
55 for( u32 i
=0; i
<world_static
.active_trigger_volume_count
; i
++ )
56 if( world_static
.active_trigger_volumes
[i
] == idx
)
59 if( world_static
.active_trigger_volume_count
>
60 vg_list_size(world_static
.active_trigger_volumes
) ) continue;
63 m4x3_mulv( volume
->to_local
, pos
, local
);
65 if( (fabsf(local
[0]) <= 1.0f
) &&
66 (fabsf(local
[1]) <= 1.0f
) &&
67 (fabsf(local
[2]) <= 1.0f
) )
70 basecall
.function
= k_ent_function_trigger
;
71 basecall
.id
= mdl_entity_id( k_ent_volume
, idx
);
74 entity_call( world
, &basecall
);
75 world_static
.active_trigger_volumes
[
76 world_static
.active_trigger_volume_count
++ ] = idx
;
79 vg_line_boxf_transformed( volume
->to_world
, cube
, 0xffcccccc );
81 else if( volume
->type
== k_volume_subtype_particle
){
82 vg_line_boxf_transformed( volume
->to_world
, cube
, 0xff00c0ff );
84 for( int j
=0; j
<random_ticks
; j
++ ){
86 basecall
.id
= mdl_entity_id( k_ent_volume
, idx
);
89 entity_call( world
, &basecall
);
98 * ----------------------------------------------------------------------------
101 VG_STATIC
void volume_vg_expand_bound( void *user
, boxf bound
, u32 item_index
)
103 world_instance
*world
= user
;
105 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, item_index
);
107 m4x3_expand_aabb_point( volume
->to_world
, bound
, (v3f
){ 1.0f
, 1.0f
, 1.0f
} );
108 m4x3_expand_aabb_point( volume
->to_world
, bound
, (v3f
){ 1.0f
, 1.0f
,-1.0f
} );
109 m4x3_expand_aabb_point( volume
->to_world
, bound
, (v3f
){ 1.0f
,-1.0f
, 1.0f
} );
110 m4x3_expand_aabb_point( volume
->to_world
, bound
, (v3f
){ 1.0f
,-1.0f
,-1.0f
} );
111 m4x3_expand_aabb_point( volume
->to_world
, bound
, (v3f
){-1.0f
, 1.0f
, 1.0f
} );
112 m4x3_expand_aabb_point( volume
->to_world
, bound
, (v3f
){-1.0f
, 1.0f
,-1.0f
} );
113 m4x3_expand_aabb_point( volume
->to_world
, bound
, (v3f
){-1.0f
,-1.0f
, 1.0f
} );
114 m4x3_expand_aabb_point( volume
->to_world
, bound
, (v3f
){-1.0f
,-1.0f
,-1.0f
} );
117 VG_STATIC
float volume_vg_centroid( void *user
, u32 item_index
, int axis
)
119 world_instance
*world
= user
;
120 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, item_index
);
121 return volume
->to_world
[3][axis
];
124 VG_STATIC
void volume_vg_swap( void *user
, u32 ia
, u32 ib
)
126 world_instance
*world
= user
;
127 ent_volume
*a
= mdl_arritm( &world
->ent_volume
, ia
),
128 *b
= mdl_arritm( &world
->ent_volume
, ib
),
136 VG_STATIC
void volume_vg_debug( void *user
, u32 item_index
)
138 world_instance
*world
= user
;
139 ent_volume
*volume
= mdl_arritm( &world
->ent_volume
, item_index
);
140 vg_line_boxf_transformed( volume
->to_world
, (boxf
){{-1.0f
,-1.0f
,-1.0f
},
141 { 1.0f
, 1.0f
, 1.0f
}},
145 #endif /* WORLD_VOLUMES_H */