veloren_voxygen_anim/quadruped_small/
stunned.rs

1use super::{
2    super::{Animation, vek::*},
3    QuadrupedSmallSkeleton, 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 = QuadrupedSmallSkeleton;
13
14    #[cfg(feature = "use-dyn-lib")]
15    const UPDATE_FN: &'static [u8] = b"quadruped_small_stunned\0";
16
17    #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_small_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) * 10.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        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
41
42        next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + movement1abs * -1.5);
43        next.head.orientation = Quaternion::rotation_x(movement1abs * -0.2)
44            * Quaternion::rotation_y(movement1 * -0.6)
45            * Quaternion::rotation_z(movement1 * 0.4 + twitch * 0.2 * mirror);
46
47        next.chest.orientation =
48            Quaternion::rotation_x(movement1abs * -0.2) * Quaternion::rotation_z(0.0);
49
50        next.leg_fl.position = Vec3::new(-s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2);
51        next.leg_fl.orientation = Quaternion::rotation_x(movement1abs * 0.8);
52
53        next.leg_fr.position = Vec3::new(s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2);
54        next.leg_fr.orientation = Quaternion::rotation_x(movement1abs * 0.8);
55
56        next.leg_bl.position = Vec3::new(-s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2);
57        next.leg_bl.orientation = Quaternion::rotation_x(movement1abs * -0.2);
58
59        next.leg_br.position = Vec3::new(s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2);
60        next.leg_br.orientation = Quaternion::rotation_x(movement1abs * -0.2);
61
62        next.tail.orientation =
63            Quaternion::rotation_x(movement1abs * 0.5) * Quaternion::rotation_z(movement1 * -0.4);
64
65        next
66    }
67}