holdout poses
[carveJwlIkooP6JGAAIwe30JlM.git] / player_walk.c
index fb71f23c3cc57f8b2ad2e38731fecc6001edfc86..0503f48fde51853c300f8cccfaf868ca7c42d2b1 100644 (file)
@@ -3,57 +3,75 @@
 
 #include "player.h"
 
-VG_STATIC void player_walk_transfer_to_skate( player_instance *player,
-                                              enum skate_activity init )
+VG_STATIC void player_walk_drop_in_vector( player_instance *player, v3f vec )
 {
    struct player_walk *w = &player->_walk;
 
+   v3f axis, init_dir;
+   v3_cross( (v3f){0.0f,1.0f,0.0f}, w->state.drop_in_normal, axis );
+   v3_cross( axis, w->state.drop_in_normal, init_dir );
+   v3_normalize( init_dir );
+   v3_muls( init_dir, 7.0f, vec );
+}
+
+VG_STATIC void player_walk_generic_to_skate( player_instance *player,
+                                             enum skate_activity init )
+{
+   player->subsystem = k_player_subsystem_skate;
+
+   struct player_walk *w = &player->_walk;
+   struct player_skate *s = &player->_skate;
+
    v3f xy_speed, v;
 
    v3_copy( player->rb.v, xy_speed );
    xy_speed[1] = 0.0f;
 
    if( v3_length2( xy_speed ) < 0.1f * 0.1f )
-   {
       q_mulv( player->rb.q, (v3f){0.0f,0.0f,-1.6f}, v );
-   }
    else
       v3_copy( player->rb.v, v );
 
-   player->subsystem = k_player_subsystem_skate;
-   player__skate_transition( player, v, init );
-   return;
+   s->state.activity_prev = k_skate_activity_ground;
+   s->state.activity = init;
+
+   v3f dir;
+   v3_copy( v, dir );
+   v3_normalize( dir );
+
+   q_axis_angle( player->rb.q, (v3f){0.0f,1.0f,0.0f}, 
+                 atan2f( -dir[0], -dir[2] ) );
+
+   v3_muladds( player->rb.co, player->rb.to_world[1], 1.0f, s->state.cog );
+   v3_copy( v, s->state.cog_v );
+   v3_copy( v, player->rb.v );
+
+   player__skate_reset_animator( player );
+   player__skate_clear_mechanics( player );
+   rb_update_transform( &player->rb );
+
+   if( init == k_skate_activity_air )
+      player__approximate_best_trajectory( player );
 }
 
-VG_STATIC void temp_drop_in_finish( player_instance *player )
+VG_STATIC void player_walk_drop_in_to_skate( player_instance *player )
 {
    player->subsystem = k_player_subsystem_skate;
 
    struct player_walk *w = &player->_walk;
    struct player_skate *s = &player->_skate;
-   s->state.activity_prev = k_skate_activity_air;
-   s->state.activity = k_skate_activity_air;
-
-   s->blend_fly = 0.0f;
-   s->blend_slide = 0.0f;
-   s->blend_z = 0.0f;
-   s->blend_x = 0.0f;
-   s->blend_stand = 0.0f;
-   s->blend_push = 0.0f;
-   s->blend_jump = 0.0f;
-   s->blend_airdir = 0.0f;
-
-   v3f axis, init_dir, init_velocity;
-   v3_cross( (v3f){0.0f,1.0f,0.0f}, w->state.drop_in_normal, axis );
-   v3_cross( axis, w->state.drop_in_normal, init_dir );
-   v3_normalize( init_dir );
-   v3_muls( init_dir, 7.0f, init_velocity );
+   s->state.activity_prev = k_skate_activity_ground;
+   s->state.activity = k_skate_activity_ground;
 
-   rb_update_transform( &player->rb );
+   player__skate_clear_mechanics( player );
+   player__skate_reset_animator( player );
+
+   v3f init_velocity;
+   player_walk_drop_in_vector( player, init_velocity );
 
+   rb_update_transform( &player->rb );
    v3_muladds( player->rb.co, player->rb.to_world[1], 1.0f, s->state.cog );
    v3_copy( init_velocity, s->state.cog_v );
-   v3_copy( init_velocity, s->state.vl );
    v3_copy( init_velocity, player->rb.v );
    v3_copy( init_velocity, player->cam_velocity_smooth );
 }
@@ -136,21 +154,8 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player )
          v3_copy( edge, w->state.drop_in_target );
          v3_copy( s1->normal, w->state.drop_in_normal );
 
-         v3f axis, init_dir;
-         v3_cross( (v3f){0.0f,1.0f,0.0f}, w->state.drop_in_normal, axis );
-         v3_cross( axis, w->state.drop_in_normal, init_dir );
-         v3_normalize( init_dir );
-         v3_muls( init_dir, 7.0f, player->rb.v );
-
+         player_walk_drop_in_vector( player, player->rb.v );
          return 1;
