veloren_voxygen_anim/quadruped_medium/
leapmelee.rs

1use super::{
2    super::{Animation, vek::*},
3    QuadrupedMediumSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6
7pub struct LeapMeleeAnimation;
8
9impl Animation for LeapMeleeAnimation {
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_leapmelee\0";
15
16    #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_leapmelee")]
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        //let speed = (Vec2::<f32>::from(velocity).magnitude()).min(24.0);
26
27        let (movement1base, movement2base, movement3base, movement4) = match stage_section {
28            Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0, 0.0),
29            Some(StageSection::Movement) => (1.0, anim_time, 0.0, 0.0),
30            Some(StageSection::Action) => (1.0, 1.0, anim_time, 0.0),
31            Some(StageSection::Recover) => (0.0, 1.0, 1.0, anim_time.powi(4)),
32            _ => (0.0, 0.0, 0.0, 0.0),
33        };
34        let pullback = 1.0 - movement4;
35        let subtract = global_time - timer;
36        let check = subtract - subtract.trunc();
37        let mirror = (check - 0.5).signum();
38        let movement1abs = movement1base * pullback;
39        let movement2abs = movement2base * pullback;
40        let movement3abs = movement3base * pullback;
41
42        let twitch1 = (movement1base * 10.0).sin() * (1.0 - movement2base);
43        let twitch3 = (movement3base * 5.0).sin() * mirror;
44        let twitch1abs = twitch1 * mirror;
45
46        next.head.orientation = Quaternion::rotation_x(movement1abs * 0.2 + movement3abs * -0.7)
47            * Quaternion::rotation_y(twitch1abs * 0.3 + twitch3 * 0.7);
48
49        next.neck.orientation = Quaternion::rotation_x(movement1abs * -0.2 + movement1abs * -0.2)
50            * Quaternion::rotation_y(twitch1abs * 0.1);
51
52        next.jaw.orientation = Quaternion::rotation_x(movement1abs * -0.4 + twitch1 * 0.2);
53
54        next.tail.orientation = Quaternion::rotation_z(twitch1abs * 1.0);
55        next.torso_front.position = Vec3::new(
56            0.0,
57            s_a.torso_front.0 + movement1abs * -4.0,
58            s_a.torso_front.1,
59        );
60        next.torso_front.orientation =
61            Quaternion::rotation_x(movement1abs * 0.3 + movement2abs * -0.3 + movement3abs * 0.3)
62                * Quaternion::rotation_y(twitch1abs * -0.1);
63
64        next.torso_back.orientation =
65            Quaternion::rotation_x(movement1abs * -0.45) * Quaternion::rotation_y(twitch1abs * 0.1);
66
67        next.ears.orientation = Quaternion::rotation_x(twitch1 * 0.1);
68        next.leg_fl.orientation = Quaternion::rotation_x(movement1abs * 0.8 + movement2abs * 0.4)
69            * Quaternion::rotation_y(twitch1abs * 0.1);
70
71        next.leg_fr.orientation = Quaternion::rotation_x(movement1abs * 0.8 + movement2abs * 0.4)
72            * Quaternion::rotation_y(twitch1abs * 0.1);
73
74        next.leg_bl.orientation = Quaternion::rotation_x(movement1abs * 0.4 + movement2abs * -1.2);
75
76        next.leg_br.orientation = Quaternion::rotation_x(movement1abs * 0.4 + movement2abs * -1.2);
77
78        next.foot_fl.orientation = Quaternion::rotation_x(movement1abs * -0.9);
79
80        next.foot_fr.orientation = Quaternion::rotation_x(movement1abs * -0.9);
81
82        next.foot_bl.orientation = Quaternion::rotation_x(movement1abs * -1.1);
83
84        next.foot_br.orientation = Quaternion::rotation_x(movement1abs * -1.1);
85
86        next
87    }
88}