This commit is contained in:
jacob 2024-08-29 15:44:15 -05:00
parent 2150d0e3c4
commit 7e125e864e
3 changed files with 24 additions and 8 deletions

View File

@ -757,20 +757,15 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
pen = epa(e0_poly, e1_poly, simplex);
if (colliding) {
#if 0
/* Pen movement test */
#if 1
{
struct xform xf = e1_xf;
//xf.og = v2_add(xf.og, v2_div(pen, 2));
xf.og = v2_add(xf.og, pen);
entity_set_xform(e1, xf);
e1->verlet_xform = xf;
//e1->verlet_xform.og = v2_add(e1->verlet_xform.og, pen);
}
#endif
break;
}
}

View File

@ -214,6 +214,7 @@ struct v2 epa(struct v2_array poly0, struct v2_array poly1, struct simplex simpl
}
/* Insert point into prototype array */
/* FIXME: Preserve winding order */
arena_push(scratch.arena, struct v2);
++proto_count;
for (u32 i = proto_count - 1; i > pen_pe_index; --i) {
@ -268,3 +269,22 @@ struct v2_array menkowski(struct arena *arena, struct v2_array poly0, struct v2_
return res;
#endif
}
/* Returns 1 if winding forward, -1 if backward */
i32 poly_get_winding_order(struct v2_array poly)
{
i32 res;
if (poly.count >= 3) {
struct v2 a = poly.points[0];
struct v2 b = poly.points[1];
struct v2 c = poly.points[2];
if (v2_wedge(v2_sub(b, a), v2_sub(c, b)) > 0) {
res = 1;
} else {
res = -1;
}
} else {
res = -1;
}
return res;
}

View File

@ -201,5 +201,6 @@ struct v2 normal_towards_point(struct v2 start, struct v2 end, struct v2 p);
struct gjk_result gjk(struct v2_array poly0, struct v2_array poly1);
struct v2 epa(struct v2_array poly0, struct v2_array poly1, struct simplex simplex);
struct v2_array menkowski(struct arena *arena, struct v2_array poly0, struct v2_array poly1);
i32 poly_get_winding_order(struct v2_array poly);
#endif