-
-#if 0
-         v3_muladds( w->state.drop_in_target, s0->normal, 0.3f,
-                     player->rb.co );
-
-         player->subsystem = k_player_subsystem_skate;
-         player__skate_transition( player, s1->normal, k_skate_activity_air );
-#endif
       }
       else
       {
@@ -179,11 +184,11 @@ VG_STATIC void player__walk_pre_update( player_instance *player )
          w->state.outro_anim = NULL;
          if( w->state.outro_type == k_walk_outro_drop_in )
          {
-            temp_drop_in_finish( player );
+            player_walk_drop_in_to_skate( player );
          }
          else
          {
-            player_walk_transfer_to_skate( player, k_skate_activity_air );
+            player_walk_generic_to_skate( player, k_skate_activity_air );
          }
          return;
       }
@@ -192,18 +197,12 @@ VG_STATIC void player__walk_pre_update( player_instance *player )
    {
       if( w->state.activity == k_walk_activity_ground )
       {
-         //player_walk_transfer_to_skate( player, k_skate_activity_ground );
          if( player_walk_scan_for_drop_in( player ) )
          {
             w->state.outro_type = k_walk_outro_drop_in;
             w->state.outro_anim = w->anim_drop_in;
             w->state.outro_start_time = vg.time;
-#if 0
-            v3_copy( player->cam.pos, player->follow_pos );
-            v3_copy( player->cam.angles, player->follow_angles );
-#endif
             w->state.activity = k_walk_activity_immobile;
-            //v3_zero( player->rb.v );
             v3_copy( player->rb.co, w->state.drop_in_start );
 
             w->state.drop_in_start_angle = player_get_heading_yaw( player );
@@ -222,10 +221,6 @@ VG_STATIC void player__walk_pre_update( player_instance *player )
          w->state.outro_type = k_walk_outro_jump_to_air;
          w->state.outro_anim = w->anim_jump_to_air;
          w->state.outro_start_time = vg.time;
-#if 0
-         v3_copy( player->cam.pos, player->follow_pos );
-         v3_copy( player->cam.angles, player->follow_angles );
-#endif
          return;
       }
    }
@@ -501,14 +496,6 @@ VG_STATIC void player__walk_update( player_instance *player )
       m3x3_mulv( gate->transport, player->rb.v,  player->rb.v );
       rb_update_transform( &player->rb );
 
-      /* analytical rotation of yaw */
-      float a = player_get_heading_yaw( player );
-      v3f fwd_dir = { cosf(a),
-                      0.0f,
-                      sinf(a)};
-      m3x3_mulv( gate->transport, fwd_dir, fwd_dir );
-      player->angles[0] = atan2f( fwd_dir[2], fwd_dir[0] );
-
       w->state_gate_storage = w->state;
       player__pass_gate( player, gate );
    }
@@ -649,9 +636,6 @@ VG_STATIC void player__walk_animate( player_instance *player,
 
          walk_yaw = vg_alerpf( w->state.drop_in_start_angle, 
                                w->state.drop_in_angle, step_t );
-#if 0
-         w->state.heading_angle = walk_yaw;
-#endif
 
          v3_lerp( w->state.drop_in_start, w->state.drop_in_target,
                   step_t, player->rb.co );
@@ -671,38 +655,46 @@ VG_STATIC void player__walk_animate( player_instance *player,
          
 
          /* the drop in bit */
-         v4f final_q;
-         v3f axis;
-         v3_cross( (v3f){0.0f,1.0f,0.0f}, w->state.drop_in_normal, axis );
-         v3_normalize( axis );
+         if( step_t >= 1.0f )
+         {
+            v4f final_q;
+            v3f axis;
+            v3_cross( (v3f){0.0f,1.0f,0.0f}, w->state.drop_in_normal, axis );
+            v3_normalize( axis );
 
-         float a = acosf( w->state.drop_in_normal[1] ) * dop_t;
+            float a = acosf( w->state.drop_in_normal[1] ) * dop_t;
 
-         q_axis_angle( final_q, axis, a );
-         q_mul( final_q, dest->root_q, dest->root_q );
+            q_axis_angle( final_q, axis, a );
+            q_mul( final_q, dest->root_q, dest->root_q );
 
-         float l = dop_t * 0.5f,
-               heading_angle = player_get_heading_yaw( player );
+            float l = dop_t * 0.5f,
+                  heading_angle = w->state.drop_in_angle;
 
-         v3f overhang;
-         overhang[0] = sinf( heading_angle ) * l;
-         overhang[1] = 0.28f * l;
-         overhang[2] = cosf( heading_angle ) * l;
+            v3f overhang;
+            overhang[0] = sinf( heading_angle ) * l;
+            overhang[1] = 0.28f * l;
+            overhang[2] = cosf( heading_angle ) * l;
 
-         q_mulv( final_q, overhang, overhang );
+            q_mulv( final_q, overhang, overhang );
 
-         v3_add( player->rb.co, overhang, player->rb.co );
-         v3_copy( player->rb.co, dest->root_co );
-         v4_copy( dest->root_q, player->rb.q );
+            v3f overhang_pos;
+            v3_add( w->state.drop_in_target, overhang, player->rb.co );
+            v4_copy( dest->root_q, player->rb.q );
+            v3_muladds( dest->root_co, player->rb.to_world[1], 
+                        -0.28f * dop_t, dest->root_co );
 
-         v3_muladds( dest->root_co, player->rb.to_world[1], 
-                     -0.28f * dop_t, dest->root_co );
+            skeleton_copy_pose( sk, dest->pose, player->holdout_pose );
+            player->holdout_time = 1.0f;
+         }
          return;
       }
       else
       {
          v3_muladds( dest->root_co, player->rb.to_world[1], 
                      -0.28f * outro_t, dest->root_co );
+
+         skeleton_copy_pose( sk, dest->pose, player->holdout_pose );
+         player->holdout_time = 1.0f;
       }
    }
    else
