veloren_voxygen_anim/quadruped_medium/
stunned.rs1use super::{
2 super::{Animation, vek::*},
3 QuadrupedMediumSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6
7pub struct StunnedAnimation;
8
9impl Animation for StunnedAnimation {
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_stunned\0";
15
16 #[cfg_attr(
17 feature = "be-dyn-lib",
18 unsafe(export_name = "quadruped_medium_stunned")
19 )]
20 fn update_skeleton_inner(
21 skeleton: &Self::Skeleton,
22 (_velocity, global_time, stage_section, timer): Self::Dependency<'_>,
23 anim_time: f32,
24 _rate: &mut f32,
25 s_a: &SkeletonAttr,
26 ) -> Self::Skeleton {
27 let mut next = (*skeleton).clone();
28
29 let (movement1base, movement2, twitch) = match stage_section {
30 Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0),
31 Some(StageSection::Recover) => {
32 (1.0, anim_time.powf(3.0), ((1.0 - anim_time) * 7.0).sin())
33 },
34 _ => (0.0, 0.0, 0.0),
35 };
36 let pullback = 1.0 - movement2;
37 let subtract = global_time - timer;
38 let check = subtract - subtract.trunc();
39 let mirror = (check - 0.5).signum();
40 let movement1 = movement1base * mirror * pullback;
41 let movement1abs = movement1base * pullback;
42
43 next.head.orientation = Quaternion::rotation_x(movement1abs * -0.55)
44 * Quaternion::rotation_y(movement1 * 0.35)
45 * Quaternion::rotation_z(movement1 * 0.15 + twitch * 0.3 * mirror);
46
47 next.neck.orientation = Quaternion::rotation_x(movement1abs * -0.4)
48 * Quaternion::rotation_y(movement1 * 0.0)
49 * Quaternion::rotation_z(movement1 * 0.10 + movement1 * -0.15);
50
51 next.jaw.orientation = Quaternion::rotation_x(0.0);
52
53 next.tail.orientation = Quaternion::rotation_z(movement1 * 0.5);
54 next.torso_front.position = Vec3::new(
55 0.0,
56 s_a.torso_front.0 + movement1abs * -4.0,
57 s_a.torso_front.1,
58 );
59 next.torso_front.orientation =
60 Quaternion::rotation_y(0.0) * Quaternion::rotation_z(movement1 * 0.15);
61
62 next.torso_back.orientation =
63 Quaternion::rotation_y(movement1 * 0.18) * Quaternion::rotation_z(movement1 * -0.4);
64
65 next.ears.orientation = Quaternion::rotation_x(twitch * 0.1 * mirror);
66
67 next.leg_fl.position = Vec3::new(-s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
68 next.leg_fl.orientation = Quaternion::rotation_y(0.0);
69
70 next.leg_fr.position = Vec3::new(s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
71 next.leg_fr.orientation = Quaternion::rotation_y(0.0);
72
73 next.leg_bl.position = Vec3::new(-s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
74 next.leg_bl.orientation = Quaternion::rotation_y(movement1 * -0.3);
75
76 next.leg_br.position = Vec3::new(s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
77 next.leg_br.orientation = Quaternion::rotation_y(movement1 * -0.3);
78
79 next.foot_fl.position = Vec3::new(-s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2);
80 next.foot_fl.orientation = Quaternion::rotation_x(movement1abs * 0.2);
81
82 next.foot_fr.position = Vec3::new(s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2);
83 next.foot_fr.orientation = Quaternion::rotation_x(movement1abs * 0.2);
84
85 next.foot_bl.position = Vec3::new(-s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2);
86
87 next.foot_br.position = Vec3::new(s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2);
88
89 next
90 }
91}