X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_walk.c;h=841574142d12071831958f0c68e67df30b864e59;hb=1d06671f87a9d24596fc6808d8e0db889a818750;hp=5c52f2d03004a6cc865d1191e91fcb3c5d231cb4;hpb=9a7f395032111ebea53acf45c5af67ecbfbf7651;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_walk.c b/player_walk.c index 5c52f2d..8415741 100644 --- a/player_walk.c +++ b/player_walk.c @@ -59,6 +59,7 @@ VG_STATIC void player_walk_generic_to_skate( player_instance *player, v3_copy( v, s->state.cog_v ); v3_copy( v, player->rb.v ); + player__begin_holdout( player ); player__skate_reset_animator( player ); player__skate_clear_mechanics( player ); rb_update_transform( &player->rb ); @@ -78,6 +79,7 @@ VG_STATIC void player_walk_drop_in_to_skate( player_instance *player ) s->state.activity_prev = k_skate_activity_ground; s->state.activity = k_skate_activity_ground; + player__begin_holdout( player ); player__skate_clear_mechanics( player ); player__skate_reset_animator( player ); @@ -88,7 +90,7 @@ VG_STATIC void player_walk_drop_in_to_skate( player_instance *player ) 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, player->rb.v ); - v3_copy( init_velocity, player->cam_velocity_smooth ); + v3_copy( init_velocity, player->cam_control.cam_velocity_smooth ); v3_copy( (v3f){1.0f,0.0f,0.0f}, s->state.trick_euler ); } @@ -144,10 +146,9 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player ) ray_hit *ray = &samples[ sample_count ]; ray->dist = 2.0f; - if( ray_world( world, pos, ray_dir, ray ) ) - { + if( ray_world( world, pos, ray_dir, ray, 0 ) ){ vg_line( pos, ray->pos, VG__RED ); - vg_line_pt3( ray->pos, 0.025f, VG__BLACK ); + vg_line_point( ray->pos, 0.025f, VG__BLACK ); sample_count ++; } @@ -156,25 +157,21 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player ) float min_a = 0.70710678118654752f; ray_hit *candidate = NULL; - if( sample_count >= 2 ) - { - for( int i=0; i= 2 ){ + for( int i=0; inormal, s1->normal ); - if( (a < min_a) && (a >= -0.1f) && (s0->normal[1]>s1->normal[1]) ) - { + if( (a < min_a) && (a >= -0.1f) && (s0->normal[1]>s1->normal[1]) ){ min_a = a; candidate = s0; } } } - if( candidate ) - { + if( candidate ){ v4f pa, pb, pc; ray_hit *s0 = candidate, @@ -192,8 +189,7 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player ) pc[3] = v3_dot( pc, player->rb.co ); v3f edge; - if( plane_intersect3( pa, pb, pc, edge ) ) - { + if( plane_intersect3( pa, pb, pc, edge ) ){ v3_copy( edge, w->state.drop_in_target ); v3_copy( s1->normal, w->state.drop_in_normal ); v3_copy( player->rb.co, w->state.drop_in_start ); @@ -222,19 +218,17 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player ) ray_hit ray; ray.dist = k_board_length*2.0f + 0.6f; - if( ray_world( world, va, v0, &ray ) ) - { + if( ray_world( world, va, v0, &ray, 0 ) ){ vg_line( va, vb, VG__RED ); - vg_line_pt3( ray.pos, 0.1f, VG__RED ); + vg_line_point( ray.pos, 0.1f, VG__RED ); vg_error( "invalidated\n" ); return 0; } v3_muls( v0, -1.0f, v0 ); - if( ray_world( world, vb, v0, &ray ) ) - { + if( ray_world( world, vb, v0, &ray, 0 ) ){ vg_line( va, vb, VG__RED ); - vg_line_pt3( ray.pos, 0.1f, VG__RED ); + vg_line_point( ray.pos, 0.1f, VG__RED ); vg_error( "invalidated\n" ); return 0; } @@ -251,20 +245,34 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player ) return 0; } +VG_STATIC struct skeleton_anim *player_walk_outro_anim( player_instance *player, + enum walk_outro type ){ + struct player_walk *w = &player->_walk; + + return (struct skeleton_anim *[]){ + [k_walk_outro_none] = NULL, + [k_walk_outro_jump_to_air] = w->anim_jump_to_air, + [k_walk_outro_regular] = w->anim_intro, + [k_walk_outro_drop_in] = w->anim_drop_in + }[ type ]; +} + + VG_STATIC void player__walk_pre_update( player_instance *player ) { struct player_walk *w = &player->_walk; if( !player->immobile ) - player_look( player, player->angles ); + player_look( player->angles, skaterift.time_rate ); - 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; + if( w->state.outro_type ){ + struct skeleton_anim *anim = + player_walk_outro_anim( player, w->state.outro_type ); + + f32 outro_length = (f32)anim->length / anim->rate, + outro_time = vg.time - w->state.outro_start_time; if( outro_time >= outro_length ){ - w->state.outro_anim = NULL; if( w->state.outro_type == k_walk_outro_drop_in ){ player_walk_drop_in_to_skate( player ); } @@ -276,6 +284,7 @@ VG_STATIC void player__walk_pre_update( player_instance *player ) k_skate_activity_ground, 1.0f ); } + w->state.outro_type = k_walk_outro_none; return; } } @@ -284,13 +293,15 @@ VG_STATIC void player__walk_pre_update( player_instance *player ) player->subsystem = k_player_subsystem_drive; } else{ - if( !player_get_player_board(player) ) - return; + struct player_board *board = + addon_cache_item_if_loaded( k_addon_type_board, + player->board_view_slot ); + + if( !board ) return; if( w->state.activity == k_walk_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; player->immobile = 1; @@ -301,7 +312,6 @@ VG_STATIC void player__walk_pre_update( player_instance *player ) } else{ w->state.outro_type = k_walk_outro_regular; - w->state.outro_anim = w->anim_intro; w->state.outro_start_time = vg.time; w->state.activity = k_walk_activity_lockedmove; @@ -311,7 +321,6 @@ VG_STATIC void player__walk_pre_update( player_instance *player ) } else{ 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; return; } @@ -323,13 +332,11 @@ VG_STATIC void player__walk_pre_update( player_instance *player ) } } -VG_STATIC int player_walk_normal_standable( player_instance *player, v3f n ) -{ +VG_STATIC int player_walk_normal_standable( player_instance *player, v3f n ){ return v3_dot( n, player->basis[1] ) > 0.70710678118f; } -VG_STATIC void player_accelerate( v3f v, v3f movedir, float speed, float accel ) -{ +VG_STATIC void player_accelerate( v3f v, v3f movedir, f32 speed, f32 accel ){ float currentspeed = v3_dot( v, movedir ), addspeed = speed - currentspeed; @@ -344,8 +351,7 @@ VG_STATIC void player_accelerate( v3f v, v3f movedir, float speed, float accel ) v3_muladds( v, movedir, accelspeed, v ); } -VG_STATIC void player_friction( v3f v ) -{ +VG_STATIC void player_friction( v3f v ){ float speed = v3_length( v ), drop = 0.0f, control = vg_maxf( speed, k_stopspeed ); @@ -361,10 +367,47 @@ VG_STATIC void player_friction( v3f v ) v3_muls( v, newspeed, v ); } -VG_STATIC void player__walk_update( player_instance *player ) -{ +VG_STATIC void player_walk_custom_filter( world_instance *world, + rb_ct *man, int len, f32 w ){ + for( int i=0; itype == k_contact_type_disabled || + ci->type == k_contact_type_edge ) + continue; + + + float d1 = v3_dot( ci->co, ci->n ); + + for( int j=0; jtype == k_contact_type_disabled ) + continue; + + struct world_surface *si = world_contact_surface( world, ci ), + *sj = world_contact_surface( world, cj ); + + if( (sj->info.flags & k_material_flag_walking) && + !(si->info.flags & k_material_flag_walking)){ + continue; + } + + float d2 = v3_dot( cj->co, ci->n ), + d = d2-d1; + + if( fabsf( d ) <= w ){ + cj->type = k_contact_type_disabled; + } + } + } +} + +VG_STATIC void player__walk_update( player_instance *player ){ struct player_walk *w = &player->_walk; v3_copy( player->rb.co, w->state.prev_pos ); + v3_zero( player->rb.w ); world_instance *world = world_current_instance(); @@ -378,9 +421,6 @@ VG_STATIC void player__walk_update( player_instance *player ) enum walk_activity prev_state = w->state.activity; - if( player->immobile ) - return; - w->collider.height = 2.0f; w->collider.radius = 0.3f; @@ -388,7 +428,7 @@ VG_STATIC void player__walk_update( player_instance *player ) m3x3_copy( player->rb.to_world, mtx ); v3_add( player->rb.co, player->basis[1], mtx[3] ); - debug_capsule( mtx, w->collider.radius, w->collider.height, VG__WHITE ); + vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__WHITE ); rb_ct manifold[64]; int len; @@ -404,15 +444,15 @@ VG_STATIC void player__walk_update( player_instance *player ) v2f steer; joystick_state( k_srjoystick_steer, steer ); - w->move_speed = v2_length( steer ); + w->move_speed = player->immobile? 0.0f: v2_length( steer ); /* * Collision detection */ len = rb_capsule__scene( mtx, &w->collider, NULL, - &world->rb_geo.inf.scene, manifold ); - rb_manifold_filter_coplanar( manifold, len, 0.01f ); + &world->rb_geo.inf.scene, manifold, 0 ); + player_walk_custom_filter( world, manifold, len, 0.01f ); len = rb_manifold_apply_filtered( manifold, len ); v3f surface_avg = { 0.0f, 0.0f, 0.0f }; @@ -453,7 +493,7 @@ VG_STATIC void player__walk_update( player_instance *player ) v3_normalize( surface_avg ); v3f tx, ty; - rb_tangent_basis( surface_avg, tx, ty ); + v3_tangent_basis( surface_avg, tx, ty ); if( v2_length2(steer) > 0.001f ){ /* clip movement to the surface */ @@ -524,7 +564,8 @@ VG_STATIC void player__walk_update( player_instance *player ) v3f n; float t; - if( spherecast_world( world, pa, pb, w->collider.radius, &t, n ) != -1 ){ + if( spherecast_world( world, pa, pb, + w->collider.radius, &t, n, 0 ) != -1 ){ if( player_walk_normal_standable( player, n ) ){ v3_lerp( pa, pb, t, player->rb.co ); v3_muladds( player->rb.co, player->basis[1], @@ -553,9 +594,14 @@ VG_STATIC void player__walk_update( player_instance *player ) player->rb.v ); } + if( player->immobile ){ + player->rb.v[0] = 0.0f; + player->rb.v[2] = 0.0f; + } + v3_muladds( player->rb.co, player->rb.v, k_rb_delta, player->rb.co ); v3_add( player->rb.co, player->basis[1], mtx[3] ); - debug_capsule( mtx, w->collider.radius, w->collider.height, VG__GREEN ); + vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__GREEN ); /* * CCD routine @@ -578,13 +624,13 @@ VG_STATIC void player__walk_update( player_instance *player ) float t, sr = w->collider.radius-0.04f; v3f n; - if( spherecast_world( world, lwr_prev, lwr_now, sr, &t, n ) != -1 ){ + if( spherecast_world( world, lwr_prev, lwr_now, sr, &t, n, 0 ) != -1 ){ v3_lerp( lwr_prev, lwr_now, vg_maxf(0.01f,t), player->rb.co ); player->rb.co[1] -= w->collider.radius; rb_update_transform( &player->rb ); v3_add( player->rb.co, player->basis[1], mtx[3] ); - debug_capsule( mtx, w->collider.radius, w->collider.height, VG__RED ); + vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__RED); } } @@ -599,21 +645,12 @@ VG_STATIC void player__walk_update( player_instance *player ) q_mul( transport_rotation, player->rb.q, player->rb.q ); rb_update_transform( &player->rb ); - - w->state_gate_storage = w->state; player__pass_gate( player, gate ); } rb_update_transform( &player->rb ); } -VG_STATIC void player__walk_restore( player_instance *player ) -{ - struct player_walk *w = &player->_walk; - w->state = w->state_gate_storage; -} - -VG_STATIC void player__walk_post_update( player_instance *player ) -{ +VG_STATIC void player__walk_post_update( player_instance *player ){ struct player_walk *w = &player->_walk; m4x3f mtx; @@ -622,7 +659,7 @@ VG_STATIC void player__walk_post_update( player_instance *player ) float substep = vg.time_fixed_extrapolate; v3_muladds( mtx[3], player->rb.v, k_rb_delta*substep, mtx[3] ); - debug_capsule( mtx, w->collider.radius, w->collider.height, VG__YELOW ); + vg_line_capsule( mtx, w->collider.radius, w->collider.height, VG__YELOW ); /* Calculate header */ @@ -638,7 +675,7 @@ VG_STATIC void player__walk_post_update( player_instance *player ) q_normalize( player->rb.q ); } - vg_line_pt3( w->state.drop_in_target, 0.1f, VG__GREEN ); + vg_line_point( w->state.drop_in_target, 0.1f, VG__GREEN ); v3f p1; v3_muladds( w->state.drop_in_target, w->state.drop_in_normal, 0.3f, p1 ); vg_line( w->state.drop_in_target, p1, VG__GREEN ); @@ -646,7 +683,7 @@ VG_STATIC void player__walk_post_update( player_instance *player ) vg_line( w->state.drop_in_target, p1, VG__GREEN ); vg_line( w->state.drop_in_target, w->state.drop_in_foot_anchor, VG__WHITE ); - vg_line_pt3( w->state.drop_in_foot_anchor, 0.08f, VG__PINK ); + vg_line_point( w->state.drop_in_foot_anchor, 0.08f, VG__PINK ); float a = player_get_heading_yaw( player ); @@ -660,12 +697,12 @@ VG_STATIC void player__walk_post_update( player_instance *player ) int walk_phase = 0; - if( vg_fractf(w->walk_timer) > 0.5f ) + if( vg_fractf(w->state.walk_timer) > 0.5f ) walk_phase = 1; else walk_phase = 0; - if( (w->step_phase != walk_phase) && + if( (w->state.step_phase != walk_phase) && (w->state.activity == k_walk_activity_ground ) ) { audio_lock(); @@ -677,170 +714,191 @@ VG_STATIC void player__walk_post_update( player_instance *player ) } else if( w->surface == k_surface_prop_grass ){ audio_oneshot_3d( - &audio_footsteps_grass[vg_randu32()%vg_list_size(audio_footsteps_grass)], + &audio_footsteps_grass[ vg_randu32()% + vg_list_size(audio_footsteps_grass)], player->rb.co, 40.0f, 1.0f ); } else if( w->surface == k_surface_prop_wood ){ audio_oneshot_3d( - &audio_footsteps_wood[vg_randu32()%vg_list_size(audio_footsteps_wood)], + &audio_footsteps_wood[ vg_randu32()% + vg_list_size(audio_footsteps_wood)], player->rb.co, 40.0f, 1.0f ); } audio_unlock(); } - w->step_phase = walk_phase; + w->state.step_phase = walk_phase; } -VG_STATIC void player__walk_animate( player_instance *player, - player_animation *dest ) -{ +VG_STATIC void player__walk_animate( player_instance *player ){ struct player_walk *w = &player->_walk; - struct skeleton *sk = &player->playeravatar->sk; + player_pose *pose = &player->pose; + struct player_walk_animator *animator = &w->animator; + + animator->outro_type = w->state.outro_type; { - float fly = (w->state.activity == k_walk_activity_air)? 1.0f: 0.0f, - rate; + f32 fly = (w->state.activity == k_walk_activity_air)? 1.0f: 0.0f, + rate; - if( w->state.activity == k_walk_activity_air ) - rate = 2.4f; - else - rate = 9.0f; + if( w->state.activity == k_walk_activity_air ) rate = 2.4f; + else rate = 9.0f; - w->blend_fly = vg_lerpf( w->blend_fly, fly, rate*vg.time_delta ); - w->blend_run = vg_lerpf( w->blend_run, w->move_speed, 2.0f*vg.time_delta); + animator->fly = vg_lerpf( animator->fly, fly, rate*vg.time_delta ); + animator->run = vg_lerpf( animator->run, w->move_speed, + 2.0f*vg.time_delta); } - player_pose apose, bpose; - if( w->move_speed > 0.025f ){ /* TODO move */ float walk_norm = 30.0f/(float)w->anim_walk->length, run_norm = 30.0f/(float)w->anim_run->length, walk_adv = vg_lerpf( walk_norm, run_norm, w->move_speed ); - w->walk_timer += walk_adv * vg.time_delta; + w->state.walk_timer += walk_adv * vg.time_delta; } + else + w->state.walk_timer = 0.0f; + animator->walk_timer = w->state.walk_timer; + + if( !player->immobile ) + rb_extrapolate( &player->rb, animator->root_co, animator->root_q ); else{ - w->walk_timer = 0.0f; + v3_copy( player->rb.co, animator->root_co ); + v4_copy( player->rb.q, animator->root_q ); } - float walk_norm = (float)w->anim_walk->length/30.0f, - run_norm = (float)w->anim_run->length/30.0f, - t = w->walk_timer, - l = vg_clampf( w->blend_run*15.0f, 0.0f, 1.0f ), - idle_walk = vg_clampf( (w->blend_run-0.1f)/(1.0f-0.1f), 0.0f, 1.0f ); - - /* walk/run */ - skeleton_sample_anim( sk, w->anim_walk, t*walk_norm, apose ); - skeleton_sample_anim( sk, w->anim_run, t*run_norm, bpose ); - - skeleton_lerp_pose( sk, apose, bpose, l, apose ); - - /* idle */ - skeleton_sample_anim( sk, w->anim_idle, vg.time*0.1f, bpose ); - skeleton_lerp_pose( sk, apose, bpose, 1.0f-idle_walk, apose ); - - /* air */ - skeleton_sample_anim( sk, w->anim_jump, vg.time*0.6f, bpose ); - skeleton_lerp_pose( sk, apose, bpose, w->blend_fly, apose ); - - /* Create transform */ - rb_extrapolate( &player->rb, dest->root_co, dest->root_q ); - - float walk_yaw = player_get_heading_yaw( player ); - - if( w->state.outro_anim ){ + f32 walk_yaw = player_get_heading_yaw( player ); + if( w->state.outro_type ){ struct player_avatar *av = player->playeravatar; - 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; - - /* TODO: Compression */ - skeleton_sample_anim_clamped( sk, w->state.outro_anim, - outro_time, bpose ); - skeleton_lerp_pose( sk, apose, bpose, outro_t * 10.0f, dest->pose ); + struct skeleton_anim *anim = + player_walk_outro_anim( player, w->state.outro_type ); + f32 outro_length = (f32)anim->length / anim->rate, + outro_time = vg.time - w->state.outro_start_time; + animator->outro_t = outro_time / outro_length; if( w->state.outro_type == k_walk_outro_drop_in ){ - float inv_rate = 1.0f / w->state.outro_anim->rate, - anim_frames = w->state.outro_anim->length * inv_rate, + float inv_rate = 1.0f / anim->rate, + anim_frames = anim->length * inv_rate, step_frames = 12.0f * inv_rate, commit_frames = 6.0f * inv_rate, drop_frames = anim_frames - step_frames, step_t = vg_minf( 1.0f, outro_time / step_frames ), remaind_time = vg_maxf( 0.0f, outro_time - step_frames ), - dop_t = vg_minf( 1.0f, remaind_time / drop_frames ), - commit_t = vg_minf( 1.0f, remaind_time / commit_frames ); + dop_t = vg_minf( 1.0f, remaind_time / drop_frames ); + animator->commit_t = vg_minf( 1.0f, remaind_time / commit_frames ); walk_yaw = vg_alerpf( w->state.drop_in_start_angle, w->state.drop_in_angle, step_t ); v3_lerp( w->state.drop_in_start, w->state.drop_in_target, step_t, player->rb.co ); - q_axis_angle( dest->root_q, (v3f){0.0f,1.0f,0.0f}, walk_yaw + VG_PIf ); - - m4x3f transform, inverse; - q_m3x3( dest->root_q, transform ); - v3_copy( dest->root_co, transform[3] ); - m4x3_invert_affine( transform, inverse ); - - v3f anchored_pos; - m4x3_mulv( inverse, w->state.drop_in_foot_anchor, anchored_pos ); + q_axis_angle( animator->root_q, (v3f){0.0f,1.0f,0.0f}, + walk_yaw + VG_PIf ); - v3_lerp( dest->pose[ av->id_ik_foot_r-1 ].co, anchored_pos, - 1.0f-commit_t, - dest->pose[ av->id_ik_foot_r-1 ].co ); - + v3_copy( w->state.drop_in_foot_anchor, animator->foot_anchor ); /* the drop in bit */ if( step_t >= 1.0f ){ v4f final_q; player_walk_drop_in_overhang_transform( player, dop_t, player->rb.co, final_q ); - q_mul( final_q, dest->root_q, dest->root_q ); - - v4_copy( dest->root_q, player->rb.q ); - v3_muladds( dest->root_co, player->rb.to_world[1], - -0.1f * dop_t, dest->root_co ); + q_mul( final_q, animator->root_q, animator->root_q ); - skeleton_copy_pose( sk, dest->pose, player->holdout_pose ); - player->holdout_time = 1.0f; + v4_copy( animator->root_q, player->rb.q ); + v3_muladds( animator->root_co, player->rb.to_world[1], + -0.1f*dop_t, animator->root_co ); } return; } else{ - v3_muladds( dest->root_co, player->rb.to_world[1], - -0.1f * outro_t, dest->root_co ); - - skeleton_copy_pose( sk, dest->pose, player->holdout_pose ); - player->holdout_time = 1.0f; + v3_muladds( animator->root_co, player->rb.to_world[1], + -0.1f*animator->outro_t, animator->root_co ); } } - else{ - skeleton_copy_pose( sk, apose, dest->pose ); - } - q_axis_angle( dest->root_q, (v3f){0.0f,1.0f,0.0f}, walk_yaw + VG_PIf ); - q_mul( player->qbasis, dest->root_q, dest->root_q ); - q_normalize( dest->root_q ); + q_axis_angle( animator->root_q, (v3f){0.0f,1.0f,0.0f}, walk_yaw + VG_PIf ); + q_mul( player->qbasis, animator->root_q, animator->root_q ); + q_normalize( animator->root_q ); } -VG_STATIC void player__walk_post_animate( player_instance *player ) -{ +VG_STATIC void player__walk_pose( player_instance *player, player_pose *pose ){ + struct player_walk *w = &player->_walk; + struct player_walk_animator *animator = &w->animator; + struct skeleton *sk = &player->playeravatar->sk; + struct player_avatar *av = player->playeravatar; + + v3_copy( animator->root_co, pose->root_co ); + v4_copy( animator->root_q, pose->root_q ); + pose->board.lean = 0.0f; + pose->type = k_player_pose_type_ik; + + float walk_norm = (float)w->anim_walk->length/30.0f, + run_norm = (float)w->anim_run->length/30.0f, + t = animator->walk_timer, + l = vg_clampf( animator->run*15.0f, 0.0f, 1.0f ), + idle_walk = vg_clampf( (animator->run-0.1f)/(1.0f-0.1f), 0.0f, 1.0f ); + + /* walk/run */ + mdl_keyframe apose[32], bpose[32]; + skeleton_sample_anim( sk, w->anim_walk, t*walk_norm, apose ); + skeleton_sample_anim( sk, w->anim_run, t*run_norm, bpose ); + + skeleton_lerp_pose( sk, apose, bpose, l, apose ); + + /* idle */ + skeleton_sample_anim( sk, w->anim_idle, vg.time*0.1f, bpose ); + skeleton_lerp_pose( sk, apose, bpose, 1.0f-idle_walk, apose ); + + /* air */ + skeleton_sample_anim( sk, w->anim_jump, vg.time*0.6f, bpose ); + skeleton_lerp_pose( sk, apose, bpose, animator->fly, apose ); + + if( animator->outro_type ){ + struct skeleton_anim *anim = + player_walk_outro_anim( player, animator->outro_type ); + + f32 outro_length = (f32)anim->length / anim->rate, + outro_time = animator->outro_t*outro_length; + + skeleton_sample_anim_clamped( sk, anim, outro_time, bpose ); + skeleton_lerp_pose( sk, apose, bpose, animator->outro_t*10.0f, + pose->keyframes ); + + if( animator->outro_type == k_walk_outro_drop_in ){ + m4x3f transform, inverse; + q_m3x3( pose->root_q, transform ); + v3_copy( pose->root_co, transform[3] ); + m4x3_invert_affine( transform, inverse ); + + v3f anchored_pos; + m4x3_mulv( inverse, animator->foot_anchor, anchored_pos ); + + v3_lerp( pose->keyframes[ av->id_ik_foot_r-1 ].co, anchored_pos, + 1.0f-animator->commit_t, + pose->keyframes[ av->id_ik_foot_r-1 ].co ); + } + } + else + skeleton_copy_pose( sk, apose, pose->keyframes ); +} + +VG_STATIC void player__walk_post_animate( player_instance *player ){ /* * Camera */ struct player_walk *w = &player->_walk; struct player_avatar *av = player->playeravatar; - 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; + if( w->state.outro_type ){ + struct skeleton_anim *anim = + player_walk_outro_anim( player, w->state.outro_type ); + + f32 outro_length = (f32)anim->length / anim->rate, + outro_time = vg.time - w->state.outro_start_time, + outro_t = outro_time / outro_length; player->cam_velocity_influence = outro_t; } @@ -848,9 +906,7 @@ VG_STATIC void player__walk_post_animate( player_instance *player ) player->cam_velocity_influence = 0.0f; } - -VG_STATIC void player__walk_im_gui( player_instance *player ) -{ +VG_STATIC void player__walk_im_gui( player_instance *player ){ struct player_walk *w = &player->_walk; player__debugtext( 1, "V: %5.2f %5.2f %5.2f",player->rb.v[0], player->rb.v[1], @@ -872,16 +928,17 @@ VG_STATIC void player__walk_im_gui( player_instance *player ) "metal" } [w->surface] ); - 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; + if( w->state.outro_type ){ + struct skeleton_anim *anim = + player_walk_outro_anim( player, w->state.outro_type ); + + f32 outro_length = (f32)anim->length / anim->rate, + outro_time = vg.time - w->state.outro_start_time; player__debugtext( 1, "outro time: %f / %f", outro_time, outro_length ); } } -VG_STATIC void player__walk_bind( player_instance *player ) -{ +VG_STATIC void player__walk_bind( player_instance *player ){ struct player_walk *w = &player->_walk; struct player_avatar *av = player->playeravatar; struct skeleton *sk = &av->sk; @@ -895,10 +952,15 @@ VG_STATIC void player__walk_bind( player_instance *player ) w->anim_intro = skeleton_get_anim( sk, "into_skate" ); } -VG_STATIC void player__walk_transition( player_instance *player, v3f angles ) -{ +VG_STATIC void player__walk_transition( player_instance *player ){ struct player_walk *w = &player->_walk; w->state.activity = k_walk_activity_air; + w->state.outro_type = k_walk_outro_none; + w->state.outro_start_time = 0.0; + w->state.jump_queued = 0; + w->state.jump_input_time = 0.0; + w->state.walk_timer = 0.0f; + w->state.step_phase = 0; v3f fwd = { 0.0f, 0.0f, 1.0f }; q_mulv( player->rb.q, fwd, fwd ); @@ -911,12 +973,10 @@ VG_STATIC void player__walk_transition( player_instance *player, v3f angles ) rb_update_transform( &player->rb ); } -VG_STATIC void player__walk_reset( player_instance *player, ent_spawn *rp ) -{ +VG_STATIC void player__walk_reset( player_instance *player, ent_spawn *rp ){ struct player_walk *w = &player->_walk; w->state.activity = k_walk_activity_air; w->state.outro_type = k_walk_outro_none; - w->state.outro_anim = NULL; w->state.outro_start_time = 0.0; }