store & calculate friction
This commit is contained in:
parent
c966924760
commit
8eadda9931
@ -16,6 +16,7 @@ READONLY struct entity _g_entity_nil = {
|
|||||||
.local_xform = XFORM_IDENT_NOCAST,
|
.local_xform = XFORM_IDENT_NOCAST,
|
||||||
.cached_global_xform = XFORM_IDENT_NOCAST,
|
.cached_global_xform = XFORM_IDENT_NOCAST,
|
||||||
.cached_global_xform_dirty = false,
|
.cached_global_xform_dirty = false,
|
||||||
|
.friction = 0.5f,
|
||||||
.mass_unscaled = 1,
|
.mass_unscaled = 1,
|
||||||
.inertia_unscaled = 1,
|
.inertia_unscaled = 1,
|
||||||
.sprite_local_xform = XFORM_IDENT_NOCAST,
|
.sprite_local_xform = XFORM_IDENT_NOCAST,
|
||||||
@ -27,6 +28,7 @@ GLOBAL READONLY struct entity g_entity_default = {
|
|||||||
.local_xform = XFORM_IDENT_NOCAST,
|
.local_xform = XFORM_IDENT_NOCAST,
|
||||||
.cached_global_xform = XFORM_IDENT_NOCAST,
|
.cached_global_xform = XFORM_IDENT_NOCAST,
|
||||||
.cached_global_xform_dirty = true,
|
.cached_global_xform_dirty = true,
|
||||||
|
.friction = 0.5f,
|
||||||
.mass_unscaled = 1,
|
.mass_unscaled = 1,
|
||||||
.inertia_unscaled = 1,
|
.inertia_unscaled = 1,
|
||||||
.sprite_local_xform = XFORM_IDENT_NOCAST,
|
.sprite_local_xform = XFORM_IDENT_NOCAST,
|
||||||
|
|||||||
@ -91,6 +91,8 @@ struct contact_constraint {
|
|||||||
struct contact_point points[2];
|
struct contact_point points[2];
|
||||||
u32 num_points;
|
u32 num_points;
|
||||||
|
|
||||||
|
f32 friction;
|
||||||
|
|
||||||
struct math_spring_result softness;
|
struct math_spring_result softness;
|
||||||
f32 pushout_velocity;
|
f32 pushout_velocity;
|
||||||
|
|
||||||
@ -275,8 +277,13 @@ struct entity {
|
|||||||
|
|
||||||
/* ENTITY_PROP_PHYSICAL */
|
/* ENTITY_PROP_PHYSICAL */
|
||||||
|
|
||||||
|
//f32 density; /* Density in kg/m^2 */
|
||||||
|
|
||||||
|
f32 friction;
|
||||||
|
|
||||||
f32 mass_unscaled; /* Mass of entity in kg before any transformations */
|
f32 mass_unscaled; /* Mass of entity in kg before any transformations */
|
||||||
f32 inertia_unscaled; /* Inertia of entity in kg*m^2 before any transformations */
|
f32 inertia_unscaled; /* Inertia of entity in kg*m^2 before any transformations */
|
||||||
|
|
||||||
f32 linear_ground_friction;
|
f32 linear_ground_friction;
|
||||||
f32 angular_ground_friction;
|
f32 angular_ground_friction;
|
||||||
|
|
||||||
|
|||||||
12
src/game.c
12
src/game.c
@ -176,11 +176,13 @@ INTERNAL void spawn_test_entities(f32 offset)
|
|||||||
e->angular_ground_friction = 100;
|
e->angular_ground_friction = 100;
|
||||||
|
|
||||||
|
|
||||||
|
//e->control_force = 500;
|
||||||
e->control_force = 500;
|
e->control_force = 500;
|
||||||
e->control_force_max_speed = 4;
|
e->control_force_max_speed = 4;
|
||||||
e->control_torque = 5000;
|
e->control_torque = 500;
|
||||||
|
|
||||||
entity_enable_prop(e, ENTITY_PROP_PHYSICAL);
|
entity_enable_prop(e, ENTITY_PROP_PHYSICAL);
|
||||||
|
|
||||||
e->mass_unscaled = 10;
|
e->mass_unscaled = 10;
|
||||||
e->inertia_unscaled = 10;
|
e->inertia_unscaled = 10;
|
||||||
|
|
||||||
@ -189,7 +191,7 @@ INTERNAL void spawn_test_entities(f32 offset)
|
|||||||
player_ent = e;
|
player_ent = e;
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
{
|
{
|
||||||
struct entity *joint_ent = entity_alloc(root);
|
struct entity *joint_ent = entity_alloc(root);
|
||||||
entity_enable_prop(joint_ent, ENTITY_PROP_PHYSICAL);
|
entity_enable_prop(joint_ent, ENTITY_PROP_PHYSICAL);
|
||||||
@ -487,6 +489,8 @@ INTERNAL void create_contacts(void)
|
|||||||
if (res.num_points > 0) {
|
if (res.num_points > 0) {
|
||||||
struct contact_constraint *constraint = &constraint_ent->contact_constraint_data;
|
struct contact_constraint *constraint = &constraint_ent->contact_constraint_data;
|
||||||
|
|
||||||
|
constraint->friction = math_sqrt(e0->friction * e1->friction);
|
||||||
|
|
||||||
/* Delete old contacts that are no longer present */
|
/* Delete old contacts that are no longer present */
|
||||||
for (u32 i = 0; i < constraint->num_points; ++i) {
|
for (u32 i = 0; i < constraint->num_points; ++i) {
|
||||||
struct contact_point *old = &constraint->points[i];
|
struct contact_point *old = &constraint->points[i];
|
||||||
@ -769,10 +773,10 @@ INTERNAL void solve_contacts(f32 dt, b32 apply_bias)
|
|||||||
f32 vt = v2_dot(vrel, tangent);
|
f32 vt = v2_dot(vrel, tangent);
|
||||||
f32 j = vt * k;
|
f32 j = vt * k;
|
||||||
|
|
||||||
f32 friction = 0.6f;
|
//f32 friction = 0.6f;
|
||||||
//f32 friction = 1.0f;
|
//f32 friction = 1.0f;
|
||||||
//f32 friction = F32_INFINITY;
|
//f32 friction = F32_INFINITY;
|
||||||
f32 max_friction = friction * point->normal_impulse;
|
f32 max_friction = constraint->friction * point->normal_impulse;
|
||||||
f32 old_impulse = point->tangent_impulse;
|
f32 old_impulse = point->tangent_impulse;
|
||||||
f32 new_impulse = clamp_f32(old_impulse + j, -max_friction, max_friction);
|
f32 new_impulse = clamp_f32(old_impulse + j, -max_friction, max_friction);
|
||||||
f32 delta = new_impulse - old_impulse;
|
f32 delta = new_impulse - old_impulse;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user