fix contact direction skip not updating

This commit is contained in:
jacob 2025-05-28 03:43:34 -05:00
parent 6926bdfa5a
commit 40a20439e5
3 changed files with 10 additions and 9 deletions

View File

@ -174,12 +174,14 @@ void phys_create_and_update_contacts(struct phys_step_ctx *ctx, f32 elapsed_dt,
struct v2 dir0 = e0->collision_dir;
struct v2 dir1 = e1->collision_dir;
f32 threshold = 0.5;
if (!v2_is_zero(dir0) && !constraint->skip_solve) {
constraint->skip_solve = v2_dot(dir0, normal) <= threshold;
b32 is_wrong_dir = false;
if (!v2_is_zero(dir0)) {
is_wrong_dir = v2_dot(dir0, normal) <= threshold;
}
if (!v2_is_zero(dir1) && !constraint->skip_solve) {
constraint->skip_solve = v2_dot(dir1, v2_neg(normal)) <= threshold;
if (!v2_is_zero(dir1) && !is_wrong_dir) {
is_wrong_dir = v2_dot(dir1, v2_neg(normal)) <= threshold;
}
constraint->wrong_dir = is_wrong_dir;
}
/* Run collision callback */
@ -396,7 +398,7 @@ void phys_warm_start_contacts(struct phys_step_ctx *ctx)
struct sim_ent *e0 = sim_ent_from_id(ss, constraint->e0);
struct sim_ent *e1 = sim_ent_from_id(ss, constraint->e1);
if (num_points > 0 && sim_ent_is_valid_and_active(e0) && sim_ent_is_valid_and_active(e1) && !constraint->skip_solve) {
if (num_points > 0 && sim_ent_is_valid_and_active(e0) && sim_ent_is_valid_and_active(e1) && !constraint->skip_solve && !constraint->wrong_dir) {
f32 inv_m0 = constraint->inv_m0;
f32 inv_m1 = constraint->inv_m1;
f32 inv_i0 = constraint->inv_i0;
@ -453,7 +455,7 @@ void phys_solve_contacts(struct phys_step_ctx *ctx, f32 dt, b32 apply_bias)
f32 w1 = e1->angular_velocity;
u32 num_points = constraint->num_points;
if (num_points > 0 && sim_ent_is_valid_and_active(e0) && sim_ent_is_valid_and_active(e1) && !constraint->skip_solve) {
if (num_points > 0 && sim_ent_is_valid_and_active(e0) && sim_ent_is_valid_and_active(e1) && !constraint->skip_solve && !constraint->wrong_dir) {
struct xform e0_xf = sim_ent_get_xform(e0);
struct xform e1_xf = sim_ent_get_xform(e1);

View File

@ -61,6 +61,7 @@ struct phys_contact_point {
struct phys_contact_constraint {
u64 last_phys_iteration; /* To avoid checking collisions for the same constraint twice in one tick */
b32 skip_solve;
b32 wrong_dir;
struct sim_ent_id e0;
struct sim_ent_id e1;
f32 inv_m0;

View File

@ -1422,13 +1422,12 @@ INTERNAL void user_update(void)
(UNUSED)e0;
(UNUSED)e1;
#if 1
#if DEVELOPER
/* Draw contact points */
{
f32 radius = 5;
for (u32 i = 0; i < data->num_points; ++i) {
u32 color = data->skip_solve ? ALPHA_F(COLOR_YELLOW, 0.3) : RGBA_F(0.8, 0.2, 0.2, 1);
u32 color = (data->skip_solve || data->wrong_dir) ? ALPHA_F(COLOR_YELLOW, 0.3) : RGBA_F(0.8, 0.2, 0.2, 1);
struct phys_contact_point point = data->points[i];
struct v2 dbg_pt = point.dbg_pt;
@ -1672,7 +1671,6 @@ INTERNAL void user_update(void)
}
#endif
}
#endif
#endif
/* Draw hierarchy */