X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_physics.h;h=e396e0031d3771cb937a5955b73c5f13bbed2de3;hb=3d8eaabcfd3b87fb52127eaa1241673e8d197bea;hp=20ce7f5d2877aca286dd45a70d0ea0fe6a836356;hpb=a1741ec4aed057cbafff2d6bc9e5cf8a15ae322b;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_physics.h b/player_physics.h index 20ce7f5..e396e00 100644 --- a/player_physics.h +++ b/player_physics.h @@ -339,12 +339,32 @@ VG_STATIC void player_walk_physics(void) v3f forward_dir = { sinf(player.angles[0]),0.0f,-cosf(player.angles[0]) }; v3f right_dir = { -forward_dir[2], 0.0f, forward_dir[0] }; + v2f walk = { player.input_walkh->axis.value, + player.input_walkv->axis.value }; + + if( v2_length2(walk) > 0.001f ) + v2_normalize_clamp( walk ); + if( phys->in_air ) { player_walk_update_collision(); rb_debug( rbf, 0xff0000ff ); rb_debug( rbb, 0xff0000ff ); + /* allow player to accelerate a bit */ + v3f walk_3d; + v3_muls( forward_dir, walk[1], walk_3d ); + v3_muladds( walk_3d, right_dir, walk[0], walk_3d ); + + float current_vel = fabsf(v3_dot( walk_3d, phys->rb.v )), + new_vel = current_vel + VG_TIMESTEP_FIXED*k_air_accelerate, + clamped_new = vg_clampf( new_vel, 0.0f, k_walkspeed ), + vel_diff = vg_maxf( 0.0f, clamped_new - current_vel ); + + v3_muladds( phys->rb.v, right_dir, walk[0] * vel_diff, phys->rb.v ); + v3_muladds( phys->rb.v, forward_dir, walk[1] * vel_diff, phys->rb.v ); + + len = 0; len += rb_sphere_scene( rbf, &world.rb_geo, manifold+len ); len += rb_sphere_scene( rbb, &world.rb_geo, manifold+len ); @@ -396,13 +416,6 @@ VG_STATIC void player_walk_physics(void) } else { - /* translate player */ - v2f walk = { player.input_walkh->axis.value, - player.input_walkv->axis.value }; - - if( v2_length2(walk) > 0.001f ) - v2_normalize_clamp( walk ); - player.walk = v2_length( walk ); if( player.input_walk->button.value ) @@ -443,6 +456,12 @@ VG_STATIC void player_walk_physics(void) } v3_add( dt, phys->rb.co, phys->rb.co ); + if( len ) + { + struct world_material *surface_mat = world_contact_material(manifold); + player.surface_prop = surface_mat->info.surface_prop; + } + /* jump */ if( player.input_jump->button.value ) { @@ -537,6 +556,27 @@ VG_STATIC void player_physics(void) len += rb_sphere_scene( rbf, &world.rb_geo, manifold+len ); len += rb_sphere_scene( rbb, &world.rb_geo, manifold+len ); + /* + * Preprocess collision points, and create a surface picture. + * we want contacts that are within our 'capsule's internal line to be + * clamped so that they face the line and do not oppose, to stop the + * player hanging up on stuff + */ + for( int i=0; ico, dfront ); + v3_sub( manifold[i].co, rbb->co, dback ); + + if( (v3_dot( dfront, phys->rb.forward ) < -0.02f) && + (v3_dot( dback, phys->rb.forward ) > 0.02f)) + { + float p = v3_dot( manifold[i].n, phys->rb.forward ); + v3_muladds( manifold[i].n, phys->rb.forward, -p, manifold[i].n ); + v3_normalize( manifold[i].n ); + } + } + rb_presolve_contacts( manifold, len ); v3f surface_avg = {0.0f, 0.0f, 0.0f};