physics adjustments
authorhgn <hgodden00@gmail.com>
Thu, 10 Nov 2022 03:32:23 +0000 (03:32 +0000)
committerhgn <hgodden00@gmail.com>
Thu, 10 Nov 2022 03:32:23 +0000 (03:32 +0000)
build.c
maps_src/mp_mtzero.mdl
player.h
player_physics.h
rigidbody.h
vg_config.h [deleted file]

diff --git a/build.c b/build.c
index 41e34c0a251a390679b77ad26bc7e66b97f9afff..bc6e81a89d6cc8e7ce9a1bfcf0cbfa62971044d5 100644 (file)
--- a/build.c
+++ b/build.c
@@ -80,6 +80,13 @@ int main( int argc, char *argv[] )
                               vg_compiler.name, uid, vg_compiler.build_dir );
       }
 
+      if( vg_opt('p') || vg_long_opt("run") )
+      {
+         chdir( vg_compiler.build_dir );
+         vg_build_syscall( "./%s", vg_compiler.name );
+         chdir( "../../" );
+      }
+
       if( vg_long_opt( "zip" ) || vg_opt( 'z' ) )
       {
          vg_build_syscall( "mkdir -p dist" );
index 3fa9748ef29821a5bcd963d0906dffa28a3947e6..95d812574a1eb075dc170baa6f293a38a396f7b4 100644 (file)
Binary files a/maps_src/mp_mtzero.mdl and b/maps_src/mp_mtzero.mdl differ
index 0abb22e41963d8da8c5e8e579e93c0417aaba6ef..d3038915c0b09b6393c66c0f0dbcdf39bc18f2de 100644 (file)
--- a/player.h
+++ b/player.h
@@ -14,7 +14,9 @@
 #include "bvh.h"
 
 VG_STATIC float 
-   k_walkspeed             = 12.0f,  /* no longer used */
+   k_walkspeed             = 12.0f,
+   k_air_accelerate        = 20.0f,
+
    k_runspeed              = 20.0f,
    k_board_radius          = 0.3f,
    k_board_length          = 0.45f,
@@ -294,13 +296,21 @@ VG_STATIC void player_init(void)                                            /* 1
    });
 
    vg_convar_push( (struct vg_convar){
-      .name = "walk_speed",
+      .name = "gwalk_speed",
       .data = &k_walkspeed,
       .data_type = k_convar_dtype_f32,
       .opt_f32 = { .clamp = 0 },
       .persistent = 0
    });
 
+   vg_convar_push( (struct vg_convar){
+      .name = "air_accelerate",
+      .data = &k_air_accelerate,
+      .data_type = k_convar_dtype_f32,
+      .opt_f32 = { .clamp = 0 },
+      .persistent = 0
+   });
+
    vg_convar_push( (struct vg_convar){
       .name = "run_speed",
       .data = &k_runspeed,
index 20ce7f5d2877aca286dd45a70d0ea0fe6a836356..9d58e17dfa7196147b7ead3cc944a677c4dfbe09 100644 (file)
@@ -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 )
@@ -537,6 +550,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; i<len; i++ )
+   {
+      v3f dfront, dback;
+      v3_sub( manifold[i].co, rbf->co, 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};
 
index 04d5a9c9830c824d466b7c3fb7cff82364556726..480e43fb5d086752fb42d9ec559681d6f1d97442 100644 (file)
@@ -1427,12 +1427,13 @@ next_vert:;
       vg_line( tri[1],tri[2],0x10ffffff );
       vg_line( tri[2],tri[0],0x10ffffff );
 
-      int hits = rb_sphere_triangle( rba, rbb, tri, buf+count );
+      int contact = rb_sphere_triangle( rba, rbb, tri, buf+count );
+
 #ifdef RIGIDBODY_DYNAMIC_MESH_EDGES
-      if( hits )
+      if( contact )
          inf->collided = 1;
 #endif
-      count += hits;
+      count += contact;
 
       if( count == 12 )
       {
@@ -1475,7 +1476,7 @@ next_vert:;
             continue;
 
          rb_ct *ct = buf+count;
-            
+
          v3_muls( inf_i->normal, c0, ct->n );
          v3_muladds( ct->n, inf_j->normal, c1, ct->n );
          v3_normalize( ct->n );
diff --git a/vg_config.h b/vg_config.h
deleted file mode 100644 (file)
index 0800614..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
- */
-
-#define VG_CONFIG
-#include "vg/vg.h"
-
-VG_STATIC struct button_binding vg_button_binds[] = 
-{
-       { .name = "primary", .bind = GLFW_MOUSE_BUTTON_LEFT },
-       { .name = "secondary", .bind = GLFW_MOUSE_BUTTON_RIGHT },
-   { .name = "left", .bind = GLFW_KEY_A },
-   { .name = "right", .bind = GLFW_KEY_D },
-   { .name = "forward", .bind = GLFW_KEY_W },
-   { .name = "back", .bind = GLFW_KEY_S },
-   { .name = "up", .bind = GLFW_KEY_R },
-   { .name = "reset", .bind = GLFW_KEY_R },
-   { .name = "down", .bind = GLFW_KEY_F },
-   { .name = "yawl", .bind = GLFW_KEY_Q },
-   { .name = "yawr", .bind = GLFW_KEY_E },
-   { .name = "jump", .bind = GLFW_KEY_SPACE },
-   { .name = "kbdwalk/push", .bind = GLFW_KEY_LEFT_SHIFT },
-   { .name = "switchmode", .bind = GLFW_KEY_E },
-   { .name = "menu", .bind = GLFW_KEY_ESCAPE }
-};
-
-VG_STATIC struct button_binding vg_controller_binds[] = 
-{
-   { "jump",         GLFW_GAMEPAD_BUTTON_A },
-   { "break",        GLFW_GAMEPAD_BUTTON_B },
-   { "switchmode",   GLFW_GAMEPAD_BUTTON_Y },
-   { "reset",        GLFW_GAMEPAD_BUTTON_LEFT_BUMPER },
-   { "menu",         GLFW_GAMEPAD_BUTTON_BACK }
-};
-
-VG_STATIC struct axis_binding vg_axis_binds[] = 
-{
-       { .name = "lookh",         .axis = GLFW_GAMEPAD_AXIS_LEFT_X },
-       { .name = "lookv",         .axis = GLFW_GAMEPAD_AXIS_LEFT_Y },
-   { .name = "grabh",      .axis = GLFW_GAMEPAD_AXIS_RIGHT_X },
-   { .name = "grabv",      .axis = GLFW_GAMEPAD_AXIS_RIGHT_Y },
-   { .name = "walk/push",  .axis = GLFW_GAMEPAD_AXIS_LEFT_TRIGGER },
-   { .name = "grab",       .axis = GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER },
-};
-
-VG_STATIC struct vg_achievement vg_achievements[] =
-{
-};