+void player__skate_animate(void){
+ struct player_skate_state *state = &player_skate.state;
+ struct player_skate_animator *animator = &player_skate.animator;
+
+ /* Head */
+ float kheight = 2.0f,
+ kleg = 0.6f;
+
+ v3_zero( animator->offset );
+
+ v3f cog_local, cog_ideal;
+ m4x3_mulv( localplayer.rb.to_local, state->cog, cog_local );
+
+ v3_copy( state->up_dir, cog_ideal );
+ v3_normalize( cog_ideal );
+ m3x3_mulv( localplayer.rb.to_local, cog_ideal, cog_ideal );
+
+ v3_sub( cog_ideal, cog_local, animator->offset );
+
+ v3_muls( animator->offset, 4.0f, animator->offset );
+ animator->offset[1] *= -1.0f;
+
+ float curspeed = v3_length( localplayer.rb.v ),
+ kickspeed = vg_clampf( curspeed*(1.0f/40.0f), 0.0f, 1.0f ),
+ kicks = (vg_randf64(&vg.rand)-0.5f)*2.0f*kickspeed,
+ sign = vg_signf( kicks );
+
+ animator->wobble[0] = vg_lerpf( animator->wobble[0], kicks*kicks*sign,
+ 6.0f*vg.time_delta);
+ animator->wobble[1] = vg_lerpf( animator->wobble[1], animator->wobble[0],
+ 2.4f*vg.time_delta);
+
+ animator->offset[0] *= 0.26f;
+ animator->offset[0] += animator->wobble[1]*3.0f;
+
+ animator->offset[1] *= -0.3f;
+ animator->offset[2] *= 0.01f;
+
+ animator->offset[0]=vg_clampf(animator->offset[0],-0.8f,0.8f)*
+ (1.0f-fabsf(animator->slide)*0.9f);
+ animator->offset[1]=vg_clampf(animator->offset[1],-0.5f,0.0f);
+
+ v3f cam_offset;
+ v3_mul( animator->offset, (v3f){1.0f,0.3f,1.0f}, cam_offset );
+
+ /* localized vectors */
+ m4x3_mulv( localplayer.rb.to_local, state->cog, animator->local_cog );
+
+ /*
+ * Animation blending
+ * ===========================================
+ */
+
+ /* sliding */
+ {
+ float desired = 0.0f;
+ if( state->activity == k_skate_activity_ground )
+ desired = vg_clampf( vg_maxf(fabsf( state->slip ),
+ fabsf( state->skid ) ), 0.0f, 1.0f );
+
+ animator->slide = vg_lerpf( animator->slide, desired, 2.4f*vg.time_delta);
+
+ f32 dirx = 0.0f;
+ if( fabsf(state->slip) > fabsf(dirx) ) dirx = state->slip;
+ if( fabsf(state->skid) > fabsf(dirx) ) dirx = state->skid;
+ if( fabsf( dirx ) > 0.025f ) dirx = vg_signf( dirx );
+ dirx = vg_signf( state->slip );
+ vg_slewf( &animator->x, dirx, 2.6f*vg.time_delta );
+ }
+
+ cam_offset[0] += animator->slide * -animator->x;
+ v3_copy( cam_offset, localplayer.cam_control.tpv_offset_extra );
+
+ /* movement information */
+ int iair = state->activity <= k_skate_activity_air_to_grind;
+
+ float dirz = state->reverse > 0.0f? 0.0f: 1.0f,
+ fly = iair? 1.0f: 0.0f,
+ wdist= player_skate.weight_distribution[2] / k_board_length;
+
+ if( state->activity >= k_skate_activity_grind_any )
+ wdist = 0.0f;
+
+ animator->z = vg_lerpf( animator->z, dirz, 2.4f*vg.time_delta );
+ animator->skid = state->skid;
+ animator->fly = vg_lerpf( animator->fly, fly, 3.4f*vg.time_delta );
+ animator->weight = vg_lerpf( animator->weight, wdist, 9.0f*vg.time_delta );
+
+ float stand = 1.0f - vg_clampf( curspeed * 0.03f, 0.0f, 1.0f );
+ animator->stand = vg_lerpf( animator->stand, stand, 6.0f*vg.time_delta );
+ animator->reverse = state->reverse;
+
+ if( fabsf(state->slip) > 0.3f ){
+ f32 slide_x = v3_dot(localplayer.rb.v, localplayer.rb.to_world[0]);
+ state->delayed_slip_dir = vg_signf(slide_x);
+ }
+
+ /* grinding */
+ f32 grind=state->activity >= k_skate_activity_grind_any? 1.0f: 0.0f;
+ animator->grind = vg_lerpf( animator->grind, grind, 5.0f*vg.time_delta );
+
+ f32 grind_frame = 0.5f;
+
+ if( state->activity == k_skate_activity_grind_front50 )
+ grind_frame = 0.0f;
+ else if( state->activity == k_skate_activity_grind_back50 )
+ grind_frame = 1.0f;
+
+ animator->grind_balance = vg_lerpf( animator->grind_balance, grind_frame,
+ 5.0f*vg.time_delta );
+ animator->activity = state->activity;
+ animator->surface = player_skate.surface;
+
+ /* pushing */
+ animator->push_time = vg.time - state->start_push;
+ animator->push = vg_lerpf( animator->push,
+ (vg.time - state->cur_push) < 0.125,
+ 6.0f*vg.time_delta );
+
+ /* jumping */
+ animator->jump_charge = state->jump_charge;
+ animator->jump = vg_lerpf( animator->jump, animator->jump_charge,
+ 8.4f*vg.time_delta );
+
+ /* trick setup */
+ animator->jump_dir = state->jump_dir;
+ f32 jump_start_frame = 14.0f/30.0f;
+ animator->jump_time = animator->jump_charge * jump_start_frame;
+ f32 jump_frame = (vg.time - state->jump_time) + jump_start_frame;
+ if( jump_frame >= jump_start_frame && jump_frame <= (40.0f/30.0f) )
+ animator->jump_time = jump_frame;
+
+ /* trick */
+ float jump_t = vg.time-state->jump_time;
+ float k=17.0f;
+ float h = k*jump_t;
+ float extra = h*exp(1.0-h) * (state->jump_dir?1.0f:-1.0f);
+ extra *= state->slap * 4.0f;
+
+ v3_add( state->trick_euler, state->trick_residuald,
+ animator->board_euler );
+ v3_muls( animator->board_euler, VG_TAUf, animator->board_euler );
+
+ animator->board_euler[0] *= 0.5f;
+ animator->board_euler[1] += extra;
+ animator->trick_type = state->trick_type;
+
+ /* board lean */
+ f32 lean1, lean2 = animator->steer[0] * animator->reverse * -0.36f,
+ lean;
+
+ lean1 = animator->slide * animator->delayed_slip_dir;
+ if( fabsf(lean1)>fabsf(lean2) ) lean = lean1;
+ else lean = lean2;
+
+ if( ((int)roundf(animator->board_euler[0]/VG_PIf)) % 2 ) lean = -lean;
+ lean = vg_clampf( lean, -1.0f, 1.0f );
+ animator->board_lean =
+ vg_lerpf(animator->board_lean, lean, vg.time_delta*18.0f);
+
+ /* feet placement */
+ struct player_board *board =
+ addon_cache_item_if_loaded( k_addon_type_board,
+ localplayer.board_view_slot );
+ if( board ){
+ if( animator->weight > 0.0f ){
+ animator->foot_offset[0] =
+ board->truck_positions[k_board_truck_back][2]+0.3f;
+ }
+ else{
+ animator->foot_offset[1] =
+ board->truck_positions[k_board_truck_front][2]-0.3f;
+ }
+ }
+
+ f32 slapm = vg_maxf( 1.0f-v3_length2( state->trick_vel ), 0.0f );
+ animator->slap = state->slap;
+ animator->subslap = vg_lerpf( animator->subslap, slapm,
+ vg.time_delta*10.0f );
+
+#if 0
+ f32 l = ((state->activity < k_skate_activity_ground) &&
+ v3_length2(state->trick_vel) > 0.1f )? 1: 0;
+ animator->trick_foot = vg_lerpf( animator->trick_foot, l,
+ 8.4f*vg.time_delta );
+#endif
+
+ animator->trick_foot = vg_exp_impulse( state->trick_time, 5.0f );
+
+ /* grab */
+ v2f grab_input;
+ joystick_state( k_srjoystick_grab, grab_input );
+ v2_add( state->grab_mouse_delta, grab_input, grab_input );
+
+ if( v2_length2( grab_input ) <= 0.001f ) grab_input[0] = -1.0f;
+ else v2_normalize_clamp( grab_input );
+ v2_lerp( animator->grab, grab_input, 2.4f*vg.time_delta, animator->grab );
+ animator->grabbing = state->grabbing;
+
+ /* steer */
+ v2f steer;
+ joystick_state( k_srjoystick_steer, steer );
+ animator->airdir = vg_lerpf( animator->airdir,
+ -steer[0], 2.4f*vg.time_delta );
+
+ animator->steer[0] = steer[0];
+ animator->steer[1] = vg_lerpf( animator->steer[1],
+ steer[0], 4.0f*vg.time_delta );
+
+
+ /* flip angle */
+ if( (state->activity <= k_skate_activity_air_to_grind) &&
+ (fabsf(state->flip_rate) > 0.01f) ){
+ float substep = vg.time_fixed_extrapolate;
+ float t = state->flip_time+state->flip_rate*substep*vg.time_fixed_delta;
+ sign = vg_signf( t );
+
+ t = 1.0f - vg_minf( 1.0f, fabsf( t * 1.1f ) );
+ t = sign * (1.0f-t*t);
+
+ f32 angle = vg_clampf( t, -1.0f, 1.0f ) * VG_TAUf,
+ distm = state->land_dist * fabsf(state->flip_rate) * 3.0f,
+ blend = vg_clampf( 1.0f-distm, 0.0f, 1.0f );
+ angle = vg_lerpf( angle, vg_signf(state->flip_rate)*VG_TAUf, blend );
+ q_axis_angle( animator->qflip, state->flip_axis, angle );
+ }
+ else
+ q_identity( animator->qflip );
+
+ /* counter-rotation */
+ if( v3_length2( state->up_dir ) > 0.001f ){
+ v4_lerp( state->smoothed_rotation, localplayer.rb.q,
+ 2.0f*vg.time_frame_delta,
+ state->smoothed_rotation );
+ q_normalize( state->smoothed_rotation );
+
+ v3f yaw_smooth = {1.0f,0.0f,0.0f};
+ q_mulv( state->smoothed_rotation, yaw_smooth, yaw_smooth );
+ m3x3_mulv( localplayer.rb.to_local, yaw_smooth, yaw_smooth );
+ yaw_smooth[1] = 0.0f;
+ v3_normalize( yaw_smooth );
+
+ f32 yaw_counter_rotate = yaw_smooth[0];
+ yaw_counter_rotate = vg_maxf( 0.7f, yaw_counter_rotate );
+ yaw_counter_rotate = acosf( yaw_counter_rotate );
+ yaw_counter_rotate *= 1.0f-animator->fly;
+
+ v3f ndir;
+ m3x3_mulv( localplayer.rb.to_local, state->up_dir, ndir );
+ v3_normalize( ndir );
+
+ v3f up = { 0.0f, 1.0f, 0.0f };
+ float a = v3_dot( ndir, up );
+ a = acosf( vg_clampf( a, -1.0f, 1.0f ) );
+
+ v3f axis;
+ v4f qcounteryaw, qfixup;
+
+ v3_cross( up, ndir, axis );
+ q_axis_angle( qfixup, axis, a*2.0f );
+
+ v3_cross( (v3f){1.0f,0.0f,0.0f}, yaw_smooth, axis );
+ q_axis_angle( qcounteryaw, axis, yaw_counter_rotate );
+
+ q_mul( qcounteryaw, qfixup, animator->qfixuptotal );
+ q_normalize( animator->qfixuptotal );
+
+ v3f p1, p2;
+ m3x3_mulv( localplayer.rb.to_world, up, p1 );
+ m3x3_mulv( localplayer.rb.to_world, ndir, p2 );
+
+ vg_line_arrow( localplayer.rb.co, p1, 0.5f, VG__PINK );
+ vg_line_arrow( localplayer.rb.co, p2, 0.5f, VG__PINK );
+ }
+ else q_identity( animator->qfixuptotal );
+
+ if( state->activity == k_skate_activity_handplant ){
+ v3_copy( state->store_co, animator->root_co );
+ v4_copy( state->store_q, animator->root_q );
+ v3_zero( animator->root_v );
+ }
+ else {
+ rb_extrapolate( &localplayer.rb, animator->root_co, animator->root_q );
+ v3_copy( localplayer.rb.v, animator->root_v );
+ }
+
+ animator->handplant_t = state->handplant_t;
+}
+
+void player__skate_pose( void *_animator, player_pose *pose ){
+ struct skeleton *sk = &localplayer.skeleton;
+ struct player_skate_animator *animator = _animator;
+
+ pose->type = k_player_pose_type_ik;
+ v3_copy( animator->root_co, pose->root_co );
+ v4_copy( animator->root_q, pose->root_q );
+
+ /* transform */
+ v3f ext_up,ext_co;
+ q_mulv( pose->root_q, (v3f){0.0f,1.0f,0.0f}, ext_up );
+ v3_copy( pose->root_co, ext_co );
+ v3_muladds( pose->root_co, ext_up, -0.1f, pose->root_co );
+
+ /* apply flip rotation at midpoint */
+ q_mul( animator->qflip, pose->root_q, pose->root_q );
+ q_normalize( pose->root_q );
+
+ v3f rotation_point, rco;
+ v3_muladds( ext_co, ext_up, 0.5f, rotation_point );
+ v3_sub( pose->root_co, rotation_point, rco );
+
+ q_mulv( animator->qflip, rco, rco );
+ v3_add( rco, rotation_point, pose->root_co );
+
+ /* ANIMATIONS
+ * ---------------------------------------------------------------------- */
+
+ mdl_keyframe apose[32], bpose[32];
+ mdl_keyframe ground_pose[32];
+ {
+ /* stand/crouch */
+ f32 dir_frame = animator->z * (15.0f/30.0f),
+ stand_blend = animator->offset[1]*-2.0f;
+
+ pose->board.lean = animator->board_lean;
+
+ stand_blend = vg_clampf( 1.0f-animator->local_cog[1], 0, 1 );
+
+ skeleton_sample_anim( sk, player_skate.anim_stand, dir_frame, apose );
+ skeleton_sample_anim( sk, player_skate.anim_highg, dir_frame, bpose );
+ skeleton_lerp_pose( sk, apose, bpose, stand_blend, apose );
+
+ /* sliding */
+ f32 slide_frame = animator->x * 0.25f + 0.25f;
+ skeleton_sample_anim( sk, player_skate.anim_slide, slide_frame, bpose );
+
+ mdl_keyframe mirrored[32];
+ player_mirror_pose( bpose, mirrored );
+ skeleton_lerp_pose( sk, bpose, mirrored, animator->z, bpose );
+ skeleton_lerp_pose( sk, apose, bpose, animator->slide, apose );
+
+ if( animator->reverse > 0.0f ){
+ skeleton_sample_anim( sk, player_skate.anim_push, animator->push_time,
+ bpose );
+ }
+ else{
+ skeleton_sample_anim( sk, player_skate.anim_push_reverse,
+ animator->push_time, bpose );
+ }
+ skeleton_lerp_pose( sk, apose, bpose, animator->push, apose );
+
+ struct skeleton_anim *jump_anim = animator->jump_dir?
+ player_skate.anim_ollie:
+ player_skate.anim_ollie_reverse;
+
+ f32 setup_blend = vg_minf( animator->jump, 1.0f );
+ skeleton_sample_anim_clamped( sk, jump_anim, animator->jump_time, bpose );
+ skeleton_lerp_pose( sk, apose, bpose, setup_blend, ground_pose );
+ }
+
+ mdl_keyframe air_pose[32];
+ {
+ float air_frame = (animator->airdir*0.5f+0.5f) * (15.0f/30.0f);
+ skeleton_sample_anim( sk, player_skate.anim_air, air_frame, apose );
+
+ float ang = atan2f( animator->grab[0], animator->grab[1] ),
+ ang_unit = (ang+VG_PIf) * (1.0f/VG_TAUf),
+ grab_frame = ang_unit * (15.0f/30.0f);
+
+ skeleton_sample_anim( sk, player_skate.anim_grabs, grab_frame, bpose );
+ skeleton_lerp_pose( sk, apose, bpose, animator->grabbing, air_pose );
+ }
+
+ skeleton_lerp_pose( sk, ground_pose, air_pose, animator->fly,
+ pose->keyframes );
+
+ 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];
+ {
+ f32 frame = animator->grind_balance * 0.5f;
+
+ skeleton_sample_anim( sk, player_skate.anim_grind, frame, apose );
+ skeleton_sample_anim( sk, player_skate.anim_grind_jump, frame, bpose );
+ skeleton_lerp_pose( sk, apose, bpose, animator->jump, grind_pose );
+ }
+ skeleton_lerp_pose( sk, pose->keyframes, grind_pose,
+ animator->grind, pose->keyframes );
+ float add_grab_mod = 1.0f - animator->fly;
+
+ /* additive effects */
+ 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,
+ 0.75f,
+ 0.75f,
+ 0.75f };
+
+ for( int i=0; i<vg_list_size(apply_to); i ++ ){
+ pose->keyframes[apply_to[i]-1].co[0] += animator->offset[0]*add_grab_mod;
+ pose->keyframes[apply_to[i]-1].co[2] += animator->offset[2]*add_grab_mod;
+ }
+
+#if 1
+ /* angle 'correction' */
+ v3f origin;
+ v3_add( sk->bones[localplayer.id_hip].co, kf_hip->co, origin );
+
+ for( int i=0; i<vg_list_size(apply_to); i ++ ){
+ mdl_keyframe *kf = &pose->keyframes[apply_to[i]-1];
+ keyframe_rotate_around( kf, origin, sk->bones[apply_to[i]].co,
+ animator->qfixuptotal );
+ }
+#endif
+
+
+ if( animator->activity == k_skate_activity_handplant ){
+ struct skeleton_anim *anim = player_skate.anim_handplant;
+
+ mdl_keyframe hpose[32];
+ skeleton_sample_anim_clamped( sk, anim, animator->handplant_t, hpose );
+ if( animator->reverse < 0.0f )
+ player_mirror_pose( hpose, hpose );
+
+ mdl_keyframe *kf_world = &hpose[ localplayer.id_world -1 ];
+ m4x3f world, mmdl, world_view;
+ q_m3x3( kf_world->q, world );
+ v3_copy( kf_world->co, world[3] );
+
+ q_m3x3( pose->root_q, mmdl );
+ v3_copy( pose->root_co, mmdl[3] );
+
+ m4x3_mul( mmdl, world, world_view );
+
+ vg_line_arrow( world_view[3], world_view[0], 1.0f, 0xff0000ff );
+ vg_line_arrow( world_view[3], world_view[1], 1.0f, 0xff00ff00 );
+ vg_line_arrow( world_view[3], world_view[2], 1.0f, 0xffff0000 );
+
+ m4x3f invworld;
+ m4x3_invert_affine( world, invworld );
+ m4x3_mul( mmdl, invworld, world_view );
+
+ m3x3_q( world_view, pose->root_q );
+ v3_copy( world_view[3], pose->root_co );
+
+ f32 t = animator->handplant_t,
+ frames = anim->length-1,
+ length = animator->activity == k_skate_activity_handplant?
+ frames / anim->rate:
+ 999999,
+ end_dist = vg_minf( t, length - t )/k_anim_transition,
+ blend = vg_smoothstepf( vg_minf(1,end_dist) );
+
+ skeleton_lerp_pose( sk, pose->keyframes, hpose, blend, pose->keyframes );
+ }
+
+
+ /* trick rotation */
+ v4f qtrick, qyaw, qpitch, qroll;
+ q_axis_angle( qyaw, (v3f){0.0f,1.0f,0.0f}, animator->board_euler[0] );
+ q_axis_angle( qpitch, (v3f){1.0f,0.0f,0.0f}, animator->board_euler[1] );
+ q_axis_angle( qroll, (v3f){0.0f,0.0f,1.0f}, animator->board_euler[2] );
+
+ q_mul( qyaw, qroll, qtrick );
+ q_mul( qpitch, qtrick, qtrick );
+ q_mul( kf_board->q, qtrick, kf_board->q );
+ q_normalize( kf_board->q );
+
+ kf_foot_l->co[2] = vg_lerpf( kf_foot_l->co[2], animator->foot_offset[0],
+ 0.5f * animator->weight );
+ kf_foot_r->co[2] = vg_lerpf( kf_foot_r->co[2], animator->foot_offset[1],
+ -0.5f * animator->weight );
+
+ kf_foot_l->co[1] += animator->slap;
+ kf_foot_r->co[1] += animator->slap;
+ kf_knee_l->co[1] += animator->slap;
+ kf_knee_r->co[1] += animator->slap;
+ kf_board->co[1] += animator->slap * animator->subslap;
+ kf_hip->co[1] += animator->slap * 0.25f;
+
+ /* kickflip and shuvit are in the wrong order for some reason */
+ if( animator->trick_type == k_trick_type_kickflip ){
+ kf_foot_l->co[0] += animator->trick_foot * 0.15f;
+ kf_foot_r->co[0] -= animator->trick_foot * 0.15f;
+ kf_foot_l->co[1] -= animator->trick_foot * 0.18f;
+ kf_foot_r->co[1] -= animator->trick_foot * 0.18f;
+ }
+ else if( animator->trick_type == k_trick_type_shuvit ){
+ kf_foot_l->co[0] += animator->trick_foot * 0.2f;
+ kf_foot_l->co[1] -= animator->trick_foot * 0.18f;
+ kf_foot_r->co[0] -= animator->trick_foot * 0.1f;
+ kf_foot_r->co[1] += animator->trick_foot * 0.09f;
+ }
+ else if( animator->trick_type == k_trick_type_treflip ){
+ kf_foot_l->co[0] += animator->trick_foot * 0.2f;
+ kf_foot_r->co[0] -= animator->trick_foot * 0.15f;
+ kf_foot_l->co[1] -= animator->trick_foot * 0.18f;
+ kf_foot_r->co[1] -= animator->trick_foot * 0.18f;
+ }
+
+ /*
+ * animation wishlist:
+ * boardslide/grind jump animations
+ * when tricking the slap should not appply or less apply
+ * not animations however DONT target grinds that are vertically down.
+ */
+
+ /* truck rotation */
+ for( int i=0; i<2; i++ ){
+ float a = vg_minf( player_skate.truckv0[i][0], 1.0f );
+ a = -acosf( a ) * vg_signf( player_skate.truckv0[i][1] );
+
+ v4f q;
+ q_axis_angle( q, (v3f){0.0f,0.0f,1.0f}, a );
+ q_mul( q, kf_wheels[i]->q, kf_wheels[i]->q );
+ q_normalize( kf_wheels[i]->q );
+ }
+
+#if 1
+ {
+ mdl_keyframe
+ *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],
+ *kf_hip = &pose->keyframes[localplayer.id_hip-1];
+
+ float warble = vg_perlin_fract_1d( vg.time, 2.0f, 2, 300 );
+ warble *= vg_maxf(animator->grind, fabsf(animator->weight)) * 0.3f;
+
+ v4f qrot;
+ q_axis_angle( qrot, (v3f){0.8f,0.7f,0.6f}, warble );
+
+ v3f origin = {0.0f,0.2f,0.0f};
+ keyframe_rotate_around( kf_hand_l, origin,
+ sk->bones[localplayer.id_ik_hand_l].co, qrot );
+ keyframe_rotate_around( kf_hand_r, origin,
+ sk->bones[localplayer.id_ik_hand_r].co, qrot );
+ keyframe_rotate_around( kf_hip, origin,
+ sk->bones[localplayer.id_hip].co, qrot );
+ keyframe_rotate_around( kf_elbow_r, origin,
+ sk->bones[localplayer.id_ik_elbow_r].co, qrot );
+ keyframe_rotate_around( kf_elbow_l, origin,
+ 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 );
+
+
+ /* hand placement */
+
+ u32 hand_id = animator->z < 0.5f?
+ localplayer.id_ik_hand_l: localplayer.id_ik_hand_r;
+
+ v3f sample_co;
+ m4x3f mmdl;
+ q_m3x3( pose->root_q, mmdl );
+ q_mulv( pose->root_q, pose->keyframes[hand_id-1].co, mmdl[3] );
+ v3_add( mmdl[3], pose->root_co, mmdl[3] );
+ m4x3_mulv( mmdl, sk->bones[hand_id].co, sample_co );
+
+ v3_muladds( sample_co, mmdl[1], 0.3f, sample_co );
+ vg_line_point( sample_co, 0.04f, 0xff0000ff );
+
+ v3f dir;
+ v3_muls( mmdl[1], -1.0f, dir );
+ ray_hit hit = { .dist = 1.5f };
+ if(ray_world( world_current_instance(), sample_co, dir, &hit, 0 )){
+ vg_line_cross( hit.pos, 0xff0000ff, 0.05f );
+ vg_line( sample_co, hit.pos, 0xffffffff );
+
+ f32 amt = vg_maxf( 0.0f, animator->slide-0.5f ) *
+ 2.0f * fabsf(animator->z*2.0f-1.0f);
+
+ f32 d = (hit.dist - 0.3f) * amt;
+ pose->keyframes[hand_id-1].co[1] -= d;
+ kf_hip->co[1] -= d*0.4f;
+ }
+
+ /* skid */
+ f32 amt = vg_maxf(0.0f, (animator->slide - 0.5f) * 2.0f);
+ u8 skidders[] = { localplayer.id_ik_foot_l,
+ localplayer.id_ik_foot_r,
+ localplayer.id_board };
+ v4f qskid;
+ q_axis_angle( qskid, (v3f){0,1,0}, -animator->steer[1]*0.2f );
+
+ for( u32 i=0; i<vg_list_size(skidders); i ++ ){
+ mdl_keyframe *kf = &pose->keyframes[ skidders[i]-1 ];
+ keyframe_rotate_around( kf,
+ (v3f){0,0,0.4f*(animator->z*2.0f-1.0f)*amt},
+ sk->bones[skidders[i]].co, qskid );
+ }
+ }
+#endif
+}
+
+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;
+
+ 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 );
+
+ if( animator->surface == k_surface_prop_sand ){
+ if( (animator->slide>0.4f) && (v3_length2(animator->root_v)>4.0f*4.0f) ){
+ v3f v, co;
+ v3_muls( animator->root_v, 0.5f, v );
+ v3_lerp( vp0, vp1, vg_randf64(&vg.rand), co );
+
+ effect_data->sand.colour = 0xff8ec4e6;
+ effect_spark_apply( &effect_data->sand, co, v, vg.time_delta * 8.0 );
+ }
+ }
+
+ if( animator->grind > 0.5f ){
+ 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 );
+ }
+ }
+}
+
+void player__skate_post_animate(void){
+ struct player_skate_state *state = &player_skate.state;
+ localplayer.cam_velocity_influence = 1.0f;
+ localplayer.cam_dist = 1.8f;
+
+ v3f head = { 0.0f, 1.8f, 0.0f };
+ m4x3_mulv( localplayer.final_mtx[ localplayer.id_head ],
+ head, state->head_position );
+ m4x3_mulv( localplayer.rb.to_local,
+ state->head_position, state->head_position );
+}
+
+void player__skate_reset_animator(void){
+ struct player_skate_state *state = &player_skate.state;
+
+ memset( &player_skate.animator, 0, sizeof(player_skate.animator) );
+
+ if( state->activity <= k_skate_activity_air_to_grind )
+ player_skate.animator.fly = 1.0f;
+ else
+ player_skate.animator.fly = 0.0f;
+}
+
+void player__skate_clear_mechanics(void)