rb_solver_reset();
for( int i=0; i<rd->part_count; i ++ )
- rb_collide( &rd->parts[i].rb, &world->rb_geo );
+ {
+ if( rb_global_has_space() )
+ {
+ rb_ct *buf = rb_global_buffer();
+
+ int l = rb_capsule__scene( rd->parts[i].rb.to_world,
+ &rd->parts[i].rb.inf.capsule,
+ NULL, &world->rb_geo.inf.scene, buf );
+
+ for( int j=0; j<l; j++ )
+ {
+ buf[j].rba = &rd->parts[i].rb;
+ buf[j].rbb = &world->rb_geo;
+ }
+
+ rb_contact_count += l;
+ }
+ }
/*
* COLLISION DETECTION
for( int j=i+1; j<rd->part_count; j ++ )
{
if( rd->parts[j].parent != i )
- rb_collide( &rd->parts[i].rb, &rd->parts[j].rb );
+ {
+ if( rb_global_has_space() )
+ {
+ rb_ct *buf = rb_global_buffer();
+
+ int l = rb_capsule__capsule( rd->parts[i].rb.to_world,
+ &rd->parts[i].rb.inf.capsule,
+ rd->parts[j].rb.to_world,
+ &rd->parts[j].rb.inf.capsule,
+ buf );
+
+ for( int k=0; k<l; k++ )
+ {
+ buf[k].rba = &rd->parts[i].rb;
+ buf[k].rbb = &rd->parts[j].rb;
+ }
+
+ rb_contact_count += l;
+ }
+ }
}
}
* Extrapolate rigidbody into a transform based on vg accumulator.
* Useful for rendering
*/
+#if 0
__attribute__ ((deprecated))
VG_STATIC void rb_extrapolate_transform( rigidbody *rb, m4x3f transform )
{
q_m3x3( q, transform );
v3_copy( co, transform[3] );
}
+#endif
VG_STATIC void rb_extrapolate( rigidbody *rb, v3f co, v4f q )
{
manifold->t1 = -INFINITY;
}
+#if 0
__attribute__ ((deprecated))
VG_STATIC int rb_capsule_manifold_done( rigidbody *rba, rigidbody *rbb,
capsule_manifold *manifold, rb_ct *buf )
return count;
}
+#endif
VG_STATIC int rb_capsule__manifold_done( m4x3f mtx, rb_capsule *c,
capsule_manifold *manifold,
return 0;
}
-VG_STATIC int rb_capsule_capsule( rigidbody *rba, rigidbody *rbb, rb_ct *buf )
+VG_STATIC int rb_capsule__capsule( m4x3f mtxA, rb_capsule *ca,
+ m4x3f mtxB, rb_capsule *cb, rb_ct *buf )
{
- if( !box_overlap( rba->bbx_world, rbb->bbx_world ) )
- return 0;
-
- float ha = rba->inf.capsule.height,
- hb = rbb->inf.capsule.height,
- ra = rba->inf.capsule.radius,
- rb = rbb->inf.capsule.radius,
+ float ha = ca->height,
+ hb = cb->height,
+ ra = ca->radius,
+ rb = cb->radius,
r = ra+rb;
v3f p0, p1, p2, p3;
- v3_muladds( rba->co, rba->up, -ha*0.5f+ra, p0 );
- v3_muladds( rba->co, rba->up, ha*0.5f-ra, p1 );
- v3_muladds( rbb->co, rbb->up, -hb*0.5f+rb, p2 );
- v3_muladds( rbb->co, rbb->up, hb*0.5f-rb, p3 );
+ v3_muladds( mtxA[3], mtxA[1], -ha*0.5f+ra, p0 );
+ v3_muladds( mtxA[3], mtxA[1], ha*0.5f-ra, p1 );
+ v3_muladds( mtxB[3], mtxB[1], -hb*0.5f+rb, p2 );
+ v3_muladds( mtxB[3], mtxB[1], hb*0.5f-rb, p3 );
capsule_manifold manifold;
rb_capsule_manifold_init( &manifold );
rb_capsule_manifold( p0, pa, 0.0f, r, &manifold );
rb_capsule_manifold( p1, pb, 1.0f, r, &manifold );
- return rb_capsule_manifold_done( rba, rbb, &manifold, buf );
+ return rb_capsule__manifold_done( mtxA, ca, &manifold, buf );
}
+#if 0
/*
* Generates up to two contacts; optimised for the most stable manifold
*/
return rb_capsule_manifold_done( rba, rbb, &manifold, buf );
}
+#endif
VG_STATIC int rb_sphere_box( rigidbody *rba, rigidbody *rbb, rb_ct *buf )
{
//#define RIGIDBODY_DYNAMIC_MESH_EDGES
+#if 0
__attribute__ ((deprecated))
VG_STATIC int rb_sphere_triangle( rigidbody *rba, rigidbody *rbb,
v3f tri[3], rb_ct *buf )
return 0;
}
+#endif
VG_STATIC int rb_sphere__triangle( m4x3f mtxA, rb_sphere *b,
v3f tri[3], rb_ct *buf )
return count;
}
+#if 0
__attribute__ ((deprecated))
VG_STATIC int rb_sphere_scene( rigidbody *rba, rigidbody *rbb, rb_ct *buf )
{
return count;
}
+#endif
VG_STATIC int rb_box_scene( rigidbody *rba, rigidbody *rbb, rb_ct *buf )
{
/*
* Generates up to two contacts; optimised for the most stable manifold
*/
+#if 0
__attribute__ ((deprecated))
VG_STATIC int rb_capsule_triangle( rigidbody *rba, rigidbody *rbb,
v3f tri[3], rb_ct *buf )
return count;
}
+#endif
/* mtxB is defined only for tradition; it is not used currently */
VG_STATIC int rb_capsule__scene( m4x3f mtxA, rb_capsule *c,
return count;
}
+#if 0
__attribute__ ((deprecated))
VG_STATIC int rb_capsule_scene( rigidbody *rba, rigidbody *rbb, rb_ct *buf )
{
{
return rb_capsule_scene( rbb, rba, buf );
}
+#endif
VG_STATIC int RB_MATRIX_ERROR( rigidbody *rba, rigidbody *rbb, rb_ct *buf )
{
return rb_capsule_sphere( rbb, rba, buf );
}
+#if 0
VG_STATIC int rb_box_capsule( rigidbody *rba, rigidbody *rbb, rb_ct *buf )
{
return rb_capsule_box( rbb, rba, buf );
}
+#endif
VG_STATIC int rb_box_sphere( rigidbody *rba, rigidbody *rbb, rb_ct *buf )
{
return rb_box_scene( rbb, rba, buf );
}
+#if 0
VG_STATIC int (*rb_jump_table[4][4])( rigidbody *a, rigidbody *b, rb_ct *buf ) =
{
/* box */ /* Sphere */ /* Capsule */ /* Mesh */
else
return 0;
}
+#endif
+
+VG_STATIC int rb_global_has_space( void )
+{
+ if( rb_contact_count + 16 > vg_list_size(rb_contact_buffer) )
+ return 0;
+
+ return 1;
+}
+
+VG_STATIC rb_ct *rb_global_buffer( void )
+{
+ return &rb_contact_buffer[ rb_contact_count ];
+}
/*
* -----------------------------------------------------------------------------