foot animation for ticks
[carveJwlIkooP6JGAAIwe30JlM.git] / player_skate.c
index efc0f348db2900014c95cf14a848a7d340751a89..ef13865546431cb5d2af4047c698bff0b0555bdf 100644 (file)
@@ -6,6 +6,7 @@
 #include "vg/vg_perlin.h"
 #include "menu.h"
 #include "ent_skateshop.h"
+#include "addon.h"
 
 VG_STATIC void player__skate_bind( player_instance *player )
 {
@@ -261,7 +262,7 @@ too_many_samples:
    v3_copy( average_normal, inf->n );
    v3_copy( average_direction, inf->dir );
 
-   vg_line_pt3( inf->co, 0.02f, VG__GREEN );
+   vg_line_point( inf->co, 0.02f, VG__GREEN );
    vg_line_arrow( inf->co, average_direction, 0.3f, VG__GREEN );
    vg_line_arrow( inf->co, inf->n, 0.2f, VG__CYAN );
 
@@ -713,7 +714,7 @@ VG_STATIC void skate_apply_air_model( player_instance *player )
    q_mul( correction, player->rb.q, player->rb.q );
 }
 
-VG_STATIC int player_skate_trick_input( player_instance *player );
+VG_STATIC enum trick_type player_skate_trick_input( player_instance *player );
 VG_STATIC void skate_apply_trick_model( player_instance *player )
 {
    struct player_skate *s = &player->_skate;
@@ -850,6 +851,10 @@ VG_STATIC void skate_apply_steering_model( player_instance *player )
          rate = 35.0f;
          top  = 1.5f;
       }
+      
+      if( grab < 0.5f ){
+         top *= 1.0f+v3_length( s->state.throw_v )*k_mmthrow_steer;
+      }
    }
 
    float current  = v3_dot( player->rb.to_world[1], player->rb.w ),
@@ -977,7 +982,7 @@ VG_STATIC void skate_apply_jump_model( player_instance *player )
       s->state.jump_time = vg.time;
 
       audio_lock();
-      audio_oneshot_3d( &audio_jumps[vg_randu32()%2], player->rb.co, 40.0f, 1.0f );
+      audio_oneshot_3d( &audio_jumps[vg_randu32()%2], player->rb.co,40.0f,1.0f);
       audio_unlock();
    }
 }
@@ -1103,7 +1108,7 @@ VG_STATIC void skate_copy_holdout( player_instance *player )
    skeleton_copy_pose( sk, s->holdout, player->holdout_pose );
 }
 
-VG_STATIC int player_skate_trick_input( player_instance *player )
+VG_STATIC enum trick_type player_skate_trick_input( player_instance *player )
 {
    return (button_press( k_srbind_trick0 )     ) |
           (button_press( k_srbind_trick1 ) << 1) |
@@ -1129,24 +1134,25 @@ VG_STATIC void player__skate_pre_update( player_instance *player )
       return;
    }
 
