now fall in immobile mode
[carveJwlIkooP6JGAAIwe30JlM.git] / player_walk.c
index 87c2246fe6960a662852f3210d95abfc8e1c062d..841574142d12071831958f0c68e67df30b864e59 100644 (file)
@@ -146,8 +146,7 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player )
       ray_hit *ray = &samples[ sample_count ];
       ray->dist = 2.0f;
 
-      if( ray_world( world, pos, ray_dir, ray ) )
-      {
+      if( ray_world( world, pos, ray_dir, ray, 0 ) ){
          vg_line( pos, ray->pos, VG__RED );
          vg_line_point( ray->pos, 0.025f, VG__BLACK );
          
@@ -219,8 +218,7 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player )
          ray_hit ray;
          ray.dist = k_board_length*2.0f + 0.6f;
          
-         if( ray_world( world, va, v0, &ray ) )
-         {
+         if( ray_world( world, va, v0, &ray, 0 ) ){
             vg_line( va, vb, VG__RED );
             vg_line_point( ray.pos, 0.1f, VG__RED );
             vg_error( "invalidated\n" );
@@ -228,8 +226,7 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player )
          }
 
          v3_muls( v0, -1.0f, v0 );
-         if( ray_world( world, vb, v0, &ray ) )
-         {
+         if( ray_world( world, vb, v0, &ray, 0 ) ){
             vg_line( va, vb, VG__RED );
             vg_line_point( ray.pos, 0.1f, VG__RED );
             vg_error( "invalidated\n" );
@@ -370,6 +367,43 @@ VG_STATIC void player_friction( v3f v ){
    v3_muls( v, newspeed, v );
 }
 
+VG_STATIC void player_walk_custom_filter( world_instance *world,
+                                          rb_ct *man, int len, f32 w ){
+   for( int i=0; i<len; i++ ){
+      rb_ct *ci = &man[i];
+      if( ci->type == k_contact_type_disabled ||
+          ci->type == k_contact_type_edge ) 
+         continue;
+
+
+      float d1 = v3_dot( ci->co, ci->n );
+
+      for( int j=0; j<len; j++ ){
+         if( j == i )
+            continue;
+
+         rb_ct *cj = &man[j];
+         if( cj->type == k_contact_type_disabled ) 
+            continue;
+
+         struct world_surface *si = world_contact_surface( world, ci ),
+                              *sj = world_contact_surface( world, cj );
+
+         if(  (sj->info.flags & k_material_flag_walking) &&
+             !(si->info.flags & k_material_flag_walking)){
+            continue;
+         }
+         
+         float d2 = v3_dot( cj->co, ci->n ),
+               d  = d2-d1;
+
+         if( fabsf( d ) <= w ){
+            cj->type = k_contact_type_disabled;
+         }
+      }
+   }
+}
+
 VG_STATIC void player__walk_update( player_instance *player ){
    struct player_walk *w = &player->_walk;
    v3_copy( player->rb.co, w->state.prev_pos );
@@ -387,9 +421,6 @@ VG_STATIC void player__walk_update( player_instance *player ){
 
    enum walk_activity prev_state = w->state.activity;
 
-   if( player->immobile )
-      return;
-
    w->collider.height = 2.0f;
    w->collider.radius = 0.3f;
 
@@ -413,15 +444,15 @@ VG_STATIC void player__walk_update( player_instance *player ){
    v2f steer;
    joystick_state( k_srjoystick_steer, steer );
 
-   w->move_speed = v2_length( steer );
+   w->move_speed = player->immobile? 0.0f: v2_length( steer );
 
    /* 
     * Collision detection
     */
 
    len = rb_capsule__scene( mtx, &w->collider, NULL, 
-                            &world->rb_geo.inf.scene, manifold );
-   rb_manifold_filter_coplanar( manifold, len, 0.01f );
+                            &world->rb_geo.inf.scene, manifold, 0 );
+   player_walk_custom_filter( world, manifold, len, 0.01f );
    len = rb_manifold_apply_filtered( manifold, len );
 
    v3f surface_avg = { 0.0f, 0.0f, 0.0f };
@@ -533,7 +564,8 @@ VG_STATIC void player__walk_update( player_instance *player ){
 
       v3f n;
       float t;
-      if( spherecast_world( world, pa, pb, w->collider.radius, &t, n ) != -1 ){
+      if( spherecast_world( world, pa, pb, 
+                            w->collider.radius, &t, n, 0 ) != -1 ){
          if( player_walk_normal_standable( player, n ) ){
             v3_lerp( pa, pb, t, player->rb.co );
             v3_muladds( player->rb.co, player->basis[1], 
@@ -562,6 +594,11 @@ VG_STATIC void player__walk_update( player_instance *player ){
                   player->rb.v );
    }
 
+   if( player->immobile ){
+      player->rb.v[0] = 0.0f;
+      player->rb.v[2] = 0.0f;
+   }
+
    v3_muladds( player->rb.co, player->rb.v, k_rb_delta, player->rb.co );
    v3_add( player->rb.co, player->basis[1], mtx[3] );
    vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__GREEN );
@@ -587,13 +624,13 @@ VG_STATIC void player__walk_update( player_instance *player ){
       float t, sr = w->collider.radius-0.04f;
       v3f n;
 
-      if( spherecast_world( world, lwr_prev, lwr_now, sr, &t, n ) != -1 ){
+      if( spherecast_world( world, lwr_prev, lwr_now, sr, &t, n, 0 ) != -1 ){
          v3_lerp( lwr_prev, lwr_now, vg_maxf(0.01f,t), player->rb.co );
          player->rb.co[1] -= w->collider.radius;
          rb_update_transform( &player->rb );
 
          v3_add( player->rb.co, player->basis[1], mtx[3] );
-         vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__RED );
+         vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__RED);
       }
    }