veloren_voxygen_anim/quadruped_low/
stunned.rs

1use super::{
2    super::{Animation, vek::*},
3    QuadrupedLowSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6//use std::ops::Rem;
7
8pub struct StunnedAnimation;
9
10impl Animation for StunnedAnimation {
11    type Dependency<'a> = (f32, f32, Option<StageSection>, f32);
12    type Skeleton = QuadrupedLowSkeleton;
13
14    #[cfg(feature = "use-dyn-lib")]
15    const UPDATE_FN: &'static [u8] = b"quadruped_low_stunned\0";
16
17    #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_low_stunned")]
18    fn update_skeleton_inner(
19        skeleton: &Self::Skeleton,
20        (_velocity, global_time, stage_section, timer): Self::Dependency<'_>,
21        anim_time: f32,
22        _rate: &mut f32,
23        s_a: &SkeletonAttr,
24    ) -> Self::Skeleton {
25        let mut next = (*skeleton).clone();
26
27        let (movement1base, movement2, twitch) = match stage_section {
28            Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0),
29            Some(StageSection::Recover) => {
30                (1.0, anim_time.powf(3.0), ((1.0 - anim_time) * 7.0).sin())
31            },
32            _ => (0.0, 0.0, 0.0),
33        };
34        let pullback = 1.0 - movement2;
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 movement1abs = movement1base * pullback;
40
41        // Center head
42        next.head_c_upper.orientation = Quaternion::rotation_x(movement1abs * -0.18)
43            * Quaternion::rotation_z(twitch * 0.13 * mirror);
44
45        next.head_c_lower.orientation =
46            Quaternion::rotation_x(movement1abs * -0.18) * Quaternion::rotation_y(movement1 * 0.3);
47
48        next.jaw_c.orientation = Quaternion::rotation_x(0.0);
49
50        // Left head
51        next.head_l_upper.orientation = Quaternion::rotation_x(movement1abs * -0.18)
52            * Quaternion::rotation_z(twitch * 0.13 * mirror);
53
54        next.head_l_lower.orientation =
55            Quaternion::rotation_x(movement1abs * -0.18) * Quaternion::rotation_y(movement1 * 0.3);
56
57        next.jaw_l.orientation = Quaternion::rotation_x(0.0);
58
59        // Right head
60        next.head_r_upper.orientation = Quaternion::rotation_x(movement1abs * -0.18)
61            * Quaternion::rotation_z(twitch * 0.13 * mirror);
62
63        next.head_r_lower.orientation =
64            Quaternion::rotation_x(movement1abs * -0.18) * Quaternion::rotation_y(movement1 * 0.3);
65
66        next.jaw_r.orientation = Quaternion::rotation_x(0.0);
67
68        next.chest.orientation =
69            Quaternion::rotation_y(movement1 * -0.08) * Quaternion::rotation_z(movement1 * -0.15);
70
71        next.tail_front.orientation =
72            Quaternion::rotation_x(0.15) * Quaternion::rotation_z(movement1 * -0.4);
73        if s_a.tongue_for_tail {
74            next.tail_front.scale = Vec3::one() * 0.1;
75            next.tail_rear.scale = Vec3::one() * 0.1;
76        } else {
77            next.tail_rear.orientation =
78                Quaternion::rotation_x(-0.12) * Quaternion::rotation_z(movement1 * -0.4);
79        }
80        next
81    }
82}