veloren_voxygen_anim/quadruped_medium/
shockwave.rs

1use super::{
2    super::{Animation, vek::*},
3    QuadrupedMediumSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6//use std::ops::Rem;
7use std::f32::consts::PI;
8
9pub struct ShockwaveAnimation;
10
11impl Animation for ShockwaveAnimation {
12    type Dependency<'a> = (f32, f32, Option<StageSection>, f32);
13    type Skeleton = QuadrupedMediumSkeleton;
14
15    #[cfg(feature = "use-dyn-lib")]
16    const UPDATE_FN: &'static [u8] = b"quadruped_medium_shockwave\0";
17
18    #[cfg_attr(
19        feature = "be-dyn-lib",
20        unsafe(export_name = "quadruped_medium_shockwave")
21    )]
22    fn update_skeleton_inner(
23        skeleton: &Self::Skeleton,
24        (_velocity, global_time, stage_section, timer): Self::Dependency<'_>,
25        anim_time: f32,
26        _rate: &mut f32,
27        _s_a: &SkeletonAttr,
28    ) -> Self::Skeleton {
29        let mut next = (*skeleton).clone();
30
31        let (movement1base, chargemovementbase, movement2base, movement3, legtell) =
32            match stage_section {
33                Some(StageSection::Buildup) => (anim_time.sqrt(), 0.0, 0.0, 0.0, anim_time),
34                Some(StageSection::Charge) => (1.0, 1.0, 0.0, 0.0, 0.0),
35                Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(4), 0.0, 0.2),
36                Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time, 0.0),
37                _ => (0.0, 0.0, 0.0, 0.0, 0.0),
38            };
39        let pullback = 1.0 - movement3;
40        let subtract = global_time - timer;
41        let check = subtract - subtract.trunc();
42        let mirror = (check - 0.5).signum();
43        let twitch1 = (mirror * movement1base * 3.5).sin();
44        let twitch1fast = (mirror * movement1base * 45.0).sin();
45        //let twitch3 = (mirror * movement3 * 4.0).sin();
46        //let movement1 = mirror * movement1base * pullback;
47        //let movement2 = mirror * movement2base * pullback;
48        let movement1abs = movement1base * pullback;
49        let movement2abs = movement2base * pullback;
50        //let legtwitch = (legtell * 6.0).sin() * pullback;
51        let legswing = legtell * pullback;
52        let short = ((1.0 / (0.72 + 0.28 * ((anim_time * 16.0_f32 + PI * 0.25).sin()).powi(2)))
53            .sqrt())
54            * ((anim_time * 16.0_f32 + PI * 0.25).sin())
55            * chargemovementbase
56            * pullback;
57        let shortalt = (anim_time * 16.0_f32 + PI * 0.25).sin() * chargemovementbase * pullback;
58
59        next.head.orientation = Quaternion::rotation_x(movement1abs * -0.2 + movement2abs * 0.8)
60            * Quaternion::rotation_z(short * -0.06 + twitch1 * 0.2);
61
62        next.neck.orientation = Quaternion::rotation_x(movement1abs * -0.2 + movement2abs * 0.5)
63            * Quaternion::rotation_z(short * 0.15 + twitch1 * 0.2);
64
65        next.jaw.orientation = Quaternion::rotation_x(
66            twitch1fast * 0.2
67                + movement1abs * -0.3
68                + movement2abs * 1.2
69                + chargemovementbase * -0.5,
70        );
71        next.torso_front.orientation = Quaternion::rotation_z(twitch1 * 0.06)
72            * Quaternion::rotation_y(short * 0.06)
73            * Quaternion::rotation_x(legswing * 0.06);
74
75        next.tail.orientation = Quaternion::rotation_x(
76            0.15 + movement1abs * -0.4 + movement2abs * 0.2 + chargemovementbase * 0.2,
77        ) * Quaternion::rotation_z(shortalt * 0.15);
78        next.leg_fl.orientation = Quaternion::rotation_x(legswing * 1.4);
79
80        next.foot_fl.orientation = Quaternion::rotation_x(legswing * -0.5);
81        next.leg_bl.orientation = Quaternion::rotation_x(legswing * 0.3);
82
83        next.foot_bl.orientation = Quaternion::rotation_x(legswing * -0.3);
84
85        next.leg_fr.orientation = Quaternion::rotation_x(legswing * 1.4);
86
87        next.foot_fr.orientation = Quaternion::rotation_x(legswing * -0.5);
88
89        next.leg_br.orientation = Quaternion::rotation_x(legswing * 0.3);
90
91        next.foot_br.orientation = Quaternion::rotation_x(legswing * -0.3);
92        next
93    }
94}