ahdouaeaiwe
[carveJwlIkooP6JGAAIwe30JlM.git] / player.h
index 1d54fe9a39231180d54a57631470c55df15d9688..1e667ca777d0b0d95b3c86c95bb24dbee6a0517c 100644 (file)
--- a/player.h
+++ b/player.h
 static float 
    k_walkspeed             = 2.0f,
    k_board_radius          = 0.3f,
-   k_board_length          = 0.55f,
+   k_board_length          = 0.45f,
    k_board_allowance       = 0.04f,
-   k_friction_lat          = 8.68f,
-   k_friction_resistance   = 0.02f,
+   k_friction_lat          = 8.8f,
+   k_friction_resistance   = 0.01f,
    k_max_push_speed        = 16.0f,
    k_push_accel            = 5.0f,
    k_push_cycle_rate       = 8.0f,
    k_steer_ground          = 2.5f,
    k_steer_air             = 3.6f,
    k_steer_air_lerp        = 0.3f,
+   k_pump_force            = 000.0f,
    k_downforce             = 5.0f;
 
 static int freecam = 0;
@@ -32,7 +33,7 @@ static int walk_grid_iterations = 1;
 static struct gplayer
 {
    /* Physics */
-   rigidbody rb, collide_front, collide_back;
+   rigidbody rb, collide_front, collide_back, rb_gate_frame;
 
    v3f a, v_last, m, bob, vl;
 
@@ -161,10 +162,7 @@ static void player_start_air(void)
    player.in_air = 1;
 
    float pstep = ktimestep*10.0f;
-
-   float best_velocity_mod = 0.0f,
-         best_velocity_delta = -9999.9f;
-
+   float best_velocity_delta = -9999.9f;
    float k_bias = 0.96f;
 
    v3f axis;
@@ -227,7 +225,6 @@ static void player_start_air(void)
             if( (land_delta < 0.0f) && (land_delta > best_velocity_delta) )
             {
                best_velocity_delta = land_delta;
-               best_velocity_mod = vmod;
 
                v3_copy( contact.pos, player.land_target );
                
@@ -288,7 +285,8 @@ static void player_physics_control(void)
    for( int i=0; i<5; i++ )
    {
       vel[2] = stable_force( vel[2], vg_signf( vel[2] ) * fwd_resistance );
-      vel[0] = stable_force( vel[0], vg_signf( vel[0] ) * -8.78f *substep );
+      vel[0] = stable_force( vel[0], 
+            vg_signf( vel[0] ) * -k_friction_lat*substep );
    }
    
    static double start_push = 0.0;
@@ -304,6 +302,19 @@ static void player_physics_control(void)
       new_vel -= vg_minf(current, k_max_push_speed);
       vel[2] -= new_vel * player.reverse;
    }
+
+   /* Pumping */
+   static float previous = 0.0f;
+   float delta = previous - player.grab,
+          pump = delta * k_pump_force*ktimestep;
+   previous = player.grab;
+
+   v3f p1;
+   v3_muladds( player.rb.co, player.rb.up, pump, p1 );
+   vg_line( player.rb.co, p1, 0xff0000ff );
+
+   vel[1] += pump;
+
    
    m3x3_mulv( player.rb.to_world, vel, player.rb.v );
    
@@ -411,9 +422,13 @@ static void player_physics(void)
 
    m3x3_copy( player.rb.to_world, player.collide_front.to_world );
    m3x3_copy( player.rb.to_world, player.collide_back.to_world );
-   m4x3_mulv( player.rb.to_world, (v3f){0.0f,0.0f,-k_board_length}, rbf->co );
+   
+   player.air_blend = vg_lerpf( player.air_blend, player.in_air, 0.1f );
+   float h = player.air_blend*0.2f;
+
+   m4x3_mulv( player.rb.to_world, (v3f){0.0f,h,-k_board_length}, rbf->co );
    v3_copy( rbf->co, rbf->to_world[3] );
-   m4x3_mulv( player.rb.to_world, (v3f){0.0f,0.0f, k_board_length}, rbb->co );
+   m4x3_mulv( player.rb.to_world, (v3f){0.0f,h, k_board_length}, rbb->co );
    v3_copy( rbb->co, rbb->to_world[3] );
 
    m4x3_invert_affine( rbf->to_world, rbf->to_local );
@@ -431,39 +446,6 @@ static void player_physics(void)
    len += rb_sphere_vs_scene( rbf, &world.rb_geo, manifold+len );
    len += rb_sphere_vs_scene( rbb, &world.rb_geo, manifold+len );
 
-#if 0
-   for( int i=0; i<len; i++ )
-   {
-      u32 *ptri = &world.geo.indices[ geo[i]*3 ];
-
-      for( int j=0; j<3; j++ )
-         v3_copy( world.geo.verts[ptri[j]].co, tri[j] );
-
-      vg_line(tri[0],tri[1],0xff00ff00 );
-      vg_line(tri[1],tri[2],0xff00ff00 );
-      vg_line(tri[2],tri[0],0xff00ff00 );
-
-      v3f temp;
-      v3_copy( player.rb.co, temp );
-
-      for( int j=0; j<2; j++ )
-      {
-         if(manifold_count >= vg_list_size(manifold))
-         {
-            vg_error("Manifold overflow!\n");
-            break;
-         }
-
-         rb_ct *ct = &manifold[manifold_count];
-         v3_copy( poles[j], player.rb.co );
-
-         manifold_count += rb_sphere_vs_triangle( &player.rb, tri, ct );
-      }
-
-      v3_copy( temp, player.rb.co );
-   }
-#endif
-
    rb_presolve_contacts( manifold, len );
    v3f surface_avg = {0.0f, 0.0f, 0.0f};
 
@@ -474,8 +456,19 @@ static void player_physics(void)
    else
    {
       for( int i=0; i<len; i++ )
+      {
          v3_add( manifold[i].n, surface_avg, surface_avg );
 
+#if 0
+         if( manifold[i].element_id <= world.sm_geo_std_oob.vertex_count )
+         {
+            player.is_dead = 1;
+            character_ragdoll_copypose( &player.mdl, player.rb.v );
+            return;
+         }
+#endif
+      }
+
       v3_normalize( surface_avg );
 
       if( v3_dot( player.rb.v, surface_avg ) > 0.5f )
@@ -534,14 +527,17 @@ static void player_physics(void)
       }
    }
 
