veloren_voxygen_anim/quadruped_medium/
shockwave.rs1use super::{
2 super::{Animation, vek::*},
3 QuadrupedMediumSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6use 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(feature = "be-dyn-lib", export_name = "quadruped_medium_shockwave")]
19 fn update_skeleton_inner(
20 skeleton: &Self::Skeleton,
21 (_velocity, global_time, stage_section, timer): Self::Dependency<'_>,
22 anim_time: f32,
23 _rate: &mut f32,
24 _s_a: &SkeletonAttr,
25 ) -> Self::Skeleton {
26 let mut next = (*skeleton).clone();
27
28 let (movement1base, chargemovementbase, movement2base, movement3, legtell) =
29 match stage_section {
30 Some(StageSection::Buildup) => (anim_time.sqrt(), 0.0, 0.0, 0.0, anim_time),
31 Some(StageSection::Charge) => (1.0, 1.0, 0.0, 0.0, 0.0),
32 Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(4), 0.0, 0.2),
33 Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time, 0.0),
34 _ => (0.0, 0.0, 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 twitch1 = (mirror * movement1base * 3.5).sin();
41 let twitch1fast = (mirror * movement1base * 45.0).sin();
42 let movement1abs = movement1base * pullback;
46 let movement2abs = movement2base * pullback;
47 let legswing = legtell * pullback;
49 let short = ((1.0 / (0.72 + 0.28 * ((anim_time * 16.0_f32 + PI * 0.25).sin()).powi(2)))
50 .sqrt())
51 * ((anim_time * 16.0_f32 + PI * 0.25).sin())
52 * chargemovementbase
53 * pullback;
54 let shortalt = (anim_time * 16.0_f32 + PI * 0.25).sin() * chargemovementbase * pullback;
55
56 next.head.orientation = Quaternion::rotation_x(movement1abs * -0.2 + movement2abs * 0.8)
57 * Quaternion::rotation_z(short * -0.06 + twitch1 * 0.2);
58
59 next.neck.orientation = Quaternion::rotation_x(movement1abs * -0.2 + movement2abs * 0.5)
60 * Quaternion::rotation_z(short * 0.15 + twitch1 * 0.2);
61
62 next.jaw.orientation = Quaternion::rotation_x(
63 twitch1fast * 0.2
64 + movement1abs * -0.3
65 + movement2abs * 1.2
66 + chargemovementbase * -0.5,
67 );
68 next.torso_front.orientation = Quaternion::rotation_z(twitch1 * 0.06)
69 * Quaternion::rotation_y(short * 0.06)
70 * Quaternion::rotation_x(legswing * 0.06);
71
72 next.tail.orientation = Quaternion::rotation_x(
73 0.15 + movement1abs * -0.4 + movement2abs * 0.2 + chargemovementbase * 0.2,
74 ) * Quaternion::rotation_z(shortalt * 0.15);
75 next.leg_fl.orientation = Quaternion::rotation_x(legswing * 1.4);
76
77 next.foot_fl.orientation = Quaternion::rotation_x(legswing * -0.5);
78 next.leg_bl.orientation = Quaternion::rotation_x(legswing * 0.3);
79
80 next.foot_bl.orientation = Quaternion::rotation_x(legswing * -0.3);
81
82 next.leg_fr.orientation = Quaternion::rotation_x(legswing * 1.4);
83
84 next.foot_fr.orientation = Quaternion::rotation_x(legswing * -0.5);
85
86 next.leg_br.orientation = Quaternion::rotation_x(legswing * 0.3);
87
88 next.foot_br.orientation = Quaternion::rotation_x(legswing * -0.3);
89 next
90 }
91}