update model format
[carveJwlIkooP6JGAAIwe30JlM.git] / player.h
index 2860d1934cbbf217bb652ffcb8562255f168da38..46c7dd4de0d416836bbe1b05d3b358fe80d71216 100644 (file)
--- a/player.h
+++ b/player.h
@@ -29,11 +29,12 @@ static float
 
 static int freecam = 0;
 static int walk_grid_iterations = 1;
+static float fc_speed = 10.0f;
 
 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;
 
@@ -100,13 +101,13 @@ static void player_mouseview(void)
       v2_sub( vg_mouse, mouse_last, delta );
       v2_copy( vg_mouse, mouse_last );
 
-      v2_muladds( view_vel, delta, 0.005f, view_vel );
+      v2_muladds( view_vel, delta, 0.001f, view_vel );
    }
    
    v2_muladds( view_vel, 
          (v2f){ vg_get_axis("h1"), vg_get_axis("v1") }, 
          0.05f, view_vel );
-   v2_muls( view_vel, 0.7f, view_vel );
+   v2_muls( view_vel, 0.93f, view_vel );
    v2_add( view_vel, player.angles, player.angles );
    player.angles[1] = vg_clampf( player.angles[1], -VG_PIf*0.5f, VG_PIf*0.5f );
 }
@@ -115,7 +116,7 @@ static void player_freecam(void)
 {
    player_mouseview();
 
-   float movespeed = 25.0f;
+   float movespeed = fc_speed;
    v3f lookdir = { 0.0f, 0.0f, -1.0f },
        sidedir = { 1.0f, 0.0f,  0.0f };
    
@@ -162,10 +163,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;
@@ -228,7 +226,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 );
                
@@ -450,39 +447,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};
 
@@ -493,8 +457,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 )
@@ -624,9 +599,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 ) )
       {
@@ -640,7 +616,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;
       }
    }
@@ -1035,6 +1013,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;
@@ -1044,7 +1023,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 );
@@ -2004,6 +1982,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;
 }
 
@@ -2014,7 +1994,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" ) )
    {