veloren_voxygen_anim/quadruped_medium/
dash.rs

1use super::{
2    super::{Animation, vek::*},
3    QuadrupedMediumSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6//use std::ops::Rem;
7use std::f32::consts::PI;
8
9pub struct DashAnimation;
10
11impl Animation for DashAnimation {
12    type Dependency<'a> = (f32, f32, Option<StageSection>, f32);
13    type Skeleton = QuadrupedMediumSkeleton;
14
15    #[cfg(feature = "use-dyn-lib")]
16    const UPDATE_FN: &'static [u8] = b"quadruped_medium_dash\0";
17
18    #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_dash")]
19    fn update_skeleton_inner(
20        skeleton: &Self::Skeleton,
21        (_velocity, global_time, stage_section, timer): Self::Dependency<'_>,
22        anim_time: f32,
23        _rate: &mut f32,
24        _s_a: &SkeletonAttr,
25    ) -> Self::Skeleton {
26        let mut next = (*skeleton).clone();
27
28        let (movement1base, chargemovementbase, movement2base, movement3, legtell) =
29            match stage_section {
30                Some(StageSection::Buildup) => (anim_time.sqrt(), 0.0, 0.0, 0.0, anim_time),
31                Some(StageSection::Charge) => (1.0, 1.0, 0.0, 0.0, 0.0),
32                Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(4), 0.0, 1.0),
33                Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time, 1.0),
34                _ => (0.0, 0.0, 0.0, 0.0, 0.0),
35            };
36        let pullback = 1.0 - movement3;
37        let subtract = global_time - timer;
38        let check = subtract - subtract.trunc();
39        let mirror = (check - 0.5).signum();
40        let twitch1 = (mirror * movement1base * 9.5).sin();
41        let twitch1fast = (mirror * movement1base * 25.0).sin();
42        //let twitch3 = (mirror * movement3 * 4.0).sin();
43        //let movement1 = mirror * movement1base * pullback;
44        //let movement2 = mirror * movement2base * pullback;
45        let movement1abs = movement1base * pullback;
46        let movement2abs = movement2base * pullback;
47        let legtwitch = (legtell * 6.0).sin() * pullback;
48        let legswing = legtell * pullback;
49        let short = ((1.0 / (0.72 + 0.28 * ((anim_time * 16.0_f32 + PI * 0.25).sin()).powi(2)))
50            .sqrt())
51            * ((anim_time * 16.0_f32 + PI * 0.25).sin())
52            * chargemovementbase
53            * pullback;
54        let shortalt = (anim_time * 16.0_f32 + PI * 0.25).sin() * chargemovementbase * pullback;
55
56        next.head.orientation = Quaternion::rotation_x(movement1abs * -0.2 + movement2abs * 0.8)
57            * Quaternion::rotation_z(short * -0.06 + twitch1 * 0.2);
58
59        next.neck.orientation = Quaternion::rotation_x(movement1abs * -0.2 + movement2abs * 0.5)
60            * Quaternion::rotation_z(short * 0.15 + twitch1 * 0.2);
61
62        next.jaw.orientation = Quaternion::rotation_x(
63            twitch1fast * 0.2
64                + movement1abs * -0.3
65                + movement2abs * 1.2
66                + chargemovementbase * -0.5,
67        );
68        next.torso_front.orientation =
69            Quaternion::rotation_z(twitch1 * 0.06) * Quaternion::rotation_y(short * 0.06);
70
71        next.tail.orientation = Quaternion::rotation_x(
72            0.15 + movement1abs * -0.4 + movement2abs * 0.2 + chargemovementbase * 0.2,
73        ) * Quaternion::rotation_z(shortalt * 0.15);
74        if legtell > 0.0 {
75            if mirror.is_sign_positive() {
76                next.leg_fl.orientation = Quaternion::rotation_x(legswing * 1.1);
77
78                next.foot_fl.orientation =
79                    Quaternion::rotation_x(legswing * -1.1 + legtwitch * 0.5);
80                next.leg_bl.orientation = Quaternion::rotation_x(legswing * 1.1);
81
82                next.foot_bl.orientation =
83                    Quaternion::rotation_x(legswing * -1.1 + legtwitch * 0.5);
84
85                next.leg_fr.orientation = Quaternion::rotation_x(0.0);
86
87                next.foot_fr.orientation = Quaternion::rotation_x(0.0);
88
89                next.leg_br.orientation = Quaternion::rotation_x(0.0);
90
91                next.foot_br.orientation = Quaternion::rotation_x(0.0);
92            } else {
93                next.leg_fl.orientation = Quaternion::rotation_x(0.0);
94
95                next.foot_fl.orientation = Quaternion::rotation_x(0.0);
96                next.leg_bl.orientation = Quaternion::rotation_x(0.0);
97
98                next.foot_bl.orientation = Quaternion::rotation_x(0.0);
99
100                next.leg_fr.orientation = Quaternion::rotation_x(legswing * 1.1);
101
102                next.foot_fr.orientation =
103                    Quaternion::rotation_x(legswing * -1.1 + legtwitch * 0.5);
104
105                next.leg_br.orientation = Quaternion::rotation_x(legswing * 1.1);
106
107                next.foot_br.orientation =
108                    Quaternion::rotation_x(legswing * -1.1 + legtwitch * 0.5);
109            }
110        };
111        next
112    }
113}