- {
- 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 };
-
- float apply_rates[] = { 1.0f,
- 0.75f,
- 0.75f,
- 0.75f,
- 0.75f };
-
- for( int i=0; i<vg_list_size(apply_to); i ++ ){
- dest->pose[apply_to[i]-1].co[0] += offset[0]*add_grab_mod;
- dest->pose[apply_to[i]-1].co[2] += offset[2]*add_grab_mod;
- }
-
- /* angle correction */
- if( v3_length2( s->state.up_dir ) > 0.001f ){
-
- if( v4_length(s->state.smoothed_rotation) <= 0.1f ||
- v4_length(s->state.smoothed_rotation) >= 1.1f ){
- vg_warn( "FIX THIS! CARROT\n" );
- v4_copy( player->rb.q, s->state.smoothed_rotation );
- }
- v4_lerp( s->state.smoothed_rotation, player->rb.q,
- 2.0f*vg.time_frame_delta,
- s->state.smoothed_rotation );
- q_normalize( s->state.smoothed_rotation );
-
- v3f yaw_ref = {1.0f,0.0f,0.0f},
- yaw_smooth = {1.0f,0.0f,0.0f};
- q_mulv( player->rb.q, yaw_ref, yaw_ref );
- q_mulv( s->state.smoothed_rotation, yaw_smooth, yaw_smooth );
- m3x3_mulv( player->rb.to_local, yaw_smooth, yaw_smooth );
- m3x3_mulv( player->rb.to_local, yaw_ref, yaw_ref );
-
- float yaw_counter_rotate = v3_dot(yaw_ref,yaw_smooth);
- yaw_counter_rotate = vg_clampf(yaw_counter_rotate,-1.0f,1.0f);
- yaw_counter_rotate = acosf( yaw_counter_rotate );
- yaw_counter_rotate *= 1.0f-s->blend_fly;
-
- v3f ndir;
- m3x3_mulv( player->rb.to_local, s->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 qfixup, qcounteryaw, qtotal;
-
- v3_cross( up, ndir, axis );
- q_axis_angle( qfixup, axis, a );
-
- q_axis_angle( qcounteryaw, (v3f){0.0f,1.0f,0.0f}, yaw_counter_rotate );
- q_mul( qcounteryaw, qfixup, qtotal );
- q_normalize( qtotal );
-
- mdl_keyframe *kf_hip = &dest->pose[av->id_hip-1];
- v3f origin;
- v3_add( av->sk.bones[av->id_hip].co, kf_hip->co, origin );
-
- for( int i=0; i<vg_list_size(apply_to); i ++ ){
- mdl_keyframe *kf = &dest->pose[apply_to[i]-1];
-
- keyframe_rotate_around( kf, origin, av->sk.bones[apply_to[i]].co,
- qtotal );
- }
-
- v3f p1, p2;
- m3x3_mulv( player->rb.to_world, up, p1 );
- m3x3_mulv( player->rb.to_world, ndir, p2 );
-
- vg_line_arrow( player->rb.co, p1, 0.25f, VG__PINK );
- vg_line_arrow( player->rb.co, p2, 0.25f, VG__PINK );
-
- }
-
- v4f qtotal;
- v4f qtrickr, qyawr, qpitchr, qrollr;
- v3f eulerr;
-
- v3_muls( s->board_trick_residuald, VG_TAUf, eulerr );
-
- q_axis_angle( qyawr, (v3f){0.0f,1.0f,0.0f}, eulerr[0] * 0.5f );
- q_axis_angle( qpitchr, (v3f){1.0f,0.0f,0.0f}, eulerr[1] );
- q_axis_angle( qrollr, (v3f){0.0f,0.0f,1.0f}, eulerr[2] );
-
- q_mul( qpitchr, qrollr, qtrickr );
- q_mul( qyawr, qtrickr, qtotal );
- q_normalize( qtotal );
-
- q_mul( qtotal, kf_board->q, kf_board->q );
-
-
- /* trick rotation */
- v4f qtrick, qyaw, qpitch, qroll;
- v3f euler;
- v3_muls( s->state.trick_euler, VG_TAUf, euler );
-
- float jump_t = vg.time-s->state.jump_time;
-
- float k=17.0f;
- float h = k*jump_t;
- float extra = h*exp(1.0-h) * (s->state.jump_dir?1.0f:-1.0f);
- extra *= s->state.slap * 4.0f;
-
- q_axis_angle( qyaw, (v3f){0.0f,1.0f,0.0f}, euler[0] * 0.5f );
- q_axis_angle( qpitch, (v3f){1.0f,0.0f,0.0f}, euler[1] + extra );
- q_axis_angle( qroll, (v3f){0.0f,0.0f,1.0f}, 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 );
-
+ 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 };
+
+ 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;
+ }
+
+ /* angle 'correction' */
+ v3f origin;
+ v3_add( av->sk.bones[av->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, av->sk.bones[apply_to[i]].co,
+ animator->qfixuptotal );
+ }
+
+ /* 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;
+
+ if( animator->trick_type == k_trick_type_kickflip ){
+ kf_foot_l->co[0] += animator->trick_foot * 0.2f;
+ kf_foot_l->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.1f;
+ 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_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;
+ }