@@ -732,94 +724,6 @@ VG_STATIC void player__walk_post_animate( player_instance *player )
    }
    else
       player->cam_velocity_influence = 0.0f;
-
-#if 0
-   /* 3RD */
-
-   v3f view_angles;
-   v3_copy( w->state.angles, view_angles );
-
-   m3x3f angles;
-   euler_m3x3( view_angles, angles );
-
-   v3f cast_dir, origin;
-
-   v3_add( player->rb.co, (v3f){0.0f,2.0f,0.0f}, origin );
-
-   v3_muladds( origin, angles[2], 2.0f, player->override_pos );
-   v3_muladds( player->override_pos, angles[0], 0.5f, player->override_pos );
-
-   if( w->state.outro_anim && (w->state.outro_type == k_walk_outro_drop_in))
-   {
-      float outro_length = (float)w->state.outro_anim->length /
-                                  w->state.outro_anim->rate,
-            outro_time   = vg.time - w->state.outro_start_time,
-            outro_t      = outro_time / outro_length;
-
-      player->override_pos[1] += outro_t * 3.0f;
-   }
-
-   float t;
-   v3f n;
-   if( spherecast_world( origin, player->override_pos, 0.1f, &t, n ) != -1 )
-      v3_lerp( origin, player->override_pos, t, player->override_pos );
-   v3_copy( w->state.angles, player->override_angles );
-
-   /* 1ST */
-   /* FIXME: viewpoint entity */
-   v3f vp = {-0.1f,1.8f,0.0f};
-   m4x3_mulv( av->sk.final_mtx[ av->id_head-1 ], vp, player->fpv_pos );
-   v3_copy( w->state.angles, player->fpv_angles );
-
-   if( w->state.outro_anim )
-   {
-      float outro_length = (float)w->state.outro_anim->length /
-                                  w->state.outro_anim->rate,
-            outro_time   = vg.time - w->state.outro_start_time,
-            outro_t      = outro_time / outro_length;
-
-      /* FIXME: Compression */
-      v3_add( player->rb.co, (v3f){0.0f,1.35f,0.0f}, origin );
-      player_set_follower_subject( player, origin );
-
-      player->cam_angles_override_strength   = 1.0f-outro_t;
-      player->cam_position_override_strength = 1.0f-outro_t;
-
-      v3f fpv_angles;
-
-      if( w->state.outro_anim )
-      {
-         if( w->state.outro_type == k_walk_outro_drop_in )
-         {
-            v3f axis, init_dir;
-            v3_cross( (v3f){0.0f,1.0f,0.0f}, w->state.drop_in_normal, axis );
-            v3_cross( axis, w->state.drop_in_normal, init_dir );
-
-            player_vector_angles( fpv_angles, init_dir, 1.0f, 0.25f );
-         }
-         else
-         {
-            player_vector_angles( fpv_angles, player->rb.v, 1.0f, 0.25f );
-         }
-      }
-      else
-         player_vector_angles( fpv_angles, player->rb.v, 1.0f, 0.25f );
-
-      camera_lerp_angles( player->fpv_angles, fpv_angles, outro_t,
-                          player->fpv_angles );
-   }
-   else
-   {
-      player->cam_angles_override_strength = 1.0f;
-      player->cam_position_override_strength = 1.0f;
-   }
-#endif
-
-   /* FIXME: Organize this. Its int wrong fucking place */
-   v3f vp0 = {0.0f,0.1f, 0.6f},
-       vp1 = {0.0f,0.1f,-0.6f};
-   m4x3_mulv( av->sk.final_mtx[ av->id_board ], vp0, TEMP_BOARD_0 );
-   m4x3_mulv( av->sk.final_mtx[ av->id_board ], vp1, TEMP_BOARD_1 );
 }
 
 
@@ -865,10 +769,14 @@ VG_STATIC void player__walk_bind( player_instance *player )
 VG_STATIC void player__walk_transition( player_instance *player, v3f angles )
 {
    struct player_walk *w = &player->_walk;
-#if 0
-   v3_copy( angles, w->state.angles );
-#endif
    w->state.activity = k_walk_activity_air;
+
+   v3f fwd = { 0.0f, 0.0f, 1.0f };
+   q_mulv( player->rb.q, fwd, fwd );
+
+   q_axis_angle( player->rb.q, (v3f){0.0f,1.0f,0.0f}, 
+                 atan2f( fwd[0], fwd[2] ) );
+   rb_update_transform( &player->rb );
 }
 
 #endif /* PLAYER_DEVICE_WALK_H */