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