rail targeting
[carveJwlIkooP6JGAAIwe30JlM.git] / player_animation.h
index ea7d566468bbc3463c750c8ef67249b1aeaafcbc..e08991014629b05224ab5babd4754873af2cdc6a 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "player.h"
 
-static void player_animate_offboard(void)
+VG_STATIC void player_animate_offboard(void)
 {
    {
       float fly = player.phys.in_air,
@@ -20,7 +20,8 @@ static void player_animate_offboard(void)
 
       player.ffly  = vg_lerpf( player.ffly, fly, rate*vg.time_delta );
       player.frun  = vg_lerpf( player.frun,
-                               vg_get_axis("walk/push")*0.5f+0.5f, 
+                               player.walk *
+                               (1.0f + player.input_walk->button.value*0.5f),
                                2.0f*vg.time_delta );
    }
 
@@ -83,7 +84,7 @@ static void player_animate_offboard(void)
    skeleton_debug( &player.mdl.sk );
 }
 
-static void player_animate(void)
+VG_STATIC void player_animate(void)
 {
    struct player_phys *phys = &player.phys;
    rb_extrapolate_transform( &player.phys.rb, player.visual_transform );
@@ -139,8 +140,8 @@ static void player_animate(void)
    offset[1] *= -0.3f;
    offset[2] *= 0.01f;
 
-   offset[0] = vg_clampf( offset[0], -0.8f, 0.8f );
-   offset[1] = vg_clampf( offset[1], -0.5f, 0.0f );
+   offset[0]=vg_clampf(offset[0],-0.8f,0.8f)*(1.0f-fabsf(player.fslide)*0.9f);
+   offset[1]=vg_clampf(offset[1],-0.5f,0.0f);
 
    /* 
     * Animation blending
@@ -160,7 +161,7 @@ static void player_animate(void)
    {
       float dirz = phys->reverse > 0.0f? 0.0f: 1.0f,
             dirx = phys->slip < 0.0f?    0.0f: 1.0f,
-            fly  = phys->in_air?         1.0f: 0.0f;
+            fly  = (phys->in_air|phys->grind)?  1.0f: 0.0f;
 
       player.fdirz = vg_lerpf( player.fdirz, dirz, 2.4f*vg.time_delta );
       player.fdirx = vg_lerpf( player.fdirx, dirx, 0.6f*vg.time_delta );
@@ -224,7 +225,7 @@ static void player_animate(void)
    
    mdl_keyframe air_pose[32];
    {
-      float target = -vg_get_axis("lookh");
+      float target = -player.input_js1h->axis.value;
       player.fairdir = vg_lerpf( player.fairdir, target, 2.4f*vg.time_delta );
       
       float air_frame = (player.fairdir*0.5f+0.5f) * (15.0f/30.0f);
@@ -232,8 +233,15 @@ static void player_animate(void)
       skeleton_sample_anim( sk, player.mdl.anim_air, air_frame, apose );
 
       static v2f grab_choice;
-      v2_lerp( grab_choice, (v2f){vg_get_axis("grabh"), vg_get_axis("grabv")},
-                            0.04f, grab_choice );
+
+      v2f grab_input = { player.input_js2h->axis.value,
+                         player.input_js2v->axis.value };
+      v2_add( player.phys.grab_mouse_delta, grab_input, grab_input );
+      if( v2_length2( grab_input ) <= 0.001f )
+         grab_input[0] = -1.0f;
+      else
+         v2_normalize_clamp( grab_input );
+      v2_lerp( grab_choice, grab_input, 2.4f*vg.time_delta, grab_choice );
 
       float ang = atan2f( grab_choice[0], grab_choice[1] ),
             ang_unit = (ang+VG_PIf) * (1.0f/VG_TAUf),
@@ -245,7 +253,7 @@ static void player_animate(void)
 
    skeleton_lerp_pose( sk, ground_pose, air_pose, player.ffly, apose );
 
-   float add_grab_mod = 1.0f - player.ffly*phys->grab;
+   float add_grab_mod = 1.0f - player.ffly;//*phys->grab;
 
    /* additive effects */
    {
@@ -274,7 +282,7 @@ static void player_animate(void)
    skeleton_debug( &player.mdl.sk );
 }
 
-static void player_animate_death_cam(void)
+VG_STATIC void player_animate_death_cam(void)
 {
    v3f delta;
    v3f head_pos;
@@ -300,14 +308,17 @@ static void player_animate_death_cam(void)
    if( ray_world( sample, (v3f){0.0f,-1.0f,0.0f}, &hit ))
       v3_add( hit.pos, min_height, player.camera_pos );
 
-   player.camera_pos[1] = 
-      vg_maxf( wrender.height + 2.0f, player.camera_pos[1] );
+   if( world.water.enabled )
+   {
+      player.camera_pos[1] = 
+         vg_maxf( world.water.height + 2.0f, player.camera_pos[1] );
+   }
 
    player.angles[0] = atan2f( delta[0], -delta[2] ); 
    player.angles[1] = -asinf( delta[1] );
 }
 
-static void player_animate_camera(void)
+VG_STATIC void player_animate_camera(void)
 {
    struct player_phys *phys = &player.phys;
 
@@ -325,15 +336,21 @@ static void player_animate_camera(void)
       /* Look angles */
       v3_lerp( phys->vl, phys->rb.v, 0.05f, phys->vl );
 
+      player.fgrind = vg_lerpf( player.fgrind, phys->grind, vg.time_delta );
+
       float yaw = atan2f(  phys->vl[0], -phys->vl[2] ),
-          pitch = atan2f( -phys->vl[1], 
-                sqrtf(
-                  phys->vl[0]*phys->vl[0] + phys->vl[2]*phys->vl[2]
-                )) * 0.7f;
+          pitch = atan2f
+                  ( 
+                      -phys->vl[1], 
+                      sqrtf
+                      (
+                        phys->vl[0]*phys->vl[0] + phys->vl[2]*phys->vl[2]
+                      )
+                  ) 
+                  * 0.7f + vg_lerpf( 0.30f, 0.90f, player.fgrind );
 
       player.angles[0] = yaw;
-      player.angles[1] = vg_lerpf( player.angles[1], pitch + 0.30f, 
-                                                         player.fonboard );
+      player.angles[1] = vg_lerpf( player.angles[1], pitch, player.fonboard );
 
       /* Camera shake */
       static v2f shake_damp = {0.0f,0.0f};
@@ -350,11 +367,13 @@ static void player_animate_camera(void)
    else
    {
       float speed = vg.time_delta * k_look_speed;
+#if 0
       player.angles[0] += vg_get_axis( "lookh" ) * speed;
       player.angles[1] += vg_get_axis( "lookv" ) * speed;
       
       player.angles[1] = vg_clampf( player.angles[1], 
                                        -k_pitch_limit, k_pitch_limit );
+#endif
       
       float s =  sinf(player.angles[0]) * 0.2f,
             c = -cosf(player.angles[0]) * 0.2f;
@@ -370,7 +389,7 @@ static void player_animate_camera(void)
 
       m4x3_mulv( mtx, player.mdl.cam_pos, cam_pos );
       v3_add( cam_pos, forward_dir, player.camera_pos );
-      v3_lerp( phys->vl, phys->rb.v, 0.3f, phys->vl );
+      v3_lerp( phys->vl, phys->rb.v, 18.0f*vg.time_delta, phys->vl );
    }
 }