veloren_voxygen_anim/theropod/
dash.rs

1use super::{
2    super::{Animation, vek::*},
3    SkeletonAttr, TheropodSkeleton,
4};
5use common::states::utils::StageSection;
6
7pub struct DashAnimation;
8
9impl Animation for DashAnimation {
10    type Dependency<'a> = (f32, f32, Option<StageSection>, f32);
11    type Skeleton = TheropodSkeleton;
12
13    #[cfg(feature = "use-dyn-lib")]
14    const UPDATE_FN: &'static [u8] = b"theropod_dash\0";
15
16    #[cfg_attr(feature = "be-dyn-lib", export_name = "theropod_dash")]
17    fn update_skeleton_inner(
18        skeleton: &Self::Skeleton,
19        (_velocity, global_time, stage_section, timer): Self::Dependency<'_>,
20        anim_time: f32,
21        _rate: &mut f32,
22        _s_a: &SkeletonAttr,
23    ) -> Self::Skeleton {
24        let mut next = (*skeleton).clone();
25
26        let (movement1base, chargemovementbase, movement2base, movement3, legtell) =
27            match stage_section {
28                Some(StageSection::Buildup) => (anim_time.sqrt(), 0.0, 0.0, 0.0, anim_time),
29                Some(StageSection::Charge) => (1.0, 1.0, 0.0, 0.0, 0.0),
30                Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(4), 0.0, 1.0),
31                Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time, 1.0),
32                _ => (0.0, 0.0, 0.0, 0.0, 0.0),
33            };
34        let pullback = 1.0 - movement3;
35        let subtract = global_time - timer;
36        let check = subtract - subtract.trunc();
37        let mirror = (check - 0.5).signum();
38        let movement1 = mirror * movement1base * pullback;
39        let movement2 = mirror * movement2base * pullback;
40        let movement1abs = movement1base * pullback;
41        let movement2abs = movement2base * pullback;
42        let legtwitch = (legtell * 6.0).sin() * pullback;
43        let legswing = legtell * pullback;
44        let chargeanim = (chargemovementbase * anim_time * 15.0).sin();
45
46        next.head.orientation =
47            Quaternion::rotation_x(movement1abs * -0.3 + chargeanim * 0.02 + movement2abs * 0.9)
48                * Quaternion::rotation_y(movement1 * 0.1 + movement2 * 0.2);
49        next.neck.orientation =
50            Quaternion::rotation_x(movement1abs * -0.8 + chargeanim * 0.05 + movement2abs * 0.9)
51                * Quaternion::rotation_y(movement1 * 0.1 + movement2 * 0.1);
52
53        next.jaw.orientation = Quaternion::rotation_x(movement1abs * -0.3 + movement2abs * 0.5);
54
55        next.chest_front.orientation = Quaternion::rotation_x(movement1abs * -0.2);
56        next.chest_back.orientation =
57            Quaternion::rotation_x(movement1abs * 0.2 + chargeanim * -0.05);
58
59        next.leg_l.orientation = Quaternion::rotation_x(movement1abs * -0.1);
60
61        next.leg_r.orientation = Quaternion::rotation_x(movement1abs * -0.1);
62        next.foot_l.orientation = Quaternion::rotation_x(movement1abs * -0.3);
63        next.foot_r.orientation = Quaternion::rotation_x(movement1abs * -0.3);
64
65        next.tail_front.orientation =
66            Quaternion::rotation_x(
67                0.1 + movement1abs * -0.1 + chargeanim * -0.05 + movement2abs * -0.3,
68            ) * Quaternion::rotation_z(movement1 * -0.1 + movement2 * -0.2);
69
70        next.tail_back.orientation =
71            Quaternion::rotation_x(
72                0.1 + movement1abs * -0.1 + chargeanim * -0.05 + movement2abs * -0.3,
73            ) * Quaternion::rotation_z(movement1 * -0.1 + movement2 * -0.2);
74
75        if legtell > 0.0 {
76            if mirror.is_sign_positive() {
77                next.leg_l.orientation = Quaternion::rotation_x(legswing * 1.1);
78
79                next.foot_l.orientation = Quaternion::rotation_x(legswing * -1.1 + legtwitch * 0.5);
80
81                next.leg_r.orientation = Quaternion::rotation_x(0.0);
82
83                next.foot_r.orientation = Quaternion::rotation_x(0.0);
84            } else {
85                next.leg_l.orientation = Quaternion::rotation_x(0.0);
86
87                next.foot_l.orientation = Quaternion::rotation_x(0.0);
88
89                next.leg_r.orientation = Quaternion::rotation_x(legswing * 1.1);
90
91                next.foot_r.orientation = Quaternion::rotation_x(legswing * -1.1 + legtwitch * 0.5);
92            }
93        };
94        next
95    }
96}