X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;ds=inline;f=player_walk.c;h=0503f48fde51853c300f8cccfaf868ca7c42d2b1;hb=b06394c241991d85211af98ed0a7f4d730fa13d4;hp=0d6f8738737996210493c96ad3404ea4a965629b;hpb=33de52d9660ab86caafdd0ae4abb496dbc072778;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_walk.c b/player_walk.c index 0d6f873..0503f48 100644 --- a/player_walk.c +++ b/player_walk.c @@ -3,61 +3,77 @@ #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 ) - { - v[0] = -sinf( -w->state.angles[0] ); - v[1] = 0.0f; - v[2] = -cosf( -w->state.angles[0] ); - v3_muls( v, 1.6f, v ); - } + 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; + 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 ); - - rb_update_transform( &player->rb ); + v3_copy( init_velocity, player->cam_velocity_smooth ); } VG_STATIC int player_walk_scan_for_drop_in( player_instance *player ) @@ -65,10 +81,7 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player ) struct player_walk *w = &player->_walk; v3f dir, center; - dir[0] = sinf( w->state.heading_angle ); - dir[1] = 0.0f; - dir[2] = cosf( w->state.heading_angle ); - + q_mulv( player->rb.q, (v3f){0.0f,0.0f,1.0f}, dir ); v3_muladds( player->rb.co, player->rb.to_world[1], -1.0f, center ); ray_hit samples[20]; @@ -141,15 +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 ); + 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 { @@ -163,7 +169,9 @@ VG_STATIC int player_walk_scan_for_drop_in( player_instance *player ) VG_STATIC void player__walk_pre_update( player_instance *player ) { struct player_walk *w = &player->_walk; - player_look( player, w->state.angles ); + + if( w->state.activity != k_walk_activity_immobile ) + player_look( player, player->angles ); if( w->state.outro_anim ) { @@ -176,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; } @@ -189,19 +197,15 @@ 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; - v3_copy( player->cam.pos, player->follow_pos ); - v3_copy( player->cam.angles, player->follow_angles ); 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 = w->state.heading_angle; + + w->state.drop_in_start_angle = player_get_heading_yaw( player ); w->state.drop_in_angle = atan2f( w->state.drop_in_normal[0], w->state.drop_in_normal[2] ); @@ -217,8 +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; - v3_copy( player->cam.pos, player->follow_pos ); - v3_copy( player->cam.angles, player->follow_angles ); return; } } @@ -282,7 +284,7 @@ VG_STATIC void player__walk_update( player_instance *player ) rb_ct manifold[64]; int len; - float yaw = w->state.angles[0]; + 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] }; @@ -494,13 +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 */ - v3f fwd_dir = { cosf(w->state.angles[0]), - 0.0f, - sinf(w->state.angles[0])}; - m3x3_mulv( gate->transport, fwd_dir, fwd_dir ); - w->state.angles[0] = atan2f( fwd_dir[2], fwd_dir[0] ); - w->state_gate_storage = w->state; player__pass_gate( player, gate ); } @@ -526,7 +521,10 @@ VG_STATIC void player__walk_post_update( player_instance *player ) xy_speed[1] = 0.0f; if( v3_length2( xy_speed ) > 0.1f * 0.1f ) - w->state.heading_angle = atan2f( player->rb.v[0], player->rb.v[2] ); + { + float a = atan2f( player->rb.v[0], player->rb.v[2] ); + q_axis_angle( player->rb.q, (v3f){0.0f,1.0f,0.0f}, a ); + } vg_line_pt3( w->state.drop_in_target, 0.1f, VG__GREEN ); v3f p1; @@ -538,9 +536,11 @@ VG_STATIC void player__walk_post_update( player_instance *player ) 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 ); - p1[0] = sinf( w->state.heading_angle ); + + float a = player_get_heading_yaw( player ); + p1[0] = sinf( a ); p1[1] = 0.0f; - p1[2] = cosf( w->state.heading_angle ); + p1[2] = cosf( a ); v3_add( player->rb.co, p1, p1 ); vg_line( player->rb.co, p1, VG__PINK ); @@ -607,7 +607,7 @@ VG_STATIC void player__walk_animate( player_instance *player, /* Create transform */ rb_extrapolate( &player->rb, dest->root_co, dest->root_q ); - float walk_yaw = w->state.heading_angle; + float walk_yaw = player_get_heading_yaw( player ); if( w->state.outro_anim ) { @@ -636,7 +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 ); - w->state.heading_angle = walk_yaw; v3_lerp( w->state.drop_in_start, w->state.drop_in_target, step_t, player->rb.co ); @@ -656,35 +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; + + q_axis_angle( final_q, axis, a ); + q_mul( final_q, dest->root_q, dest->root_q ); - float a = acosf( w->state.drop_in_normal[1] ) * dop_t; + float l = dop_t * 0.5f, + heading_angle = w->state.drop_in_angle; - q_axis_angle( final_q, axis, a ); - q_mul( final_q, dest->root_q, dest->root_q ); + v3f overhang; + overhang[0] = sinf( heading_angle ) * l; + overhang[1] = 0.28f * l; + overhang[2] = cosf( heading_angle ) * l; - float l = dop_t * 0.7f; + q_mulv( final_q, overhang, overhang ); - v3f overhang; - overhang[0] = sinf( w->state.heading_angle ) * l; - overhang[1] = 0.28f * l; - overhang[2] = cosf( w->state.heading_angle ) * l; + 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 ); - m3x3f tmp; - q_m3x3( final_q, tmp ); - m3x3_mulv( tmp, 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 ); + 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 @@ -703,33 +713,6 @@ VG_STATIC void player__walk_post_animate( player_instance *player ) struct player_walk *w = &player->_walk; struct player_avatar *av = player->playeravatar; - /* 3RD */ - m3x3f angles; - euler_m3x3( w->state.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 ); - - 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 ); - - /* FIXME: Organize this. Its int wrong fucking place */ - v3f vp0 = {0.0f,0.1f, 0.6f}, - vp1 = {0.0f,0.1f,-0.6f}; - if( w->state.outro_anim ) { float outro_length = (float)w->state.outro_anim->length / @@ -737,26 +720,10 @@ VG_STATIC void player__walk_post_animate( player_instance *player ) 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; - player_vector_angles( fpv_angles, player->rb.v, 1.0f, 0.25f ); - v3_lerp( player->fpv_angles,fpv_angles, outro_t, player->fpv_angles ); + player->cam_velocity_influence = outro_t; } else - { - player->cam_angles_override_strength = 1.0f; - player->cam_position_override_strength = 1.0f; - } - - 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 ); + player->cam_velocity_influence = 0.0f; } @@ -802,8 +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; - v3_copy( angles, w->state.angles ); 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 */