veloren_voxygen_anim/quadruped_small/
stunned.rs1use super::{
2 super::{Animation, vek::*},
3 QuadrupedSmallSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6pub 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(
18 feature = "be-dyn-lib",
19 unsafe(export_name = "quadruped_small_stunned")
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, movement2, twitch) = match stage_section {
31 Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0),
32 Some(StageSection::Recover) => {
33 (1.0, anim_time.powf(3.0), ((1.0 - anim_time) * 10.0).sin())
34 },
35 _ => (0.0, 0.0, 0.0),
36 };
37 let pullback = 1.0 - movement2;
38 let subtract = global_time - timer;
39 let check = subtract - subtract.trunc();
40 let mirror = (check - 0.5).signum();
41 let movement1 = mirror * movement1base * pullback;
42 let movement1abs = movement1base * pullback;
43 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
44
45 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + movement1abs * -1.5);
46 next.head.orientation = Quaternion::rotation_x(movement1abs * -0.2)
47 * Quaternion::rotation_y(movement1 * -0.6)
48 * Quaternion::rotation_z(movement1 * 0.4 + twitch * 0.2 * mirror);
49
50 next.chest.orientation =
51 Quaternion::rotation_x(movement1abs * -0.2) * Quaternion::rotation_z(0.0);
52
53 next.leg_fl.position = Vec3::new(-s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2);
54 next.leg_fl.orientation = Quaternion::rotation_x(movement1abs * 0.8);
55
56 next.leg_fr.position = Vec3::new(s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2);
57 next.leg_fr.orientation = Quaternion::rotation_x(movement1abs * 0.8);
58
59 next.leg_bl.position = Vec3::new(-s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2);
60 next.leg_bl.orientation = Quaternion::rotation_x(movement1abs * -0.2);
61
62 next.leg_br.position = Vec3::new(s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2);
63 next.leg_br.orientation = Quaternion::rotation_x(movement1abs * -0.2);
64
65 next.tail.orientation =
66 Quaternion::rotation_x(movement1abs * 0.5) * Quaternion::rotation_z(movement1 * -0.4);
67
68 next
69 }
70}