X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_skate.c;h=1ad7231609e2f0dcc2b5abd1a2a94d9e03ce63b8;hb=e311bbe2fa903a7e2a922f202f389b799193195d;hp=4688702a68385f01c8d95b68bbc9dffcab278cdf;hpb=6ba5c35d106d749a1ebafbd3cbe18c3a02f781d3;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_skate.c b/player_skate.c index 4688702..1ad7231 100644 --- a/player_skate.c +++ b/player_skate.c @@ -9,9 +9,7 @@ #include "addon.h" static void player__skate_bind(void){ - struct player_avatar *av = localplayer.playeravatar; - struct skeleton *sk = &av->sk; - + struct skeleton *sk = &localplayer.skeleton; rb_update_transform( &localplayer.rb ); struct { struct skeleton_anim **anim; const char *name; } @@ -119,7 +117,7 @@ static int skate_grind_scansq( v3f pos, v3f dir, float r, support_max; v3f support_axis; - v3_cross( plane, localplayer.basis[1], support_axis ); + v3_cross( plane, (v3f){0,1,0}, support_axis ); v3_normalize( support_axis ); bh_iter it; @@ -156,9 +154,9 @@ static int skate_grind_scansq( v3f pos, v3f dir, float r, v3_cross( va, vb, normal ); sample->normal[0] = v3_dot( support_axis, normal ); - sample->normal[1] = v3_dot( localplayer.basis[1], normal ); + sample->normal[1] = normal[1]; sample->co[0] = v3_dot( support_axis, d ); - sample->co[1] = v3_dot( localplayer.basis[1], d ); + sample->co[1] = d[1]; v3_copy( normal, sample->normal3 ); /* normalize later if we want to us it */ @@ -181,8 +179,7 @@ too_many_samples: if( sample_count < 2 ) return 0; - v3f - average_direction, + v3f average_direction, average_normal; v2f min_co, max_co; @@ -227,14 +224,18 @@ too_many_samples: v3_copy( si->normal3, n0 ); v3_copy( sj->normal3, n1 ); v3_cross( n0, n1, dir ); + + if( v3_length2( dir ) <= 0.000001f ) + continue; + v3_normalize( dir ); /* make sure the directions all face a common hemisphere */ v3_muls( dir, vg_signf(v3_dot(dir,plane)), dir ); v3_add( average_direction, dir, average_direction ); - float yi = v3_dot( localplayer.basis[1], si->normal3 ), - yj = v3_dot( localplayer.basis[1], sj->normal3 ); + float yi = si->normal3[1], + yj = sj->normal3[1]; if( yi > yj ) v3_add( si->normal3, average_normal, average_normal ); else v3_add( sj->normal3, average_normal, average_normal ); @@ -286,18 +287,14 @@ static int create_jumps_to_hit_target( jump_info *jumps, v3f v0; v3_sub( target, localplayer.rb.co, v0 ); - m3x3_mulv( localplayer.invbasis, v0, v0 ); v3f ax; v3_copy( v0, ax ); ax[1] = 0.0f; v3_normalize( ax ); - v3f v_local; - m3x3_mulv( localplayer.invbasis, localplayer.rb.v, v_local ); - - v2f d = { v3_dot( ax, v0 ), v0[1] }, - v = { v3_dot( ax, v_local ), v_local[1] }; + v2f d = { v3_dot( ax, v0 ), v0[1] }, + v = { v3_dot( ax, localplayer.rb.v ), localplayer.rb.v[1] }; float a = atan2f( v[1], v[0] ), m = v2_length( v ), @@ -316,7 +313,6 @@ static int create_jumps_to_hit_target( jump_info *jumps, v3_muls( ax, cosf( a0 ) * m, inf->v ); inf->v[1] += sinf( a0 ) * m; - m3x3_mulv( localplayer.basis, inf->v, inf->v ); inf->land_dist = d[0] / (cosf(a0)*m); inf->gravity = gravity; @@ -329,7 +325,6 @@ static int create_jumps_to_hit_target( jump_info *jumps, v3_muls( ax, cosf( a1 ) * m, inf->v ); inf->v[1] += sinf( a1 ) * m; - m3x3_mulv( localplayer.basis, inf->v, inf->v ); inf->land_dist = d[0] / (cosf(a1)*m); inf->gravity = gravity; @@ -357,7 +352,7 @@ static void player__approximate_best_trajectory(void){ v3_normalize( axis ); /* at high slopes, Y component is low */ - float upness = v3_dot( localplayer.rb.to_world[1], localplayer.basis[1] ), + float upness = localplayer.rb.to_world[1][1], angle_begin = -(1.0f-fabsf( upness )), angle_end = 1.0f; @@ -407,17 +402,14 @@ static void player__approximate_best_trajectory(void){ inf->gravity = gravity; v3_copy( launch_v, inf->v ); - m3x3f basis; - m3x3_copy( localplayer.basis, basis ); - for( int i=1; i<=50; i++ ){ float t = (float)i * k_trace_delta; v3_muls( launch_v, t, co1 ); - v3_muladds( co1, basis[1], -0.5f * gravity * t*t, co1 ); + co1[1] += -0.5f * gravity * t*t; v3_add( launch_co, co1, co1 ); - float launch_vy = v3_dot( launch_v,basis[1] ); + float launch_vy = launch_v[1]; int search_for_grind = 1; if( grind_located ) search_for_grind = 0; @@ -438,7 +430,7 @@ static void player__approximate_best_trajectory(void){ for( int j=0; j<2; j++ ){ v3_muls( launch_v_bounds[j], t, bound[j] ); - v3_muladds( bound[j], basis[1], -0.5f*gravity*t*t, bound[j] ); + bound[j][1] += -0.5f*gravity*t*t; v3_add( launch_co, bound[j], bound[j] ); } @@ -457,14 +449,12 @@ static void player__approximate_best_trajectory(void){ if( search_for_grind ){ v3f ve; v3_copy( launch_v, ve ); - v3_muladds( ve, basis[1], -gravity * t, ve ); + ve[1] += -gravity * t; if( skate_grind_scansq( closest, ve, 0.5f, &grind ) ){ /* check alignment */ - v2f v0 = { v3_dot( ve, basis[0] ), - v3_dot( ve, basis[2] ) }, - v1 = { v3_dot( grind.dir, basis[0] ), - v3_dot( grind.dir, basis[2] ) }; + v2f v0 = { ve[0], ve[2] }, + v1 = { grind.dir[0], grind.dir[2] }; v2_normalize( v0 ); v2_normalize( v1 ); @@ -493,11 +483,9 @@ static void player__approximate_best_trajectory(void){ m4x3_mulv( gate->transport, co1, co1 ); m3x3_mulv( gate->transport, launch_v, launch_v); m4x3_mulv( gate->transport, launch_co, launch_co ); - m3x3_mul( gate->transport, basis, basis ); - if( gate->flags & k_ent_gate_nonlocal ){ + if( gate->flags & k_ent_gate_nonlocal ) trace_world = &world_static.instances[ gate->target ]; - } } } @@ -523,7 +511,7 @@ static void player__approximate_best_trajectory(void){ v3f ve; v3_copy( launch_v, ve ); - v3_muladds( ve, localplayer.basis[1], -gravity * t, ve ); + ve[1] += -gravity * t; inf->score = -v3_dot( ve, inf->n ); inf->land_dist = t + k_trace_delta * t1; @@ -570,13 +558,10 @@ static void player__approximate_best_trajectory(void){ v3_copy( jump->v, launch_v ); v3_copy( localplayer.rb.co, launch_co ); - - m3x3f basis; - m3x3_copy( localplayer.basis, basis ); float t = 0.05f * jump->land_dist; v3_muls( launch_v, t, co0 ); - v3_muladds( co0, basis[1], -0.5f * jump->gravity * t*t, co0 ); + co0[1] += -0.5f * jump->gravity * t*t; v3_add( launch_co, co0, co0 ); /* rough scan to make sure we dont collide with anything */ @@ -587,7 +572,7 @@ static void player__approximate_best_trajectory(void){ t *= jump->land_dist; v3_muls( launch_v, t, co1 ); - v3_muladds( co1, basis[1], -0.5f * jump->gravity * t*t, co1 ); + co1[1] += -0.5f * jump->gravity * t*t; v3_add( launch_co, co1, co1 ); float t1; @@ -608,8 +593,7 @@ static void player__approximate_best_trajectory(void){ /* determine score */ v3f ve; v3_copy( jump->v, ve ); - v3_muladds( ve, localplayer.basis[1], - -jump->gravity*jump->land_dist, ve ); + ve[1] += -jump->gravity*jump->land_dist; jump->score = -v3_dot( ve, grind.n ) * 0.9f; player_skate.possible_jumps[ player_skate.possible_jump_count ++ ] = @@ -680,9 +664,8 @@ invalidated_grind:; v3_zero( state->flip_axis ); } } - else{ - v3_copy( localplayer.basis[1], state->land_normal ); - } + else + v3_copy( (v3f){0,1,0}, state->land_normal ); } /* @@ -942,7 +925,7 @@ static void skate_apply_jump_model(void){ v3f jumpdir; /* Launch more up if alignment is up else improve velocity */ - float aup = v3_dot( localplayer.basis[1], localplayer.rb.to_world[1] ), + float aup = localplayer.rb.to_world[1][1], mod = 0.5f, dir = mod + fabsf(aup)*(1.0f-mod); @@ -1052,9 +1035,7 @@ static void skate_apply_cog_model(void){ /* Apply forces & intergrate */ v3_muladds( state->cog_v, F, -rb, state->cog_v ); - v3_muladds( state->cog_v, localplayer.basis[1], -9.8f * k_rb_delta, - state->cog_v ); - + state->cog_v[1] += -9.8f * k_rb_delta; v3_muladds( state->cog, state->cog_v, k_rb_delta, state->cog ); } @@ -1500,7 +1481,7 @@ static void skate_adjust_up_direction(void){ } else{ v3f avg; - v3_add( localplayer.rb.to_world[1], localplayer.basis[1], avg ); + v3_add( localplayer.rb.to_world[1], (v3f){0,1,0}, avg ); v3_normalize( avg ); v3_lerp( state->up_dir, avg, @@ -1559,7 +1540,6 @@ static void skate_grind_decay( struct grind_info *inf, float strength ){ static void skate_grind_truck_apply( float sign, struct grind_info *inf, float strength ){ struct player_skate_state *state = &player_skate.state; - /* REFACTOR */ v3f ra = { 0.0f, -k_board_radius, sign * k_board_length }; v3f raw, wsp; @@ -2047,11 +2027,9 @@ static void player__skate_update(void){ if( world->water.enabled ){ if( localplayer.rb.co[1]+0.25f < world->water.height ){ -#if 0 player__networked_sfx( k_player_subsystem_walk, 32, k_player_walk_soundeffect_splash, localplayer.rb.co, 1.0f ); -#endif player__skate_kill_audio(); player__dead_transition(); return; @@ -2105,9 +2083,7 @@ static void player__skate_update(void){ } } min_dist -= 0.2f; - float vy = v3_dot( localplayer.basis[1], localplayer.rb.v ); - vy = vg_maxf( 0.0f, vy ); - + float vy = vg_maxf( 0.0f, localplayer.rb.v[1] ); slap = vg_clampf( (min_dist/0.5f) + vy, 0.0f, 1.0f )*0.3f; } state->slap = vg_lerpf( state->slap, slap, 10.0f*k_rb_delta ); @@ -2308,9 +2284,7 @@ begin_collision:; } rb_update_transform( &localplayer.rb ); - v3_muladds( localplayer.rb.v, localplayer.basis[1], - -state->gravity_bias * player_skate.substep_delta, - localplayer.rb.v ); + localplayer.rb.v[1] += -state->gravity_bias * player_skate.substep_delta; player_skate.substep -= player_skate.substep_delta; @@ -2415,7 +2389,7 @@ begin_collision:; } /* yes, we are currently rebuilding mass matrices every frame. too bad! */ - v3f extent = { k_board_width, 0.1f, k_board_length }; + v3f extent = { k_board_width*10.0f, 0.1f, k_board_length }; float ex2 = k_board_interia*extent[0]*extent[0], ey2 = k_board_interia*extent[1]*extent[1], ez2 = k_board_interia*extent[2]*extent[2]; @@ -2595,6 +2569,27 @@ begin_collision:; } else if( stick_frames == 0 ){ /* TODO: EXIT SOUNDS */ } + + if( (state->activity_prev < k_skate_activity_grind_any) && + (state->activity >= k_skate_activity_grind_any) ){ + state->velocity_limit = v3_length( localplayer.rb.v )*1.0f; + state->grind_y_start = localplayer.rb.co[1]; + } + + if( state->activity >= k_skate_activity_grind_any ){ + f32 dy = localplayer.rb.co[1] - state->grind_y_start; + if( dy < 0.0f ){ + state->velocity_limit += -dy*0.2f; + } + state->grind_y_start = localplayer.rb.co[1]; + + + f32 speed_end = v3_length( localplayer.rb.v ); + if( speed_end > state->velocity_limit ){ + v3_muls( localplayer.rb.v, state->velocity_limit/speed_end, + localplayer.rb.v ); + } + } } static void player__skate_im_gui(void){ @@ -2741,6 +2736,7 @@ static void player__skate_animate(void){ animator->grind_balance = vg_lerpf( animator->grind_balance, grind_frame, 5.0f*vg.time_delta ); + animator->activity = state->activity; /* pushing */ animator->push_time = vg.time - state->start_push; @@ -2897,11 +2893,11 @@ static void player__skate_animate(void){ } else q_identity( animator->qfixuptotal ); rb_extrapolate( &localplayer.rb, animator->root_co, animator->root_q ); + v3_copy( localplayer.rb.v, animator->root_v ); } static void player__skate_pose( void *_animator, player_pose *pose ){ - struct player_avatar *av = localplayer.playeravatar; - struct skeleton *sk = &av->sk; + struct skeleton *sk = &localplayer.skeleton; struct player_skate_animator *animator = _animator; pose->type = k_player_pose_type_ik; @@ -2983,14 +2979,14 @@ static void player__skate_pose( void *_animator, player_pose *pose ){ skeleton_lerp_pose( sk, ground_pose, air_pose, animator->fly, pose->keyframes ); - mdl_keyframe *kf_board = &pose->keyframes[av->id_board-1], - *kf_foot_l = &pose->keyframes[av->id_ik_foot_l-1], - *kf_foot_r = &pose->keyframes[av->id_ik_foot_r-1], - *kf_knee_l = &pose->keyframes[av->id_ik_knee_l-1], - *kf_knee_r = &pose->keyframes[av->id_ik_knee_r-1], - *kf_hip = &pose->keyframes[av->id_hip-1], - *kf_wheels[] = { &pose->keyframes[av->id_wheel_r-1], - &pose->keyframes[av->id_wheel_l-1] }; + mdl_keyframe *kf_board = &pose->keyframes[localplayer.id_board-1], + *kf_foot_l = &pose->keyframes[localplayer.id_ik_foot_l-1], + *kf_foot_r = &pose->keyframes[localplayer.id_ik_foot_r-1], + *kf_knee_l = &pose->keyframes[localplayer.id_ik_knee_l-1], + *kf_knee_r = &pose->keyframes[localplayer.id_ik_knee_r-1], + *kf_hip = &pose->keyframes[localplayer.id_hip-1], + *kf_wheels[] = { &pose->keyframes[localplayer.id_wheel_r-1], + &pose->keyframes[localplayer.id_wheel_l-1] }; mdl_keyframe grind_pose[32]; @@ -3006,11 +3002,11 @@ static void player__skate_pose( void *_animator, player_pose *pose ){ float add_grab_mod = 1.0f - animator->fly; /* additive effects */ - u32 apply_to[] = { av->id_hip, - av->id_ik_hand_l, - av->id_ik_hand_r, - av->id_ik_elbow_l, - av->id_ik_elbow_r }; + u32 apply_to[] = { localplayer.id_hip, + localplayer.id_ik_hand_l, + localplayer.id_ik_hand_r, + localplayer.id_ik_elbow_l, + localplayer.id_ik_elbow_r }; float apply_rates[] = { 1.0f, 0.75f, @@ -3025,11 +3021,11 @@ static void player__skate_pose( void *_animator, player_pose *pose ){ /* angle 'correction' */ v3f origin; - v3_add( av->sk.bones[av->id_hip].co, kf_hip->co, origin ); + v3_add( sk->bones[localplayer.id_hip].co, kf_hip->co, origin ); for( int i=0; ikeyframes[apply_to[i]-1]; - keyframe_rotate_around( kf, origin, av->sk.bones[apply_to[i]].co, + keyframe_rotate_around( kf, origin, sk->bones[apply_to[i]].co, animator->qfixuptotal ); } @@ -3091,14 +3087,13 @@ static void player__skate_pose( void *_animator, player_pose *pose ){ q_normalize( kf_wheels[i]->q ); } -#if 0 { mdl_keyframe - *kf_head = &pose->keyframes[av->id_head-1], - *kf_elbow_l = &pose->keyframes[av->id_ik_elbow_l-1], - *kf_elbow_r = &pose->keyframes[av->id_ik_elbow_r-1], - *kf_hand_l = &pose->keyframes[av->id_ik_hand_l-1], - *kf_hand_r = &pose->keyframes[av->id_ik_hand_r-1]; + *kf_head = &pose->keyframes[localplayer.id_head-1], + *kf_elbow_l = &pose->keyframes[localplayer.id_ik_elbow_l-1], + *kf_elbow_r = &pose->keyframes[localplayer.id_ik_elbow_r-1], + *kf_hand_l = &pose->keyframes[localplayer.id_ik_hand_l-1], + *kf_hand_r = &pose->keyframes[localplayer.id_ik_hand_r-1]; float warble = perlin1d( vg.time, 2.0f, 2, 300 ); warble *= vg_maxf(animator->grind, fabsf(animator->weight)) * 0.3f; @@ -3108,31 +3103,85 @@ static void player__skate_pose( void *_animator, player_pose *pose ){ v3f origin = {0.0f,0.2f,0.0f}; keyframe_rotate_around( kf_hand_l, origin, - av->sk.bones[av->id_ik_hand_l].co, qrot ); + sk->bones[localplayer.id_ik_hand_l].co, qrot ); keyframe_rotate_around( kf_hand_r, origin, - av->sk.bones[av->id_ik_hand_r].co, qrot ); + sk->bones[localplayer.id_ik_hand_r].co, qrot ); keyframe_rotate_around( kf_hip, origin, - av->sk.bones[av->id_hip].co, qrot ); + sk->bones[localplayer.id_hip].co, qrot ); keyframe_rotate_around( kf_elbow_r, origin, - av->sk.bones[av->id_ik_elbow_r].co, qrot ); + sk->bones[localplayer.id_ik_elbow_r].co, qrot ); keyframe_rotate_around( kf_elbow_l, origin, - av->sk.bones[av->id_ik_elbow_l].co, qrot ); + sk->bones[localplayer.id_ik_elbow_l].co, qrot ); q_inv( qrot, qrot ); q_mul( qrot, kf_head->q, kf_head->q ); q_normalize( kf_head->q ); } -#endif +} + +static void player__skate_effects( void *_animator, m4x3f *final_mtx, + struct player_board *board, + struct player_effects_data *effect_data ){ + + struct skeleton *sk = &localplayer.skeleton; + struct player_skate_animator *animator = _animator; + + if( animator->grind > 0.5f ){ + v3f vp0, vp1, vpc; + if( board ){ + v3_copy((v3f){0.0f,0.02f, board->truck_positions[0][2]}, vp1 ); + v3_copy((v3f){0.0f,0.02f, board->truck_positions[1][2]}, vp0 ); + } + else{ + v3_zero( vp0 ); + v3_zero( vp1 ); + } + + v3f *board_mtx = final_mtx[ localplayer.id_board ]; + m4x3_mulv( board_mtx, vp0, vp0 ); + m4x3_mulv( board_mtx, vp1, vp1 ); + v3_add( vp0, vp1, vpc ); + v3_muls( vpc, 0.5f, vpc ); + + int back = 0, front = 0, mid = 0; + + if( animator->activity == k_skate_activity_grind_5050 ){ + back = 1; + front = 1; + } + else if( animator->activity == k_skate_activity_grind_back50 ){ + back = 1; + } + else if( animator->activity == k_skate_activity_grind_front50 ){ + front = 1; + } + else if( animator->activity == k_skate_activity_grind_boardslide ){ + mid = 1; + } + + if( back ){ + effect_spark_apply( &effect_data->spark, vp0, + animator->root_v, vg.time_delta ); + } + + if( front ){ + effect_spark_apply( &effect_data->spark, vp1, + animator->root_v, vg.time_delta ); + } + + if( mid ){ + effect_spark_apply( &effect_data->spark, vpc, + animator->root_v, vg.time_delta ); + } + } } static void player__skate_post_animate(void){ - struct player_avatar *av = localplayer.playeravatar; struct player_skate_state *state = &player_skate.state; - localplayer.cam_velocity_influence = 1.0f; v3f head = { 0.0f, 1.8f, 0.0f }; - m4x3_mulv( localplayer.final_mtx[ av->id_head ], + m4x3_mulv( localplayer.final_mtx[ localplayer.id_head ], head, state->head_position ); m4x3_mulv( localplayer.rb.to_local, state->head_position, state->head_position ); @@ -3186,21 +3235,6 @@ static void player__skate_clear_mechanics(void){ v3_zero( player_skate.weight_distribution ); } -static void player__skate_reset( ent_spawn *rp ){ - struct player_skate_state *state = &player_skate.state; - v3_zero( localplayer.rb.v ); - v4_copy( rp->transform.q, localplayer.rb.q ); - - state->activity = k_skate_activity_air; - state->activity_prev = k_skate_activity_air; - - player__skate_clear_mechanics(); - player__skate_reset_animator(); - - v3_zero( state->head_position ); - state->head_position[1] = 1.8f; -} - #include "network_compression.h" static void player__skate_animator_exchange( bitpack_ctx *ctx, void *data ){ @@ -3250,6 +3284,8 @@ static void player__skate_animator_exchange( bitpack_ctx *ctx, void *data ){ bitpack_qf32( ctx, 16, 0.0f, 120.0f, &animator->push_time ); bitpack_qf32( ctx, 16, 0.0f, 120.0f, &animator->jump_time ); + bitpack_qv3f( ctx, 16, -100.0f, 100.0f, animator->root_v ); + bitpack_bytes( ctx, 1, &animator->activity ); } static void player__skate_sfx_oneshot( u8 id, v3f pos, f32 volume ){