From d3edea9c3e01a429a6ac0eb4e6a6a725731e269b Mon Sep 17 00:00:00 2001 From: luboslenco Date: Mon, 11 May 2026 20:25:36 +0200 Subject: [PATCH] asim: expose friction and bounciness --- base/sources/libs/asim.c | 14 +++++++++++--- base/sources/libs/asim.h | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/base/sources/libs/asim.c b/base/sources/libs/asim.c index 75e5d875..0354ab4d 100644 --- a/base/sources/libs/asim.c +++ b/base/sources/libs/asim.c @@ -47,6 +47,8 @@ static physics_pair_t ppairs[MAX_SPHERES]; static float ppair_best_dist; static mesh_t mesh; static aabb_t root_bounds = {{-10, -10, -10}, {10, 10, 10}}; +static float asim_bounciness = 0.0f; +static float asim_friction = 0.01f; static inline aabb_t merge_aabbs(aabb_t a, aabb_t b) { return (aabb_t){.min = {fminf(a.min.x, b.min.x), fminf(a.min.y, b.min.y), fminf(a.min.z, b.min.z)}, @@ -122,9 +124,7 @@ static void collide_sphere_triangle(sphere_t *s, int si, triangle_t *t) { if (v_dot_n < 0.0f) { vec4_t n_vel = vec4_mult(t->normal, v_dot_n); vec4_t t_vel = vec4_sub(s->velocity, n_vel); - float restitution = 0.0f; - float friction = 0.99f; - s->velocity = vec4_add(vec4_mult(n_vel, -restitution), vec4_mult(t_vel, friction)); + s->velocity = vec4_add(vec4_mult(n_vel, -asim_bounciness), vec4_mult(t_vel, 1.0f - asim_friction)); } vec4_t contact_point = vec4_sub(s->position, vec4_mult(t->normal, s->radius)); @@ -336,3 +336,11 @@ float asim_body_get_speed(void *body) { return sqrtf(spheres[slot].velocity.x * spheres[slot].velocity.x + spheres[slot].velocity.y * spheres[slot].velocity.y + spheres[slot].velocity.z * spheres[slot].velocity.z); } + +void asim_set_friction(float v) { + asim_friction = v * 0.1f; +} + +void asim_set_bounciness(float v) { + asim_bounciness = v; +} diff --git a/base/sources/libs/asim.h b/base/sources/libs/asim.h index 8260b975..390b8b5d 100644 --- a/base/sources/libs/asim.h +++ b/base/sources/libs/asim.h @@ -24,3 +24,5 @@ void asim_body_get_rot(void *body, quat_t *rot); void asim_body_sync_transform(void *body, vec4_t pos, quat_t rot); void asim_body_remove(void *body); float asim_body_get_speed(void *body); +void asim_set_friction(float v); +void asim_set_bounciness(float v);