X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_walk.c;h=815e4b4a70f81ade5c718023fa6ec1cd82b719a5;hb=da1a0abc0c32b4283746949ba9a135a7d3c0b82c;hp=7f857fed8d1cc7c82224a8d792e905c0762f8408;hpb=01e2535f8daaab0e3d46dcc61a08a9268babd47c;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_walk.c b/player_walk.c index 7f857fe..815e4b4 100644 --- a/player_walk.c +++ b/player_walk.c @@ -2,6 +2,8 @@ #define PLAYER_WALK_C #include "player.h" +#include "input.h" +#include "audio.h" VG_STATIC void player_walk_drop_in_vector( player_instance *player, v3f vec ) { @@ -57,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 ); @@ -68,6 +71,7 @@ VG_STATIC void player_walk_generic_to_skate( player_instance *player, VG_STATIC void player_walk_drop_in_to_skate( player_instance *player ) { + player->immobile = 0; player->subsystem = k_player_subsystem_skate; struct player_walk *w = &player->_walk; @@ -75,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 ); @@ -85,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 ); } @@ -118,7 +123,7 @@ VG_STATIC void player_walk_drop_in_overhang_transform( player_instance *player, VG_STATIC int player_walk_scan_for_drop_in( player_instance *player ) { struct player_walk *w = &player->_walk; - world_instance *world = get_active_world(); + world_instance *world = world_current_instance(); v3f dir, center; q_mulv( player->rb.q, (v3f){0.0f,0.0f,1.0f}, dir ); @@ -144,7 +149,7 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player ) if( ray_world( world, pos, ray_dir, ray ) ) { 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 ++; } @@ -153,25 +158,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, @@ -189,8 +190,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,7 +222,7 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player ) if( ray_world( world, va, v0, &ray ) ) { 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; } @@ -231,7 +231,7 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player ) if( ray_world( world, vb, v0, &ray ) ) { 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; } @@ -248,20 +248,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( w->state.activity != k_walk_activity_immobile ) - player_look( player, player->angles ); + if( !player->immobile ) + player_look( player->angles, skaterift.time_rate ); + + if( w->state.outro_type ){ + struct skeleton_anim *anim = + player_walk_outro_anim( player, w->state.outro_type ); - 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; + 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 ); } @@ -273,20 +287,26 @@ 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; } } - else if( vg_input_button_down( player->input_use ) ){ + else if( button_down( k_srbind_use ) && !player->immobile ){ if( v3_dist2( player->rb.co, gzoomer.obj.rb.co ) <= 4.0f*4.0f ){ player->subsystem = k_player_subsystem_drive; } else{ + 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; - w->state.activity = k_walk_activity_immobile; + player->immobile = 1; struct player_avatar *av = player->playeravatar; m4x3_mulv( av->sk.final_mtx[ av->id_ik_foot_r ], @@ -295,7 +315,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; @@ -305,21 +324,22 @@ 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; } } } + else if( button_down( k_srbind_jump ) && !player->immobile ){ + w->state.jump_queued = 1; + w->state.jump_input_time = vg.time; + } } -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; @@ -334,8 +354,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 ); @@ -351,14 +370,24 @@ 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_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(); + + if( world->water.enabled ){ + if( player->rb.co[1]+0.4f < world->water.height ){ + audio_oneshot_3d( &audio_splash, player->rb.co, 40.0f, 1.0f ); + player__dead_transition( player ); + return; + } + } enum walk_activity prev_state = w->state.activity; - if( w->state.activity == k_walk_activity_immobile ) + if( player->immobile ) return; w->collider.height = 2.0f; @@ -368,28 +397,23 @@ 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; float yaw = player->angles[0]; - v3f forward_dir = { sinf(yaw), 0.0f, -cosf(yaw) }; - v3f right_dir = { -forward_dir[2], 0.0f, forward_dir[0] }; + v3f forward_dir = { -sinf(yaw), 0.0f, cosf(yaw) }; + v3f right_dir = { forward_dir[2], 0.0f, -forward_dir[0] }; m3x3_mulv( player->basis, forward_dir, forward_dir ); m3x3_mulv( player->basis, right_dir, right_dir ); + v2f steer; + joystick_state( k_srjoystick_steer, steer ); - v2f walk = { player->input_walkh->axis.value, - player->input_walkv->axis.value }; - - if( v2_length2(walk) > 0.001f ) - v2_normalize_clamp( walk ); - - w->move_speed = v2_length( walk ); - world_instance *world = get_active_world(); + w->move_speed = v2_length( steer ); /* * Collision detection @@ -430,16 +454,17 @@ VG_STATIC void player__walk_update( player_instance *player ) */ float accel_speed = 0.0f, nominal_speed = 0.0f; v3f movedir; - v3_muls( right_dir, walk[0], movedir ); - v3_muladds( movedir, forward_dir, walk[1], movedir ); + + v3_muls( right_dir, steer[0], movedir ); + v3_muladds( movedir, forward_dir, steer[1], movedir ); if( w->state.activity == k_walk_activity_ground ){ v3_normalize( surface_avg ); v3f tx, ty; - rb_tangent_basis( surface_avg, tx, ty ); + v3_tangent_basis( surface_avg, tx, ty ); - if( v2_length2(walk) > 0.001f ){ + if( v2_length2(steer) > 0.001f ){ /* clip movement to the surface */ float d = v3_dot(surface_avg,movedir); v3_muladds( movedir, surface_avg, -d, movedir ); @@ -449,14 +474,19 @@ VG_STATIC void player__walk_update( player_instance *player ) nominal_speed = k_walkspeed; /* jump */ - if( player->input_jump->button.value ){ - float d = v3_dot( player->basis[1], player->rb.v ); - v3_muladds( player->rb.v, player->basis[1], -d, player->rb.v ); - v3_muladds( player->rb.v, player->basis[1], 5.0f, player->rb.v ); - w->state.activity = k_walk_activity_air; - prev_state = k_walk_activity_air; - accel_speed = k_walk_air_accel; - nominal_speed = k_airspeed; + if( w->state.jump_queued ){ + w->state.jump_queued = 0; + + f32 t = vg.time - w->state.jump_input_time; + if( t < PLAYER_JUMP_EPSILON ){ + float d = v3_dot( player->basis[1], player->rb.v ); + v3_muladds( player->rb.v, player->basis[1], -d, player->rb.v ); + v3_muladds( player->rb.v, player->basis[1], 5.0f, player->rb.v ); + w->state.activity = k_walk_activity_air; + prev_state = k_walk_activity_air; + accel_speed = k_walk_air_accel; + nominal_speed = k_airspeed; + } } else{ player_friction( player->rb.v ); @@ -467,7 +497,7 @@ VG_STATIC void player__walk_update( player_instance *player ) nominal_speed = k_airspeed; } - if( v2_length2(walk) > 0.001f ){ + if( v2_length2( steer ) > 0.001f ){ player_accelerate( player->rb.v, movedir, nominal_speed, accel_speed ); v3_normalize( movedir ); } @@ -534,7 +564,7 @@ VG_STATIC void player__walk_update( player_instance *player ) 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 @@ -563,7 +593,7 @@ VG_STATIC void player__walk_update( player_instance *player ) 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 ); } } @@ -578,30 +608,21 @@ 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; m3x3_copy( player->rb.to_world, mtx ); v3_add( player->rb.co, player->basis[1], mtx[3] ); - float substep = vg_clampf( vg.accumulator / k_rb_delta, 0.0f, 1.0f ); + 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 */ @@ -617,7 +638,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 ); @@ -625,7 +646,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 ); @@ -639,190 +660,208 @@ 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(); if( w->surface == k_surface_prop_concrete ){ audio_oneshot_3d( - &audio_footsteps[rand()%vg_list_size(audio_footsteps)], + &audio_footsteps[vg_randu32()%vg_list_size(audio_footsteps)], player->rb.co, 40.0f, 1.0f ); } else if( w->surface == k_surface_prop_grass ){ audio_oneshot_3d( - &audio_footsteps_grass[rand()%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[rand()%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 * - (1.0f + player->input_walk->button.value*0.5f), - 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 ); + q_mul( final_q, animator->root_q, animator->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 ); - - 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; } @@ -830,9 +869,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], @@ -844,7 +881,6 @@ VG_STATIC void player__walk_im_gui( player_instance *player ) (const char *[]){ "k_walk_activity_air", "k_walk_activity_ground", "k_walk_activity_sleep", - "k_walk_activity_immobile", "k_walk_activity_lockedmove" } [w->state.activity] ); player__debugtext( 1, "surface: %s\n", @@ -855,16 +891,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; @@ -878,8 +915,7 @@ 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; @@ -894,12 +930,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; }