assorted crap
[carveJwlIkooP6JGAAIwe30JlM.git] / player_physics.h
index 85f3744be2a274f7f585a0ad3343466c90888c39..41adc1e4150787e8ee13d021a54d8da3dede0e09 100644 (file)
@@ -137,12 +137,7 @@ VG_STATIC void player_physics_control(void)
    phys->reverse = -vg_signf(vel[2]);
 
    float substep = VG_TIMESTEP_FIXED * 0.2f;
-
-#if 0
-   float fwd_resistance = vg_get_button( "break" )? 5.0f: k_friction_resistance;
-#else
    float fwd_resistance = k_friction_resistance;
-#endif
 
    for( int i=0; i<5; i++ )
    {
@@ -183,18 +178,6 @@ VG_STATIC void player_physics_control(void)
       vel[2] -= new_vel * phys->reverse;
    }
 
-   /* Pumping */
-   static float previous = 0.0f;
-   float delta = previous - phys->grab,
-          pump = delta * k_pump_force * VG_TIMESTEP_FIXED;
-   previous = phys->grab;
-
-   v3f p1;
-   v3_muladds( phys->rb.co, phys->rb.up, pump, p1 );
-   vg_line( phys->rb.co, p1, 0xff0000ff );
-
-   vel[1] += pump;
-
    m3x3_mulv( phys->rb.to_world, vel, phys->rb.v );
    
    float input = player.input_js1h->axis.value,
@@ -517,6 +500,43 @@ VG_STATIC void player_walk_physics(void)
    }
 }
 
+VG_STATIC void player_grind(void)
+{
+   struct player_phys *phys = &player.phys;
+
+   v3f closest;
+   int idx = bh_closest_point( world.grind_bh, phys->rb.co, closest, INFINITY );
+   if( idx == -1 )
+      return;
+
+   struct grind_edge *edge = &world.grind_edges[ idx ];
+
+   vg_line( phys->rb.co, closest, 0xff000000 );
+   vg_line_cross( closest, 0xff000000, 0.3f );
+   vg_line( edge->p0, edge->p1, 0xff000000 );
+
+   return;
+
+   idx = bh_closest_point( world.geo_bh, phys->rb.co, closest, INFINITY );
+   vg_line( phys->rb.co, closest, 0xff000000 );
+   vg_line_cross( closest, 0xff000000, 0.3f );
+   
+   idx = world.scene_geo->arrindices[ idx * 3 ];
+   struct world_material *mat = world_tri_index_material( idx );
+
+   if( mat->info.flags & k_material_flag_grind_surface )
+   {
+      v3f grind_delta;
+      v3_sub( closest, phys->rb.co, grind_delta );
+      
+      float p = v3_dot( phys->rb.forward, grind_delta );
+      v3_muladds( grind_delta, phys->rb.forward, -p, grind_delta );
+      
+      float a = vg_maxf( 0.0f, 4.0f-v3_dist2( closest, phys->rb.co ) );
+      v3_muladds( phys->rb.v, grind_delta, a*0.2f, phys->rb.v );
+   }
+}
+
 /*
  * Physics collision detection, and control
  */
@@ -556,22 +576,33 @@ VG_STATIC void player_physics(void)
 
    len_f = rb_sphere_scene( rbf, &world.rb_geo, manifold );
    rb_manifold_filter_coplanar( manifold, len_f, 0.05f );
-   rb_manifold_filter_pairs( manifold, len_f, 0.05f );
    if( len_f > 1 )
+   {
       rb_manifold_filter_backface( manifold, len_f );
+      rb_manifold_filter_joint_edges( manifold, len_f, 0.05f );
+      rb_manifold_filter_pairs( manifold, len_f, 0.05f );
+   }
    len_f = rb_manifold_apply_filtered( manifold, len_f );
    
    rb_ct *man_b = &manifold[len_f];
    len_b = rb_sphere_scene( rbb, &world.rb_geo, man_b );
    rb_manifold_filter_coplanar( man_b, len_b, 0.05f );
-   rb_manifold_filter_pairs( man_b, len_b, 0.05f );
    if( len_b > 1 )
+   {
       rb_manifold_filter_backface( man_b, len_b );
+      rb_manifold_filter_joint_edges( man_b, len_b, 0.05f );
+      rb_manifold_filter_pairs( man_b, len_b, 0.05f );
+   }
    len_b = rb_manifold_apply_filtered( man_b, len_b );
 
    int len = len_f+len_b;
 
-#if 0
+   player_grind();
+
+   boxf bax;
+   v3_sub( phys->rb.co, (v3f){2.0f,2.0f,2.0f}, bax[0] );
+   v3_add( phys->rb.co, (v3f){2.0f,2.0f,2.0f}, bax[1] );
+
    /* 
     * Preprocess collision points, and create a surface picture.
     * we want contacts that are within our 'capsule's internal line to be 
@@ -592,7 +623,6 @@ VG_STATIC void player_physics(void)
          v3_normalize( manifold[i].n );
       }
    }
-#endif
 
    rb_presolve_contacts( manifold, len );
    v3f surface_avg = {0.0f, 0.0f, 0.0f};
@@ -683,8 +713,6 @@ VG_STATIC void player_physics(void)
 
    if( !phys->in_air )
    {
-      /* 20/10/22: make this only go axisways instead, may effect velocities. */
-
       v3f projected, axis;
 
       float d = v3_dot( phys->rb.forward, surface_avg );