review: rigidbody.h
[carveJwlIkooP6JGAAIwe30JlM.git] / world_volumes.c
index c08fe43155de12533c5e106b8779f72a6bfc9895..0cc1ed608929b03aaf094afd49ff4e4cba7cb5ac 100644 (file)
@@ -3,6 +3,96 @@
 
 #include "world_volumes.h"
 
+static void world_volumes_update( world_instance *world, v3f pos ){
+   /* filter and check the existing ones */
+   u32 j=0;
+   for( u32 i=0; i<world_static.active_trigger_volume_count; i++ ){
+      i32 idx = world_static.active_trigger_volumes[i];
+      ent_volume *volume = mdl_arritm( &world->ent_volume, idx );
+
+      v3f local;
+      m4x3_mulv( volume->to_local, pos, local );
+      if( (fabsf(local[0]) <= 1.0f) &&
+          (fabsf(local[1]) <= 1.0f) &&
+          (fabsf(local[2]) <= 1.0f) )
+      {
+         world_static.active_trigger_volumes[ j ++ ] = idx;
+         boxf cube = {{-1.0f,-1.0f,-1.0f},{1.0f,1.0f,1.0f}};
+         vg_line_boxf_transformed( volume->to_world, cube, 0xff00ccff );
+         /* triggr on stay ..... */
+      }
+      else{
+         /* trigger on exit...... */
+      }
+   }
+   world_static.active_trigger_volume_count = j;
+
+   static float random_accum = 0.0f;
+   random_accum += vg.time_delta;
+
+   u32 random_ticks = 0;
+
+   while( random_accum > 0.1f ){
+      random_accum -= 0.1f;
+      random_ticks ++;
+   }
+
+   float radius = 25.0f;
+   boxf volume_proximity;
+   v3_add( pos, (v3f){ radius, radius, radius }, volume_proximity[1] );
+   v3_sub( pos, (v3f){ radius, radius, radius }, volume_proximity[0] );
+
+   bh_iter it;
+   bh_iter_init_box( 0, &it, volume_proximity );
+   i32 idx;
+
+   while( bh_next( world->volume_bh, &it, &idx ) ){
+      ent_volume *volume = mdl_arritm( &world->ent_volume, idx );
+
+      boxf cube = {{-1.0f,-1.0f,-1.0f},{1.0f,1.0f,1.0f}};
+      
+      if( volume->type == k_volume_subtype_trigger ){
+         for( u32 i=0; i<world_static.active_trigger_volume_count; i++ )
+            if( world_static.active_trigger_volumes[i] == idx )
+               goto next_volume;
+
+         if( world_static.active_trigger_volume_count > 
+               vg_list_size(world_static.active_trigger_volumes) ) continue;
+
+         v3f local;
+         m4x3_mulv( volume->to_local, pos, local );
+
+         if( (fabsf(local[0]) <= 1.0f) &&
+             (fabsf(local[1]) <= 1.0f) &&
+             (fabsf(local[2]) <= 1.0f) )
+         {
+            ent_call basecall;
+            basecall.function = k_ent_function_trigger;
+            basecall.id = mdl_entity_id( k_ent_volume, idx );
+            basecall.data = NULL;
+
+            entity_call( world, &basecall );
+            world_static.active_trigger_volumes[ 
+               world_static.active_trigger_volume_count ++ ] = idx;
+         }
+         else
+            vg_line_boxf_transformed( volume->to_world, cube, 0xffcccccc );
+      }
+      else if( volume->type == k_volume_subtype_particle ){
+         vg_line_boxf_transformed( volume->to_world, cube, 0xff00c0ff );
+
+         for( int j=0; j<random_ticks; j++ ){
+            ent_call basecall;
+            basecall.id = mdl_entity_id( k_ent_volume, idx );
+            basecall.data = NULL;
+
+            entity_call( world, &basecall );
+         }
+      }
+next_volume:;
+   }
+}
+
 /*
  * BVH implementation
  * ----------------------------------------------------------------------------