use v2_winding when clipping
This commit is contained in:
parent
55fc39fddd
commit
ed8b03941e
@ -326,8 +326,9 @@ struct collider_collision_points_result collider_collision_points(struct collide
|
||||
b32 valid = true;
|
||||
|
||||
{
|
||||
const f32 validity_epsilon = min_unique_pt_dist_sq; /* Arbitrary */
|
||||
//const f32 validity_epsilon = 0.000000001f; /* Arbitrary */
|
||||
/* NOTE: Changing this value affects how stable normals are for circular colliders */
|
||||
//const f32 validity_epsilon = min_unique_pt_dist_sq; /* Arbitrary */
|
||||
const f32 validity_epsilon = 0.0000000001f; /* Arbitrary */
|
||||
|
||||
struct v2 vam = v2_sub(m, closest_a);
|
||||
struct v2 vbm = v2_sub(closest_b, closest_a);
|
||||
@ -420,24 +421,9 @@ struct collider_collision_points_result collider_collision_points(struct collide
|
||||
struct v2 vap = v2_sub(p, a);
|
||||
struct v2 vpb = v2_sub(b, p);
|
||||
|
||||
#if 1
|
||||
/* Swap a & b depending on winding order */
|
||||
if (v2_wedge(vap, vpb) < 0) {
|
||||
u32 tmp_u32 = a_i;
|
||||
a_i = b_i;
|
||||
b_i = tmp_u32;
|
||||
struct v2 tmp_v2 = a;
|
||||
a = b;
|
||||
b = tmp_v2;
|
||||
tmp_v2 = vap;
|
||||
vap = v2_neg(vpb);
|
||||
vpb = v2_neg(tmp_v2);
|
||||
}
|
||||
#endif
|
||||
|
||||
f32 vap_wedge = v2_wedge(vap, normal);
|
||||
f32 vpb_wedge = v2_wedge(vpb, normal);
|
||||
if (vap_wedge < (vpb_wedge + wedge_epsilon)) {
|
||||
if (vap_wedge * v2_winding(vap, vpb) < (vpb_wedge + wedge_epsilon)) {
|
||||
id_a0 = a_i;
|
||||
id_b0 = p_i;
|
||||
a0 = a;
|
||||
@ -463,24 +449,9 @@ struct collider_collision_points_result collider_collision_points(struct collide
|
||||
struct v2 vap = v2_sub(p, a);
|
||||
struct v2 vpb = v2_sub(b, p);
|
||||
|
||||
#if 1
|
||||
/* Swap a & b depending on winding order */
|
||||
if (v2_wedge(vap, vpb) > 0) {
|
||||
u32 tmp_u32 = a_i;
|
||||
a_i = b_i;
|
||||
b_i = tmp_u32;
|
||||
struct v2 tmp_v2 = a;
|
||||
a = b;
|
||||
b = tmp_v2;
|
||||
tmp_v2 = vap;
|
||||
vap = v2_neg(vpb);
|
||||
vpb = v2_neg(tmp_v2);
|
||||
}
|
||||
#endif
|
||||
|
||||
f32 vap_wedge = v2_wedge(vap, normal);
|
||||
f32 vpb_wedge = v2_wedge(vpb, normal);
|
||||
if (vap_wedge < (vpb_wedge + wedge_epsilon)) {
|
||||
if (vap_wedge * -v2_winding(vap, vpb) < (vpb_wedge + wedge_epsilon)) {
|
||||
id_a1 = a_i;
|
||||
id_b1 = p_i;
|
||||
a1 = a;
|
||||
|
||||
@ -36,8 +36,8 @@
|
||||
#define GAME_PHYSICS_ENABLE_WARM_STARTING 1
|
||||
#define GAME_PHYSICS_ENABLE_RELAXATION 1
|
||||
|
||||
#define USER_DRAW_MENKOWSKI 1
|
||||
#define GAME_PHYSICS_ENABLE_GROUND_FRICTION 1
|
||||
#define USER_DRAW_MENKOWSKI 0
|
||||
#define GAME_PHYSICS_ENABLE_GROUND_FRICTION 0
|
||||
#define GAME_PHYSICS_ENABLE_COLLISION 1
|
||||
#define GAME_SPAWN_LOTS 0
|
||||
#define GAME_SPAWN_TESTENT 0
|
||||
|
||||
35
src/game.c
35
src/game.c
@ -178,8 +178,8 @@ INTERNAL void spawn_test_entities(f32 offset)
|
||||
entity_enable_prop(e, ENTITY_PROP_PLAYER_CONTROLLED);
|
||||
#if GAME_PHYSICS_ENABLE_GROUND_FRICTION
|
||||
//e->control_force = 4500;
|
||||
e->control_force = 1200;
|
||||
//e->control_force = 250;
|
||||
//e->control_force = 1200;
|
||||
e->control_force = 250;
|
||||
#else
|
||||
//e->control_force = 5000;
|
||||
e->control_force = 250;
|
||||
@ -351,7 +351,7 @@ INTERNAL void spawn_test_entities(f32 offset)
|
||||
|
||||
|
||||
|
||||
INTERNAL void create_contact_manifolds(void)
|
||||
INTERNAL void generate_contacts(void)
|
||||
{
|
||||
/* TODO: Remove this */
|
||||
static u64 manifold_iteration = 0;
|
||||
@ -638,11 +638,7 @@ INTERNAL void warm_start_contacts(void)
|
||||
|
||||
|
||||
|
||||
struct soft_result {
|
||||
f32 bias_rate;
|
||||
f32 mass_scale;
|
||||
f32 impulse_scale;
|
||||
};
|
||||
struct soft_result { f32 bias_rate; f32 mass_scale; f32 impulse_scale; };
|
||||
INTERNAL struct soft_result make_soft(f32 hertz, f32 zeta, f32 h)
|
||||
{
|
||||
if (hertz == 0.0f) {
|
||||
@ -660,14 +656,7 @@ INTERNAL struct soft_result make_soft(f32 hertz, f32 zeta, f32 h)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
INTERNAL void solve_collisions(f32 dt, b32 apply_bias)
|
||||
INTERNAL void solve_contacts(f32 dt, b32 apply_bias)
|
||||
{
|
||||
struct entity_store *store = G.tick.entity_store;
|
||||
for (u64 entity_index = 0; entity_index < store->reserved; ++entity_index) {
|
||||
@ -1067,7 +1056,7 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
|
||||
struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, STR("shape"), ent->animation_frame);
|
||||
ent->local_collider = collider_from_quad(xform_mul_quad(cxf, quad_from_rect(slice.rect)));
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
if (entity_has_prop(ent, ENTITY_PROP_TEST)) {
|
||||
//if ((true)) {
|
||||
#if 1
|
||||
@ -1559,29 +1548,27 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
|
||||
* ========================== */
|
||||
|
||||
|
||||
(UNUSED)create_contact_manifolds;
|
||||
(UNUSED)solve_collisions;
|
||||
(UNUSED)generate_contacts;
|
||||
(UNUSED)solve_contacts;
|
||||
(UNUSED)integrate_velocities_from_forces;
|
||||
(UNUSED)integrate_positions_from_velocities;
|
||||
(UNUSED)warm_start_contacts;
|
||||
#if 1
|
||||
{
|
||||
integrate_velocities_from_forces(dt);
|
||||
create_contact_manifolds();
|
||||
generate_contacts();
|
||||
|
||||
f32 substep_dt = dt / GAME_PHYSICS_SUBSTEPS;
|
||||
for (u32 i = 0; i < GAME_PHYSICS_SUBSTEPS; ++i) {
|
||||
#if GAME_PHYSICS_ENABLE_WARM_STARTING
|
||||
warm_start_contacts();
|
||||
#else
|
||||
(UNUSED)warm_start_contacts;
|
||||
#endif
|
||||
#if GAME_PHYSICS_ENABLE_COLLISION
|
||||
solve_collisions(substep_dt, true);
|
||||
solve_contacts(substep_dt, true);
|
||||
#endif
|
||||
integrate_positions_from_velocities(substep_dt);
|
||||
#if GAME_PHYSICS_ENABLE_COLLISION && GAME_PHYSICS_ENABLE_RELAXATION
|
||||
solve_collisions(substep_dt, false); /* Relaxation */
|
||||
solve_contacts(substep_dt, false); /* Relaxation */
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -890,7 +890,6 @@ INTERNAL void user_update(void)
|
||||
/* Debug draw entity info */
|
||||
if (G.debug_draw && !skip_debug_draw) {
|
||||
struct temp_arena temp = arena_temp_begin(scratch.arena);
|
||||
|
||||
#if 0
|
||||
struct font *disp_font = font_load_async(STR("res/fonts/fixedsys.ttf"), 12.0f);
|
||||
if (disp_font) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user