build system revision
[vg.git] / vg_rigidbody_collision.h
1 #pragma once
2
3 /* TODO: Get rid of this! */
4 #define VG_MAX_CONTACTS 256
5
6 typedef struct rb_ct rb_ct;
7 struct rb_ct
8 {
9 rigidbody *rba, *rbb;
10 v3f co, n;
11 v3f t[2];
12 float p, bias, norm_impulse, tangent_impulse[2],
13 normal_mass, tangent_mass[2];
14
15 u32 element_id;
16
17 enum contact_type type;
18 }
19 extern rb_contact_buffer[VG_MAX_CONTACTS];
20 extern int rb_contact_count;
21
22 int rb_capsule__sphere( m4x3f mtxA, rb_capsule *ca,
23 v3f coB, f32 rb, rb_ct *buf );
24 int rb_capsule__capsule( m4x3f mtxA, rb_capsule *ca,
25 m4x3f mtxB, rb_capsule *cb, rb_ct *buf );
26 int rb_capsule__box( m4x3f mtxA, rb_capsule *ca,
27 m4x3f mtxB, m4x3f mtxB_inverse, boxf box,
28 rb_ct *buf );
29 int rb_sphere__box( v3f coA, f32 ra,
30 m4x3f mtxB, m4x3f mtxB_inverse, boxf box,
31 rb_ct *buf );
32 int rb_sphere__sphere( v3f coA, f32 ra, v3f coB, f32 rb, rb_ct *buf );
33 int rb_sphere__triangle( m4x3f mtxA, f32 r, v3f tri[3], rb_ct *buf );
34 int rb_capsule__triangle( m4x3f mtxA, rb_capsule *c, v3f tri[3], rb_ct *buf );
35 int rb_global_has_space( void );
36 rb_ct *rb_global_buffer( void );
37 int rb_manifold_apply_filtered( rb_ct *man, int len );
38
39 int rb_box_triangle_sat( v3f extent, v3f center,
40 m4x3f to_local, v3f tri_src[3] );
41
42 /*
43 * Merge two contacts if they are within radius(r) of eachother
44 */
45 void rb_manifold_contact_weld( rb_ct *ci, rb_ct *cj, float r );
46 void rb_manifold_filter_joint_edges( rb_ct *man, int len, float r );
47
48 /*
49 * Resolve overlapping pairs
50 */
51 void rb_manifold_filter_pairs( rb_ct *man, int len, float r );
52
53 /*
54 * Remove contacts that are facing away from A
55 */
56 void rb_manifold_filter_backface( rb_ct *man, int len );
57
58 /*
59 * Filter out duplicate coplanar results. Good for spheres.
60 */
61 void rb_manifold_filter_coplanar( rb_ct *man, int len, float w );
62
63 void rb_debug_contact( rb_ct *ct );
64 void rb_solver_reset(void);
65 rb_ct *rb_global_ct(void);
66 void rb_prepare_contact( rb_ct *ct, f32 dt );
67 void rb_depenetrate( rb_ct *manifold, int len, v3f dt );
68 void rb_presolve_contacts( rb_ct *buffer, f32 dt, int len );
69 void rb_contact_restitution( rb_ct *ct, float cr );
70 void rb_solve_contacts( rb_ct *buf, int len );