@@ -5,7 +5,6 @@
#include <math.h>
#define GRAVITY -9.81f
-#define TIME_STEP (1.0 / 60.0)
#define MAX_BVH_DEPTH 20
typedef struct {
@@ -189,13 +188,13 @@ void asim_world_destroy() {
mesh.root = NULL;
}
-void asim_world_update() {
+void asim_world_update(float time_step) {
ppair.pos_a_x = 0;
ppair.pos_a_y = 0;
ppair.pos_a_z = 0;
const int sub_steps = 2;
- float dt = TIME_STEP / sub_steps;
+ float dt = time_step / sub_steps;
for (int i = 0; i < sub_steps; i++) {
sphere.velocity.z += GRAVITY * dt;
sphere.position = vec4_add(sphere.position, vec4_mult(sphere.velocity, dt));
@@ -12,7 +12,7 @@ typedef struct physics_pair {
void asim_world_create();
void asim_world_destroy();
-void asim_world_update();
+void asim_world_update(float time_step);
physics_pair_t *asim_world_get_contact();
void *asim_body_create(int shape, float mass, float dimx, float dimy, float dimz, float x, float y, float z, void *posa, void *inda, float scale_pos);
@@ -5,7 +5,7 @@
declare function asim_world_create(): void;
declare function asim_world_destroy(): void;
-declare function asim_world_update(): void;
+declare function asim_world_update(time_step: f32): void;
declare function asim_world_get_contact(): physics_pair_t;
declare type physics_pair_t = {
pos_a_x: f32;
@@ -27,7 +27,7 @@ function physics_world_create(): physics_world_t {
function physics_world_update(world: physics_world_t) {
- asim_world_update();
+ asim_world_update(sys_delta());
let keys: i32[] = imap_keys(physics_body_object_map);
for (let i: i32 = 0; i < keys.length; ++i) {