veloren_voxygen_anim/quadruped_medium/
stunned.rs

1use super::{
2    super::{Animation, vek::*},
3    QuadrupedMediumSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6
7pub struct StunnedAnimation;
8
9impl Animation for StunnedAnimation {
10    type Dependency<'a> = (f32, f32, Option<StageSection>, f32);
11    type Skeleton = QuadrupedMediumSkeleton;
12
13    #[cfg(feature = "use-dyn-lib")]
14    const UPDATE_FN: &'static [u8] = b"quadruped_medium_stunned\0";
15
16    #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_stunned")]
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, movement2, twitch) = match stage_section {
27            Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0),
28            Some(StageSection::Recover) => {
29                (1.0, anim_time.powf(3.0), ((1.0 - anim_time) * 7.0).sin())
30            },
31            _ => (0.0, 0.0, 0.0),
32        };
33        let pullback = 1.0 - movement2;
34        let subtract = global_time - timer;
35        let check = subtract - subtract.trunc();
36        let mirror = (check - 0.5).signum();
37        let movement1 = movement1base * mirror * pullback;
38        let movement1abs = movement1base * pullback;
39
40        next.head.orientation = Quaternion::rotation_x(movement1abs * -0.55)
41            * Quaternion::rotation_y(movement1 * 0.35)
42            * Quaternion::rotation_z(movement1 * 0.15 + twitch * 0.3 * mirror);
43
44        next.neck.orientation = Quaternion::rotation_x(movement1abs * -0.4)
45            * Quaternion::rotation_y(movement1 * 0.0)
46            * Quaternion::rotation_z(movement1 * 0.10 + movement1 * -0.15);
47
48        next.jaw.orientation = Quaternion::rotation_x(0.0);
49
50        next.tail.orientation = Quaternion::rotation_z(movement1 * 0.5);
51        next.torso_front.position = Vec3::new(
52            0.0,
53            s_a.torso_front.0 + movement1abs * -4.0,
54            s_a.torso_front.1,
55        );
56        next.torso_front.orientation =
57            Quaternion::rotation_y(0.0) * Quaternion::rotation_z(movement1 * 0.15);
58
59        next.torso_back.orientation =
60            Quaternion::rotation_y(movement1 * 0.18) * Quaternion::rotation_z(movement1 * -0.4);
61
62        next.ears.orientation = Quaternion::rotation_x(twitch * 0.1 * mirror);
63
64        next.leg_fl.position = Vec3::new(-s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
65        next.leg_fl.orientation = Quaternion::rotation_y(0.0);
66
67        next.leg_fr.position = Vec3::new(s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
68        next.leg_fr.orientation = Quaternion::rotation_y(0.0);
69
70        next.leg_bl.position = Vec3::new(-s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
71        next.leg_bl.orientation = Quaternion::rotation_y(movement1 * -0.3);
72
73        next.leg_br.position = Vec3::new(s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
74        next.leg_br.orientation = Quaternion::rotation_y(movement1 * -0.3);
75
76        next.foot_fl.position = Vec3::new(-s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2);
77        next.foot_fl.orientation = Quaternion::rotation_x(movement1abs * 0.2);
78
79        next.foot_fr.position = Vec3::new(s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2);
80        next.foot_fr.orientation = Quaternion::rotation_x(movement1abs * 0.2);
81
82        next.foot_bl.position = Vec3::new(-s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2);
83
84        next.foot_br.position = Vec3::new(s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2);
85
86        next
87    }
88}