create contacts but skip solve based on wall direction
This commit is contained in:
parent
8aa9f1402b
commit
6926bdfa5a
30
src/phys.c
30
src/phys.c
@ -95,22 +95,8 @@ void phys_create_and_update_contacts(struct phys_step_ctx *ctx, f32 elapsed_dt,
|
||||
CT_ASSERT(ARRAY_COUNT(constraint_ent->contact_constraint_data.points) == 2);
|
||||
CT_ASSERT(ARRAY_COUNT(collider_res.points) == 2);
|
||||
|
||||
b32 create_constraint = collider_res.num_points > 0;
|
||||
if (create_constraint) {
|
||||
struct v2 normal = collider_res.normal;
|
||||
struct v2 dir0 = e0->collision_dir;
|
||||
struct v2 dir1 = e1->collision_dir;
|
||||
f32 threshold = 0.5;
|
||||
if (create_constraint && !v2_is_zero(dir0)) {
|
||||
create_constraint = v2_dot(dir0, normal) > threshold;
|
||||
}
|
||||
if (create_constraint && !v2_is_zero(dir1)) {
|
||||
create_constraint = v2_dot(dir1, v2_neg(normal)) > threshold;
|
||||
}
|
||||
}
|
||||
|
||||
struct phys_contact_constraint *constraint = NULL;
|
||||
if (create_constraint) {
|
||||
if (collider_res.num_points > 0) {
|
||||
b32 is_start = false;
|
||||
if (!constraint_ent->valid) {
|
||||
is_start = true;
|
||||
@ -182,6 +168,20 @@ void phys_create_and_update_contacts(struct phys_step_ctx *ctx, f32 elapsed_dt,
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Skip solve based on collision direction */
|
||||
{
|
||||
struct v2 normal = collider_res.normal;
|
||||
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;
|
||||
}
|
||||
if (!v2_is_zero(dir1) && !constraint->skip_solve) {
|
||||
constraint->skip_solve = v2_dot(dir1, v2_neg(normal)) <= threshold;
|
||||
}
|
||||
}
|
||||
|
||||
/* Run collision callback */
|
||||
if (collision_callback) {
|
||||
struct phys_collision_data data = ZI;
|
||||
|
||||
@ -1428,18 +1428,17 @@ INTERNAL void user_update(void)
|
||||
{
|
||||
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);
|
||||
struct phys_contact_point point = data->points[i];
|
||||
struct v2 dbg_pt = point.dbg_pt;
|
||||
|
||||
/* Draw point */
|
||||
{
|
||||
u32 color = ALPHA_F(COLOR_YELLOW, 0.50);
|
||||
draw_circle(G.user_gpu_cmd_store, xform_mul_v2(G.world_to_user_xf, dbg_pt), radius, color, 10);
|
||||
}
|
||||
|
||||
/* Draw normal */
|
||||
{
|
||||
u32 color = COLOR_WHITE;
|
||||
f32 len = 0.1f;
|
||||
f32 arrow_thickness = 2;
|
||||
f32 arrow_height = 5;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user