veloren_voxygen_anim/quadruped_low/
shockwave.rs

1use super::{
2    super::{Animation, vek::*},
3    QuadrupedLowSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6//use std::ops::Rem;
7
8pub struct ShockwaveAnimation;
9
10impl Animation for ShockwaveAnimation {
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_shockwave\0";
16
17    #[cfg_attr(
18        feature = "be-dyn-lib",
19        unsafe(export_name = "quadruped_low_shockwave")
20    )]
21    fn update_skeleton_inner(
22        skeleton: &Self::Skeleton,
23        (_velocity, global_time, stage_section, timer): Self::Dependency<'_>,
24        anim_time: f32,
25        _rate: &mut f32,
26        s_a: &SkeletonAttr,
27    ) -> Self::Skeleton {
28        let mut next = (*skeleton).clone();
29
30        let (movement1base, movement2base, movement3) = match stage_section {
31            Some(StageSection::Buildup) => (anim_time.sqrt(), 0.0, 0.0),
32            Some(StageSection::Action) => (1.0, anim_time.powi(4), 0.0),
33            Some(StageSection::Recover) => (1.0, 1.0, anim_time),
34            _ => (0.0, 0.0, 0.0),
35        };
36        let pullback = -1.0 - movement3;
37        let subtract = global_time - timer;
38        let check = subtract - subtract.trunc();
39        let mirror = (check - 0.5).signum();
40        let twitch3 = (mirror * movement3 * 9.0).sin();
41        let movement1 = mirror * movement1base * pullback;
42        let movement2 = mirror * movement2base * pullback;
43        let movement1abs = movement1base * pullback;
44        let movement2abs = movement2base * pullback;
45
46        // Center head
47        next.head_c_upper.orientation = Quaternion::rotation_z(twitch3 * 1.0);
48
49        next.head_c_lower.orientation =
50            Quaternion::rotation_x(movement1abs * 0.5 + movement2abs * -0.6)
51                * Quaternion::rotation_y(movement1 * -0.1 + movement2 * 0.5);
52
53        next.jaw_c.orientation = Quaternion::rotation_x(movement1abs * 0.0 + movement2abs * 0.3)
54            * Quaternion::rotation_z(twitch3 * 0.2);
55
56        // Left head
57        next.head_l_upper.orientation = Quaternion::rotation_z(twitch3 * 1.0);
58
59        next.head_l_lower.orientation =
60            Quaternion::rotation_x(movement1abs * 0.5 + movement2abs * -0.6)
61                * Quaternion::rotation_y(movement1 * -0.1 + movement2 * 0.5);
62
63        next.jaw_l.orientation = Quaternion::rotation_x(movement1abs * 0.0 + movement2abs * 0.3)
64            * Quaternion::rotation_z(twitch3 * 0.2);
65
66        // Right head
67        next.head_r_upper.orientation = Quaternion::rotation_z(twitch3 * 1.0);
68
69        next.head_r_lower.orientation =
70            Quaternion::rotation_x(movement1abs * 0.5 + movement2abs * -0.6)
71                * Quaternion::rotation_y(movement1 * -0.1 + movement2 * 0.5);
72
73        next.jaw_r.orientation = Quaternion::rotation_x(movement1abs * 0.0 + movement2abs * 0.3)
74            * Quaternion::rotation_z(twitch3 * 0.2);
75
76        next.chest.orientation = Quaternion::rotation_y(movement1 * 0.08 + movement2 * -0.15)
77            * Quaternion::rotation_z(movement1 * 0.2 + movement2 * -0.3);
78        if s_a.tongue_for_tail {
79            next.tail_front.scale = Vec3::one() * 0.1;
80            next.tail_rear.scale = Vec3::one() * 0.1;
81        } else {
82            next.tail_front.orientation = Quaternion::rotation_x(0.15)
83                * Quaternion::rotation_z(movement1 * 0.2 + movement2 * 0.2)
84                * twitch3
85                * 0.8;
86
87            next.tail_rear.orientation = Quaternion::rotation_x(-0.12)
88                * Quaternion::rotation_z(movement1 * 0.2 + movement2 * 0.2)
89                * twitch3
90                * 0.8;
91        }
92        next
93    }
94}