bricks
[carveJwlIkooP6JGAAIwe30JlM.git] / world_logic_bricks.h
index 2df236a6457b670fd4e520f0083488c34a592327..c4d5358db05980376588053230928b822d1df647 100644 (file)
@@ -492,4 +492,68 @@ VG_STATIC void logic_bricks_world_gen_allocate( world_instance *world )
    }
 }
 
+
+
+
+
+/*
+ * BVH implementation
+ * ----------------------------------------------------------------------------
+ */
+
+VG_STATIC void trigger_bh_expand_bound( void *user, boxf bound, u32 item_index )
+{
+   world_instance *world = user;
+   struct trigger_zone *trigger = &world->triggers[ item_index ];
+
+   m4x3_expand_aabb_point( trigger->transform, bound, (v3f){ 1.0f, 1.0f, 1.0f} );
+   m4x3_expand_aabb_point( trigger->transform, bound, (v3f){ 1.0f, 1.0f,-1.0f} );
+   m4x3_expand_aabb_point( trigger->transform, bound, (v3f){ 1.0f,-1.0f, 1.0f} );
+   m4x3_expand_aabb_point( trigger->transform, bound, (v3f){ 1.0f,-1.0f,-1.0f} );
+   m4x3_expand_aabb_point( trigger->transform, bound, (v3f){-1.0f, 1.0f, 1.0f} );
+   m4x3_expand_aabb_point( trigger->transform, bound, (v3f){-1.0f, 1.0f,-1.0f} );
+   m4x3_expand_aabb_point( trigger->transform, bound, (v3f){-1.0f,-1.0f, 1.0f} );
+   m4x3_expand_aabb_point( trigger->transform, bound, (v3f){-1.0f,-1.0f,-1.0f} );
+}
+
+VG_STATIC float trigger_bh_centroid( void *user, u32 item_index, int axis )
+{
+   world_instance *world = user;
+   struct trigger_zone *trigger = &world->triggers[ item_index ];
+
+   return trigger->transform[3][axis];
+}
+
+VG_STATIC void trigger_bh_swap( void *user, u32 ia, u32 ib )
+{
+   world_instance *world = user;
+   struct trigger_zone *a = &world->triggers[ ia ],
+                       *b = &world->triggers[ ib ],
+                       temp;
+
+   temp = *a;
+   *a = *b;
+   *b = temp;
+}
+
+VG_STATIC void trigger_bh_debug( void *user, u32 item_index )
+{
+   world_instance *world = user;
+   struct trigger_zone *zone = &world->triggers[ item_index ];
+
+   vg_line_boxf_transformed( zone->transform, (boxf){{-1.0f,-1.0f,-1.0f},
+                                                     { 1.0f, 1.0f, 1.0f}}, 
+                                                     0xff00ff00 );
+}
+
+VG_STATIC bh_system bh_system_triggers = 
+{
+   .expand_bound = trigger_bh_expand_bound,
+   .item_centroid = trigger_bh_centroid,
+   .item_closest = NULL,
+   .item_swap = trigger_bh_swap,
+   .item_debug = trigger_bh_debug,
+   .cast_ray = NULL
+};
+
 #endif /* WORLD_LOGIC_BRICKS_H */