-   int trick_id; 
+   enum trick_type trick = k_trick_type_none;
    if( (s->state.activity <= k_skate_activity_air_to_grind) && 
-       (trick_id = player_skate_trick_input( player )) )
+       (trick = player_skate_trick_input( player )) )
    {
       if( (vg.time - s->state.jump_time) < 0.1f ){
          v3_zero( s->state.trick_vel );
          s->state.trick_time = 0.0f;
 
-         if( trick_id == 1 ){
+         if( trick == k_trick_type_kickflip ){
             s->state.trick_vel[0] = 3.0f;
          }
-         else if( trick_id == 2 ){
+         else if( trick == k_trick_type_shuvit ){
             s->state.trick_vel[2] = 3.0f;
          }
-         else if( trick_id == 3 ){
+         else if( trick == k_trick_type_treflip ){
             s->state.trick_vel[0] = 2.0f;
             s->state.trick_vel[2] = 2.0f;
          }
+         s->state.trick_type = trick;
       }
    }
 }
@@ -1175,7 +1181,7 @@ VG_STATIC void player__skate_post_update( player_instance *player )
       v3_add( jump->log[jump->log_length-1], jump->n, p1 );
       vg_line( jump->log[jump->log_length-1], p1, 0xffffffff );
 
-      vg_line_pt3( jump->apex, 0.02f, 0xffffffff );
+      vg_line_point( jump->apex, 0.02f, 0xffffffff );
    }
 
    audio_lock();
@@ -2093,6 +2099,8 @@ VG_STATIC void player__skate_update( player_instance *player )
 
    v3_copy( player->rb.co, s->state.prev_pos );
    s->state.activity_prev = s->state.activity;
+   v3f normal_total;
+   v3_zero( normal_total );
 
    struct board_collider
    {
@@ -2126,7 +2134,6 @@ VG_STATIC void player__skate_update( player_instance *player )
    float slap = 0.0f;
 
    if( s->state.activity <= k_skate_activity_air_to_grind ){
-
       float min_dist = 0.6f;
       for( int i=0; i<2; i++ ){
          v3f wpos, closest;
@@ -2148,9 +2155,6 @@ VG_STATIC void player__skate_update( player_instance *player )
    wheels[1].pos[1] = s->state.slap;
 
 
-
-
-
    const int k_wheel_count = 2;
 
    s->substep = k_rb_delta;
@@ -2344,8 +2348,7 @@ begin_collision:;
    s->substep -= s->substep_delta;
 
    rb_ct manifold[128];
-   int manifold_len   = 0;
-
+   int manifold_len = 0;
    /*
     * Phase -1: head detection
     * --------------------------------------------------------------------------
@@ -2413,7 +2416,7 @@ begin_collision:;
    manifold_len += l;
 
    if( vg_lines.draw )
-      debug_capsule( mtx, capsule.radius, capsule.height, VG__WHITE );
+      vg_line_capsule( mtx, capsule.radius, capsule.height, VG__WHITE );
 
    /* add limits */
    if( s->state.activity >= k_skate_activity_grind_any ){
@@ -2435,7 +2438,7 @@ begin_collision:;
 
    v3f world_cog;
    m4x3_mulv( player->rb.to_world, s->weight_distribution, world_cog );
-   vg_line_pt3( world_cog, 0.02f, VG__BLACK );
+   vg_line_point( world_cog, 0.02f, VG__BLACK );
 
    for( int i=0; i<manifold_len; i ++ ){
       rb_prepare_contact( &manifold[i], s->substep_delta );
@@ -2497,6 +2500,7 @@ begin_collision:;
          v3f impulse;
          v3_muls( ct->n, lambda, impulse );
 
+         v3_muladds( normal_total, impulse, inv_mass, normal_total );
          v3_muladds( player->rb.v, impulse, inv_mass, player->rb.v );
          v3_cross( delta, impulse, impulse );
          m3x3_mulv( iIw, impulse, impulse );
@@ -2523,6 +2527,24 @@ begin_collision:;
     * --------------------------------------------------------------------------
     */
 
+   f32 nforce = v3_length(normal_total);
+   if( nforce > 4.0f ){
+      if( nforce > 17.6f ){
+         v3_muladds( player->rb.v, normal_total, -1.0f, player->rb.v );
+         player__dead_transition(player);
+         player__skate_kill_audio(player);
+         return;
+      }
+
+      f32 amt = k_cam_punch;
+      if( player->camera_mode == k_cam_firstperson ){
+         amt *= 0.25f;
+      }
+
+      v3_muladds( player->cam_land_punch_v, normal_total, amt,
+                  player->cam_land_punch_v );
+   }
+
    s->surface = k_surface_prop_concrete;
 
    for( int i=0; i<manifold_len; i++ ){
@@ -2537,13 +2559,13 @@ begin_collision:;
       m4x3f mtx;
       m3x3_copy( player->rb.to_world, mtx );
       m4x3_mulv( player->rb.to_world, wheels[i].pos, mtx[3] );
-      debug_sphere( mtx, wheels[i].radius,
-                   (u32[]){ VG__WHITE, VG__BLACK, 
+      vg_line_sphere( mtx, wheels[i].radius,
+                      (u32[]){ VG__WHITE, VG__BLACK, 
                             wheels[i].colour }[ wheels[i].state ]);
    }
 
    skate_integrate( player );
-   vg_line_pt3( s->state.cog, 0.02f, VG__WHITE );
+   vg_line_point( s->state.cog, 0.02f, VG__WHITE );
 
    ent_gate *gate = 
       world_intersect_gates(world, player->rb.co, s->state.prev_pos );
@@ -2605,8 +2627,7 @@ begin_collision:;
    }
 }
 
-VG_STATIC void player__skate_im_gui( player_instance *player )
-{
+VG_STATIC void player__skate_im_gui( player_instance *player ){
    struct player_skate *s = &player->_skate;
    player__debugtext( 1, "V:  %5.2f %5.2f %5.2f",player->rb.v[0],
                                                 player->rb.v[1],
@@ -2694,7 +2715,7 @@ VG_STATIC void player__skate_animate( player_instance *player,
    offset[0]=vg_clampf(offset[0],-0.8f,0.8f)*(1.0f-fabsf(s->blend_slide)*0.9f);
    offset[1]=vg_clampf(offset[1],-0.5f,0.0f);
 
-   v3_muls( offset, 0.3f, TEMP_TPV_EXTRA );
+   v3_muls( offset, 0.3f, player->tpv_offset_extra );
 
    /* 
     * Animation blending
@@ -2978,7 +2999,9 @@ VG_STATIC void player__skate_animate( player_instance *player,
       q_mul( kf_board->q, qtrick, kf_board->q );
       q_normalize( kf_board->q );
 
-      struct player_board *board = player_get_player_board( player );
+      struct player_board *board = 
+         addon_cache_item_if_loaded( k_addon_type_board,
+                                     player->board_view_slot );
       
       if( board ){
          /* foot weight distribution */
@@ -3006,6 +3029,25 @@ VG_STATIC void player__skate_animate( player_instance *player,
       kf_board->co[1] += s->state.slap * s->subslap;
       kf_hip->co[1] += s->state.slap * 0.25f;
 
+
+      f32 l = ((s->state.activity < k_skate_activity_ground) &&
+                v3_length2(s->state.trick_vel) > 0.1f )? 1: 0;
+      s->blend_trick_foot = vg_lerpf( s->blend_trick_foot, l,  
+                                      8.4f*vg.time_delta );
+
+      if( s->state.trick_type == k_trick_type_kickflip ){
+         kf_foot_l->co[0] += s->blend_trick_foot * 0.2f;
+      }
+      else if( s->state.trick_type == k_trick_type_shuvit ){
+         kf_foot_l->co[0] += s->blend_trick_foot * 0.1f;
+         kf_foot_r->co[0] -= s->blend_trick_foot * 0.15f;
+      }
+      else if( s->state.trick_type == k_trick_type_treflip ){
+         kf_foot_l->co[0] += s->blend_trick_foot * 0.2f;
+         kf_foot_r->co[0] -= s->blend_trick_foot * 0.15f;
+      }
+
+
       /* 
        * animation wishlist:
        *    boardslide/grind jump animations
@@ -3014,8 +3056,7 @@ VG_STATIC void player__skate_animate( player_instance *player,
        */
 
       /* truck rotation */
-      for( int i=0; i<2; i++ )
-      {
+      for( int i=0; i<2; i++ ){
          float a = vg_minf( s->truckv0[i][0], 1.0f );
          a = -acosf( a ) * vg_signf( s->truckv0[i][1] );
 
@@ -3108,8 +3149,6 @@ VG_STATIC void player__skate_post_animate( player_instance *player )
    m4x3_mulv( av->sk.final_mtx[ av->id_head ], head, s->state.head_position );
    m4x3_mulv( player->rb.to_local, s->state.head_position, 
                                    s->state.head_position );
-
-   /* TODO: Extrapolate to_local matrix? */
 }
 
 VG_STATIC void player__skate_reset_animator( player_instance *player )