minor tweaking
This commit is contained in:
parent
8f1422a882
commit
55fc39fddd
@ -493,21 +493,6 @@ struct collider_collision_points_result collider_collision_points(struct collide
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (radius0 > 0.0) {
|
|
||||||
struct v2 scale = xform_get_scale(xf0);
|
|
||||||
struct v2 normal_radius = v2_mul_v2(v2_mul(normal, radius0), scale);
|
|
||||||
a0 = v2_add(a0, normal_radius);
|
|
||||||
b0 = v2_add(b0, normal_radius);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (radius1 > 0.0) {
|
|
||||||
struct v2 scale = xform_get_scale(xf1);
|
|
||||||
struct v2 normal_radius = v2_mul_v2(v2_mul(normal, radius1), scale);
|
|
||||||
a1 = v2_sub(a1, normal_radius);
|
|
||||||
b1 = v2_sub(b1, normal_radius);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (radius0 > 0.0) {
|
if (radius0 > 0.0) {
|
||||||
struct v2 radius_dir = v2_rotated(normal, -xform_get_rotation(xf0));
|
struct v2 radius_dir = v2_rotated(normal, -xform_get_rotation(xf0));
|
||||||
radius_dir = v2_mul_v2(radius_dir, xform_get_scale(xf0));
|
radius_dir = v2_mul_v2(radius_dir, xform_get_scale(xf0));
|
||||||
@ -525,7 +510,6 @@ struct collider_collision_points_result collider_collision_points(struct collide
|
|||||||
a1 = v2_sub(a1, radius_dir);
|
a1 = v2_sub(a1, radius_dir);
|
||||||
b1 = v2_sub(b1, radius_dir);
|
b1 = v2_sub(b1, radius_dir);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
f32 a0t = 0;
|
f32 a0t = 0;
|
||||||
f32 a1t = 0;
|
f32 a1t = 0;
|
||||||
@ -574,65 +558,6 @@ struct collider_collision_points_result collider_collision_points(struct collide
|
|||||||
f32 va0a1_wedge_normal = v2_wedge(va0a1, normal);
|
f32 va0a1_wedge_normal = v2_wedge(va0a1, normal);
|
||||||
f32 vb0b1_wedge_normal = v2_wedge(vb0b1, normal);
|
f32 vb0b1_wedge_normal = v2_wedge(vb0b1, normal);
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (math_fabs(vab0_wedge_normal) > 0.1f) {
|
|
||||||
f32 w = 1 / vab0_wedge_normal;
|
|
||||||
a0t = clamp_f32(va0a1_wedge_normal * w, 0, 1);
|
|
||||||
b0t = clamp_f32(vb0b1_wedge_normal * -w, 0, 1);
|
|
||||||
} else {
|
|
||||||
DEBUGBREAKABLE;
|
|
||||||
if (v2_dot(b0, normal) >= v2_dot(a0, normal)) {
|
|
||||||
a0t = 1;
|
|
||||||
b0t = 0;
|
|
||||||
} else {
|
|
||||||
a0t = 0;
|
|
||||||
b0t = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (math_fabs(vab1_wedge_normal) > 0.1f) {
|
|
||||||
f32 w = 1 / vab1_wedge_normal;
|
|
||||||
a1t = clamp_f32(-va0a1_wedge_normal * w, 0, 1);
|
|
||||||
b1t = clamp_f32(-vb0b1_wedge_normal * -w, 0, 1);
|
|
||||||
} else {
|
|
||||||
if (v2_dot(b1, normal) < v2_dot(a1, normal)) {
|
|
||||||
a1t = 1;
|
|
||||||
b1t = 0;
|
|
||||||
} else {
|
|
||||||
a1t = 0;
|
|
||||||
b1t = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#elif 0
|
|
||||||
if (math_fabs(vab0_wedge_normal) > 0.01f) {
|
|
||||||
f32 w = 1 / vab0_wedge_normal;
|
|
||||||
a0t = clamp_f32(va0a1_wedge_normal * w, 0, 1);
|
|
||||||
b0t = clamp_f32(vb0b1_wedge_normal * -w, 0, 1);
|
|
||||||
} else {
|
|
||||||
if (v2_dot(b0, normal) >= v2_dot(a0, normal)) {
|
|
||||||
a0t = 1;
|
|
||||||
b0t = 0;
|
|
||||||
} else {
|
|
||||||
a0t = 0;
|
|
||||||
b0t = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (math_fabs(vab1_wedge_normal) > 0.01f) {
|
|
||||||
f32 w = 1 / vab1_wedge_normal;
|
|
||||||
a1t = clamp_f32(-va0a1_wedge_normal * w, 0, 1);
|
|
||||||
b1t = clamp_f32(-vb0b1_wedge_normal * -w, 0, 1);
|
|
||||||
} else {
|
|
||||||
if (v2_dot(b1, normal) < v2_dot(a1, normal)) {
|
|
||||||
a1t = 1;
|
|
||||||
b1t = 0;
|
|
||||||
} else {
|
|
||||||
a1t = 0;
|
|
||||||
b1t = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (!collapse0) {
|
if (!collapse0) {
|
||||||
f32 w = 1 / vab0_wedge_normal;
|
f32 w = 1 / vab0_wedge_normal;
|
||||||
a0t = clamp_f32(va0a1_wedge_normal * w, 0, 1);
|
a0t = clamp_f32(va0a1_wedge_normal * w, 0, 1);
|
||||||
@ -644,7 +569,6 @@ struct collider_collision_points_result collider_collision_points(struct collide
|
|||||||
a1t = clamp_f32(-va0a1_wedge_normal * w, 0, 1);
|
a1t = clamp_f32(-va0a1_wedge_normal * w, 0, 1);
|
||||||
b1t = clamp_f32(-vb0b1_wedge_normal * -w, 0, 1);
|
b1t = clamp_f32(-vb0b1_wedge_normal * -w, 0, 1);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct v2 a0_clipped = v2_add(a0, v2_mul(vab0, a0t));
|
struct v2 a0_clipped = v2_add(a0, v2_mul(vab0, a0t));
|
||||||
|
|||||||
@ -36,10 +36,10 @@
|
|||||||
#define GAME_PHYSICS_ENABLE_WARM_STARTING 1
|
#define GAME_PHYSICS_ENABLE_WARM_STARTING 1
|
||||||
#define GAME_PHYSICS_ENABLE_RELAXATION 1
|
#define GAME_PHYSICS_ENABLE_RELAXATION 1
|
||||||
|
|
||||||
#define USER_DRAW_MENKOWSKI 0
|
#define USER_DRAW_MENKOWSKI 1
|
||||||
#define GAME_PHYSICS_ENABLE_GROUND_FRICTION 0
|
#define GAME_PHYSICS_ENABLE_GROUND_FRICTION 1
|
||||||
#define GAME_PHYSICS_ENABLE_COLLISION 1
|
#define GAME_PHYSICS_ENABLE_COLLISION 1
|
||||||
#define GAME_SPAWN_LOTS 1
|
#define GAME_SPAWN_LOTS 0
|
||||||
#define GAME_SPAWN_TESTENT 0
|
#define GAME_SPAWN_TESTENT 0
|
||||||
#define GAME_SPAWN_BOX 1
|
#define GAME_SPAWN_BOX 1
|
||||||
#define GAME_PLAYER_AIM 0
|
#define GAME_PLAYER_AIM 0
|
||||||
@ -52,7 +52,7 @@
|
|||||||
* E.g: At 1.5, the user thread will render 75ms back in time (if game thread runs at 50FPS)
|
* E.g: At 1.5, the user thread will render 75ms back in time (if game thread runs at 50FPS)
|
||||||
*/
|
*/
|
||||||
#define USER_INTERP_OFFSET_TICK_RATIO 1.1
|
#define USER_INTERP_OFFSET_TICK_RATIO 1.1
|
||||||
#define USER_INTERP_ENABLED 0
|
#define USER_INTERP_ENABLED 1
|
||||||
|
|
||||||
#define COLLIDER_DEBUG RTC
|
#define COLLIDER_DEBUG RTC
|
||||||
|
|
||||||
|
|||||||
71
src/game.c
71
src/game.c
@ -153,13 +153,13 @@ INTERNAL void spawn_test_entities(f32 offset)
|
|||||||
//struct v2 size = V2(0.5, 0.25);
|
//struct v2 size = V2(0.5, 0.25);
|
||||||
//struct v2 size = V2(1.0, 1.0);
|
//struct v2 size = V2(1.0, 1.0);
|
||||||
//struct v2 size = V2(1.5, 1.5);
|
//struct v2 size = V2(1.5, 1.5);
|
||||||
//f32 r = PI;
|
f32 r = PI;
|
||||||
//f32 r = PI / 4;
|
//f32 r = PI / 4;
|
||||||
//f32 r = PI / 3;
|
//f32 r = PI / 3;
|
||||||
//f32 r = 0.05;
|
//f32 r = 0.05;
|
||||||
//f32 r = PI / 2;
|
//f32 r = PI / 2;
|
||||||
//f32 r = PI;
|
//f32 r = PI;
|
||||||
f32 r = 0;
|
//f32 r = 0;
|
||||||
|
|
||||||
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
|
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
|
||||||
#else
|
#else
|
||||||
@ -169,16 +169,17 @@ INTERNAL void spawn_test_entities(f32 offset)
|
|||||||
entity_set_xform(e, xf);
|
entity_set_xform(e, xf);
|
||||||
|
|
||||||
//e->sprite = sprite_tag_from_path(STR("res/graphics/tim.ase"));
|
//e->sprite = sprite_tag_from_path(STR("res/graphics/tim.ase"));
|
||||||
e->sprite = sprite_tag_from_path(STR("res/graphics/box_rounded.ase"));
|
e->sprite = sprite_tag_from_path(STR("res/graphics/box.ase"));
|
||||||
|
//e->sprite = sprite_tag_from_path(STR("res/graphics/box_rounded.ase"));
|
||||||
//e->sprite_span_name = STR("idle.unarmed");
|
//e->sprite_span_name = STR("idle.unarmed");
|
||||||
//e->sprite_span_name = STR("idle.one_handed");
|
//e->sprite_span_name = STR("idle.one_handed");
|
||||||
e->sprite_span_name = STR("idle.two_handed");
|
e->sprite_span_name = STR("idle.two_handed");
|
||||||
e->sprite_tint = RGBA_32_F(1, 1, 1, 0.25);
|
|
||||||
|
|
||||||
entity_enable_prop(e, ENTITY_PROP_PLAYER_CONTROLLED);
|
entity_enable_prop(e, ENTITY_PROP_PLAYER_CONTROLLED);
|
||||||
#if GAME_PHYSICS_ENABLE_GROUND_FRICTION
|
#if GAME_PHYSICS_ENABLE_GROUND_FRICTION
|
||||||
//e->control_force = 4500;
|
//e->control_force = 4500;
|
||||||
e->control_force = 1200;
|
e->control_force = 1200;
|
||||||
|
//e->control_force = 250;
|
||||||
#else
|
#else
|
||||||
//e->control_force = 5000;
|
//e->control_force = 5000;
|
||||||
e->control_force = 250;
|
e->control_force = 250;
|
||||||
@ -187,13 +188,13 @@ INTERNAL void spawn_test_entities(f32 offset)
|
|||||||
e->control.focus = V2(0, -1);
|
e->control.focus = V2(0, -1);
|
||||||
|
|
||||||
entity_enable_prop(e, ENTITY_PROP_PHYSICAL);
|
entity_enable_prop(e, ENTITY_PROP_PHYSICAL);
|
||||||
e->mass_unscaled = 100;
|
e->mass_unscaled = 50;
|
||||||
//e->inertia_unscaled = F32_INFINITY;
|
//e->inertia_unscaled = F32_INFINITY;
|
||||||
e->inertia_unscaled = 25;
|
e->inertia_unscaled = 25;
|
||||||
e->linear_ground_friction = 1000;
|
e->linear_ground_friction = 200;
|
||||||
e->angular_ground_friction = 100;
|
e->angular_ground_friction = 100;
|
||||||
|
|
||||||
entity_enable_prop(e, ENTITY_PROP_TEST);
|
//entity_enable_prop(e, ENTITY_PROP_TEST);
|
||||||
|
|
||||||
player_ent = e;
|
player_ent = e;
|
||||||
}
|
}
|
||||||
@ -288,8 +289,8 @@ INTERNAL void spawn_test_entities(f32 offset)
|
|||||||
struct v2 size = V2(1, 1);
|
struct v2 size = V2(1, 1);
|
||||||
#else
|
#else
|
||||||
//struct v2 size = V2(5000, 1);
|
//struct v2 size = V2(5000, 1);
|
||||||
struct v2 size = V2(50, 1);
|
//struct v2 size = V2(50, 1);
|
||||||
//struct v2 size = V2(1, 1);
|
struct v2 size = V2(1, 1);
|
||||||
#endif
|
#endif
|
||||||
//f32 rot = PI / 4;
|
//f32 rot = PI / 4;
|
||||||
f32 rot = 0;
|
f32 rot = 0;
|
||||||
@ -547,7 +548,6 @@ INTERNAL void create_contact_manifolds(void)
|
|||||||
f32 vcp0_wedge = v2_wedge(vcp0, normal);
|
f32 vcp0_wedge = v2_wedge(vcp0, normal);
|
||||||
f32 vcp1_wedge = v2_wedge(vcp1, normal);
|
f32 vcp1_wedge = v2_wedge(vcp1, normal);
|
||||||
f32 k = (inv_m0 + inv_m1) + (inv_i0 * vcp0_wedge * vcp0_wedge) + (inv_i1 * vcp1_wedge * vcp1_wedge);
|
f32 k = (inv_m0 + inv_m1) + (inv_i0 * vcp0_wedge * vcp0_wedge) + (inv_i1 * vcp1_wedge * vcp1_wedge);
|
||||||
//f32 k = ((inv_m0 + inv_m1) + (inv_i0 * vcp0_wedge * vcp0_wedge) + (inv_i1 * vcp1_wedge * vcp1_wedge)) * manifold->num_contacts;
|
|
||||||
contact->inv_normal_mass = k > 0.0f ? 1.0f / k : 0.0f;
|
contact->inv_normal_mass = k > 0.0f ? 1.0f / k : 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,7 +556,6 @@ INTERNAL void create_contact_manifolds(void)
|
|||||||
f32 vcp0_wedge = v2_wedge(vcp0, tangent);
|
f32 vcp0_wedge = v2_wedge(vcp0, tangent);
|
||||||
f32 vcp1_wedge = v2_wedge(vcp1, tangent);
|
f32 vcp1_wedge = v2_wedge(vcp1, tangent);
|
||||||
f32 k = (inv_m0 + inv_m1) + (inv_i0 * vcp0_wedge * vcp0_wedge) + (inv_i1 * vcp1_wedge * vcp1_wedge);
|
f32 k = (inv_m0 + inv_m1) + (inv_i0 * vcp0_wedge * vcp0_wedge) + (inv_i1 * vcp1_wedge * vcp1_wedge);
|
||||||
//f32 k = ((inv_m0 + inv_m1) + (inv_i0 * vcp0_wedge * vcp0_wedge) + (inv_i1 * vcp1_wedge * vcp1_wedge)) * manifold->num_contacts;
|
|
||||||
contact->inv_tangent_mass = k > 0.0f ? 1.0f / k : 0.0f;
|
contact->inv_tangent_mass = k > 0.0f ? 1.0f / k : 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -705,8 +704,8 @@ INTERNAL void solve_collisions(f32 dt, b32 apply_bias)
|
|||||||
f32 mass_scale = 1.0f;
|
f32 mass_scale = 1.0f;
|
||||||
f32 impulse_scale = 0.0f;
|
f32 impulse_scale = 0.0f;
|
||||||
|
|
||||||
#if 1
|
|
||||||
if (separation > 0.0f) {
|
if (separation > 0.0f) {
|
||||||
|
/* Speculative */
|
||||||
velocity_bias = separation / dt;
|
velocity_bias = separation / dt;
|
||||||
} else if (apply_bias) {
|
} else if (apply_bias) {
|
||||||
/* Soft constraint */
|
/* Soft constraint */
|
||||||
@ -722,27 +721,6 @@ INTERNAL void solve_collisions(f32 dt, b32 apply_bias)
|
|||||||
mass_scale = softness.mass_scale;
|
mass_scale = softness.mass_scale;
|
||||||
impulse_scale = softness.impulse_scale;
|
impulse_scale = softness.impulse_scale;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
/* Only apply speculative if applying bias */
|
|
||||||
if (apply_bias) {
|
|
||||||
if (separation > 0.0f) {
|
|
||||||
velocity_bias = separation / dt;
|
|
||||||
} else {
|
|
||||||
/* Soft constraint */
|
|
||||||
|
|
||||||
f32 contact_damping_ratio = 10.0f;
|
|
||||||
f32 contact_hertz = (GAME_FPS * GAME_PHYSICS_SUBSTEPS) / 8.f;
|
|
||||||
|
|
||||||
struct soft_result softness = make_soft(contact_hertz, contact_damping_ratio, dt);
|
|
||||||
|
|
||||||
f32 contact_pushout_velocity = 3.0f;
|
|
||||||
velocity_bias = max_f32(softness.bias_rate * separation, -contact_pushout_velocity);
|
|
||||||
|
|
||||||
mass_scale = softness.mass_scale;
|
|
||||||
impulse_scale = softness.impulse_scale;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct v2 vel0 = v2_add(v0, v2_perp_mul(vcp0, w0));
|
struct v2 vel0 = v2_add(v0, v2_perp_mul(vcp0, w0));
|
||||||
struct v2 vel1 = v2_add(v1, v2_perp_mul(vcp1, w1));
|
struct v2 vel1 = v2_add(v1, v2_perp_mul(vcp1, w1));
|
||||||
@ -1089,7 +1067,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);
|
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)));
|
ent->local_collider = collider_from_quad(xform_mul_quad(cxf, quad_from_rect(slice.rect)));
|
||||||
|
|
||||||
#if 1
|
#if 0
|
||||||
if (entity_has_prop(ent, ENTITY_PROP_TEST)) {
|
if (entity_has_prop(ent, ENTITY_PROP_TEST)) {
|
||||||
//if ((true)) {
|
//if ((true)) {
|
||||||
#if 1
|
#if 1
|
||||||
@ -1508,12 +1486,12 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
|
|||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
#if GAME_PHYSICS_ENABLE_GROUND_FRICTION
|
#if GAME_PHYSICS_ENABLE_GROUND_FRICTION
|
||||||
|
#if 0
|
||||||
/* TODO: Do this globally rather than creating entities for constant forces */
|
/* TODO: Do this globally rather than creating entities for constant forces */
|
||||||
for (u64 entity_index = 0; entity_index < store->reserved; ++entity_index) {
|
for (u64 entity_index = 0; entity_index < store->reserved; ++entity_index) {
|
||||||
struct entity *ent = &store->entities[entity_index];
|
struct entity *ent = &store->entities[entity_index];
|
||||||
if (!entity_is_valid_and_active(ent)) continue;
|
if (!entity_is_valid_and_active(ent)) continue;
|
||||||
if (!entity_has_prop(ent, ENTITY_PROP_PHYSICAL)) continue;
|
if (!entity_has_prop(ent, ENTITY_PROP_PHYSICAL)) continue;
|
||||||
#if 1
|
|
||||||
if (ent->linear_ground_friction != 0) {
|
if (ent->linear_ground_friction != 0) {
|
||||||
/* Linear velocity */
|
/* Linear velocity */
|
||||||
{
|
{
|
||||||
@ -1556,13 +1534,24 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
/* TODO: Remove this (gravity test) */
|
|
||||||
struct xform xf = entity_get_xform(ent);
|
|
||||||
f32 mass = ent->mass_unscaled * math_fabs(xform_get_determinant(xf));
|
|
||||||
entity_apply_force_to_center(ent, V2(0, 9.81 * mass));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
/* TODO: Do this globally rather than creating entities for constant forces */
|
||||||
|
for (u64 entity_index = 0; entity_index < store->reserved; ++entity_index) {
|
||||||
|
struct entity *ent = &store->entities[entity_index];
|
||||||
|
if (!entity_is_valid_and_active(ent)) continue;
|
||||||
|
if (!entity_has_prop(ent, ENTITY_PROP_PHYSICAL)) continue;
|
||||||
|
|
||||||
|
|
||||||
|
const f32 bla = 0.75f;
|
||||||
|
if (ent->linear_ground_friction != 0) {
|
||||||
|
ent->linear_velocity = v2_mul(ent->linear_velocity, bla);
|
||||||
|
}
|
||||||
|
if (ent->angular_ground_friction != 0) {
|
||||||
|
ent->angular_velocity *= bla;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
|
|||||||
@ -868,8 +868,8 @@ INTERNAL void user_update(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Draw sprite */
|
/* Draw sprite */
|
||||||
if ((false)) {
|
//if ((false)) {
|
||||||
//if (!sprite_tag_is_nil(sprite)) {
|
if (!sprite_tag_is_nil(sprite)) {
|
||||||
/* Calculate sprite xform */
|
/* Calculate sprite xform */
|
||||||
sprite_xform = xform_mul(xf, ent->sprite_local_xform);
|
sprite_xform = xform_mul(xf, ent->sprite_local_xform);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user