2 #include "vg/vg_platform.h"
5 * Copyright (C) 2021-2024 Mt.ZERO Software - All Rights Reserved
7 * Rigidbody main file, related:
8 * vg_rigidbody_collision.h
9 * vg_rigidbody_constraints.h
12 #define k_friction 0.4f
13 #define k_damp_linear 0.1f /* scale velocity 1/(1+x) */
14 #define k_damp_angular 0.1f /* scale angular 1/(1+x) */
15 #define k_penetration_slop 0.01f
16 #define k_rb_inertia_scale 4.0f
17 #define k_phys_baumgarte 0.2f
18 #define k_gravity 9.6f
19 #define k_rb_density 8.0f
24 k_rb_shape_sphere
= 2,
25 k_rb_shape_capsule
= 3,
28 typedef struct rigidbody rigidbody
;
29 typedef struct rb_capsule rb_capsule
;
43 m3x3f iI
, iIw
; /* inertia model and inverse world tensor */
44 m4x3f to_world
, to_local
;
48 * Initialize rigidbody inverse mass and inertia tensor with some common shapes
50 void rb_setbody_capsule( rigidbody
*rb
, f32 r
, f32 h
,
51 f32 density
, f32 inertia_scale
);
52 void rb_setbody_box( rigidbody
*rb
, boxf box
, f32 density
, f32 inertia_scale
);
53 void rb_setbody_sphere( rigidbody
*rb
, f32 r
, f32 density
, f32 inertia_scale
);
56 * Update ALL matrices and tensors on rigidbody
58 void rb_update_matrices( rigidbody
*rb
);
61 * Extrapolate rigidbody into a transform based on vg accumulator.
62 * Useful for rendering
64 void rb_extrapolate( rigidbody
*rb
, v3f co
, v4f q
);
65 void rb_iter( rigidbody
*rb
);
66 void rb_solve_gyroscopic( rigidbody
*rb
, m3x3f I
, f32 h
);
69 * Creates relative contact velocity vector
71 void rb_rcv( rigidbody
*rba
, rigidbody
*rbb
, v3f ra
, v3f rb
, v3f rv
);
74 * Apply impulse to object
76 void rb_linear_impulse( rigidbody
*rb
, v3f delta
, v3f impulse
);
81 void rb_effect_simple_bouyency( rigidbody
*ra
, v4f plane
, f32 amt
, f32 drag
);
82 void rb_effect_spring_target_vector( rigidbody
*rba
, v3f ra
, v3f rt
,
83 f32 spring
, f32 dampening
, f32 timestep
);