-static int rb_sphere_vs_capsule( rigidbody *rba, rigidbody *rbb, rb_ct *buf )
-{
- return rb_capsule_vs_sphere( rbb, rba, buf );
-}
-
-static int rb_box_vs_capsule( rigidbody *rba, rigidbody *rbb, rb_ct *buf )
-{
- return rb_capsule_vs_box( rbb, rba, buf );
-}
-
-static int rb_box_vs_sphere( rigidbody *rba, rigidbody *rbb, rb_ct *buf )
-{
- return rb_sphere_vs_box( rbb, rba, buf );
-}
-
-static int rb_scene_vs_box( rigidbody *rba, rigidbody *rbb, rb_ct *buf )
-{
- return rb_box_vs_scene( rbb, rba, buf );
-}
-
-static int (*rb_jump_table[4][4])( rigidbody *rba, rigidbody *rbb, rb_ct *buf )=
-{ /* box */ /* Sphere */ /* Capsule */ /* Mesh */
-/*box */ { RB_MATRIX_ERROR, rb_box_vs_sphere, rb_box_vs_capsule, rb_box_vs_scene },
-/*sphere */ { rb_sphere_vs_box, rb_sphere_vs_sphere, rb_sphere_vs_capsule, rb_sphere_vs_scene },
-/*capsule*/ { rb_capsule_vs_box,rb_capsule_vs_sphere,rb_capsule_vs_capsule,RB_MATRIX_ERROR },
-/*mesh */ { rb_scene_vs_box, RB_MATRIX_ERROR, RB_MATRIX_ERROR, RB_MATRIX_ERROR }
-};
-
-static int rb_collide( rigidbody *rba, rigidbody *rbb )
-{
- int (*collider_jump)(rigidbody *rba, rigidbody *rbb, rb_ct *buf )
- = rb_jump_table[rba->type][rbb->type];
-
- /*
- * 12 is the maximum manifold size we can generate, so we are forced to abort
- * potentially checking any more.
- */
- if( rb_contact_count + 12 > vg_list_size(rb_contact_buffer) )
- {
- vg_warn( "Too many contacts made in global collider buffer (%d of %d\n)",
- rb_contact_count, vg_list_size(rb_contact_buffer) );
- return 0;
- }
-
- /*
- * TODO: Replace this with a more dedicated broad phase pass
- */
- if( box_overlap( rba->bbx_world, rbb->bbx_world ) )
- {
- int count = collider_jump( rba, rbb, rb_contact_buffer+rb_contact_count);
- rb_contact_count += count;
- return count;
- }
- else
- return 0;
-}
-
-/*
- * Generic functions
- */
-
-#ifdef RB_DEPR
-/*
- * This function does not accept triangle as a dynamic object, it is assumed
- * to always be static.
- *
- * The triangle is also assumed to be one sided for better detection
- */
-static int rb_sphere_vs_triangle( rigidbody *rba, v3f tri[3], rb_ct *buf )
-{
- v3f delta, co;
-
- closest_on_triangle( rba->co, tri, co );
- v3_sub( rba->co, co, delta );
-
- float d2 = v3_length2( delta ),
- r = rba->inf.sphere.radius;
-
- if( d2 < r*r )
- {
- v3f ab, ac, tn;
- v3_sub( tri[1], tri[0], ab );
- v3_sub( tri[2], tri[0], ac );
- v3_cross( ac, ab, tn );
-
- if( v3_dot( delta, tn ) > 0.0f )
- v3_muls( delta, -1.0f, delta );
-
- float d = sqrtf(d2);
-
- rb_ct *ct = buf;
- v3_muls( delta, 1.0f/d, ct->n );
- v3_copy( co, ct->co );
- ct->p = r-d;
- ct->rba = rba;
- ct->rbb = &rb_static_null;
- return 1;
- }
-
- return 0;
-}
-
-static int sphere_vs_triangle( v3f c, float r, v3f tri[3],
- v3f co, v3f norm, float *p )
-{
- v3f delta;
- closest_on_triangle( c, tri, co );
-
- v3_sub( c, co, delta );
-
-
- float d = v3_length2( delta );
- if( d < r*r )
- {
- v3f ab, ac, tn;
- v3_sub( tri[1], tri[0], ab );
- v3_sub( tri[2], tri[0], ac );
- v3_cross( ac, ab, tn );
-
- if( v3_dot( delta, tn ) > 0.0f )
- v3_muls( delta, -1.0f, delta );
-
- vg_line_pt3( co, 0.05f, 0xff00ff00 );
-
- d = sqrtf(d);
- v3_muls( delta, 1.0f/d, norm );
-
- *p = r-d;
- return 1;
- }
-
- return 0;
-}
-
-#include "world.h"
-#endif
-
-static void rb_solver_reset(void)
-{
- rb_contact_count = 0;
-}
-
-static rb_ct *rb_global_ct(void)
-{
- return rb_contact_buffer + rb_contact_count;
-}
-
-#ifdef RB_DEPR
-static struct contact *rb_start_contact(void)