+   float grabt = vg_get_axis( "grabr" )*0.5f+0.5f;
+   player.grab = vg_lerpf( player.grab, grabt, 0.14f );
+
    if( !player.in_air )
    {
       v3f axis;
       float angle = v3_dot( player.rb.up, surface_avg );
       v3_cross( player.rb.up, surface_avg, axis );
 
-      float cz = v3_dot( player.rb.forward, axis );
-      v3_muls( player.rb.forward, cz, axis );
+      //float cz = v3_dot( player.rb.forward, axis );
+      //v3_muls( player.rb.forward, cz, axis );
 
       if( angle < 0.999f )
       {
@@ -602,9 +598,10 @@ static void player_do_motion(void)
    /* 
     * Gate intersection, by tracing a line over the gate planes 
     */
-   for( int i=0; i<world.gate_count; i++ )
+   for( int i=0; i<world.routes.gate_count; i++ )
    {
-      teleport_gate *gate = &world.gates[i];
+      struct route_gate *rg = &world.routes.gates[i];
+      teleport_gate *gate = &rg->gate;
 
       if( gate_intersect( gate, player.rb.co, prevco ) )
       {
@@ -618,7 +615,9 @@ static void player_do_motion(void)
          v4f transport_rotation;
          m3x3_q( gate->transport, transport_rotation );
          q_mul( transport_rotation, player.rb.q, player.rb.q );
-
+         
+         world_routes_activate_gate( i );
+         player.rb_gate_frame = player.rb;
          break;
       }
    }
@@ -1013,6 +1012,7 @@ static void player_walkgrid_iter(struct walkgrid *wg, int iter)
    pa[0] = wg->region[0][0] + (float)wg->cell_id[0] *k_gridscale;
    pa[1] = (wg->region[0][1] + wg->region[1][1]) * 0.5f + k_gridscale;
    pa[2] = wg->region[0][2] + (float)wg->cell_id[1] *k_gridscale;
+#if 0
    pb[0] = pa[0];
    pb[1] = pa[1];
    pb[2] = pa[2] + k_gridscale;
@@ -1022,7 +1022,6 @@ static void player_walkgrid_iter(struct walkgrid *wg, int iter)
    pd[0] = pa[0] + k_gridscale;
    pd[1] = pa[1];
    pd[2] = pa[2];
-#if 0
    /* if you want to draw the current cell */
    vg_line( pa, pb, 0xff00ffff );
    vg_line( pb, pc, 0xff00ffff );
@@ -1602,14 +1601,12 @@ static void player_animate(void)
 
    /* Head */
    float lslip = fabsf(player.slip);
-                              
-   float grabt = vg_get_axis( "grabr" )*0.5f+0.5f;
-   player.grab = vg_lerpf( player.grab, grabt, 0.04f );
 
    float kheight = 2.0f,
          kleg = 0.6f;
 
    v3f offset;
+   v3_zero( offset );
    m3x3_mulv( player.rb.to_local, player.bob, offset );
 
    static float speed_wobble = 0.0f, speed_wobble_2 = 0.0f;
@@ -1629,11 +1626,30 @@ static void player_animate(void)
    offset[0] = vg_clampf( offset[0], -0.8f, 0.8f );
    offset[1] = vg_clampf( offset[1], -0.5f, 0.0f );
 
+   /* 
+    * Player rotation 
+    */
+#if 0
+   float angle = v3_dot( player.rb.up, (v3f){0.0f,1.0f,0.0f} );
+   v3f axis; 
+   v3_cross( player.rb.up, (v3f){0.0f,1.0f,0.0f}, axis );
+
+   v4f correction;
+   if( angle < 0.99f && 0 )
+   {
+      m3x3_mulv( player.rb.to_local, axis, axis );
+      q_axis_angle( correction, axis, acosf(angle) );
+   }
+   else
+   {
+      q_identity( correction );
+   }
 
    /* 
     * Animation blending
     * ===========================================
     */
+#endif
 
    static float fslide = 0.0f;
    static float fdirz = 0.0f;
@@ -1673,7 +1689,7 @@ static void player_animate(void)
    character_final_pose( &player.mdl, offset, 
          &pose_slide1, amt_slide*(1.0f-fdirx) );
 
-   character_final_pose( &player.mdl, (v3f){0.0f,0.0f,0.0f}, 
+   character_final_pose( &player.mdl, (v4f){0.0f,0.0f,0.0f,1.0f}, 
          &pose_fly, amt_air );
 
    /* 
@@ -1965,6 +1981,8 @@ static int reset_player( int argc, char const *argv[] )
    
    rb_update_transform( &player.rb );
    m3x3_mulv( player.rb.to_world, (v3f){ 0.0f, 0.0f, -1.2f }, player.rb.v );
+
+   player.rb_gate_frame = player.rb;
    return 1;
 }
 
@@ -1975,7 +1993,17 @@ static void player_update(void)
             player.land_target_colours[i], 0.25f);
 
    if( vg_get_axis("grabl")>0.0f)
-      reset_player(0,NULL);
+   {
+      player.rb = player.rb_gate_frame;
+      player.is_dead = 0;
+      player.in_air = 1;
+      m3x3_identity( player.vr );
+
+      player.mdl.shoes[0] = 1;
+      player.mdl.shoes[1] = 1;
+
+      world_routes_notify_reset();
+   }
 
    if( vg_get_button_down( "switchmode" ) )
    {