veloren_voxygen_anim/arthropod/
stunned.rs1use super::{
2 super::{Animation, vek::*},
3 ArthropodSkeleton, 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 = ArthropodSkeleton;
12
13 #[cfg(feature = "use-dyn-lib")]
14 const UPDATE_FN: &'static [u8] = b"arthropod_stunned\0";
15
16 #[cfg_attr(feature = "be-dyn-lib", export_name = "arthropod_stunned")]
17 fn update_skeleton_inner(
18 skeleton: &Self::Skeleton,
19 (_velocity, global_time, stage_section, timer): Self::Dependency<'_>,
20 anim_time: f32,
21 _rate: &mut f32,
22 s_a: &SkeletonAttr,
23 ) -> Self::Skeleton {
24 let mut next = (*skeleton).clone();
25
26 let (_movement1base, movement2, twitch) = match stage_section {
27 Some(StageSection::Buildup) => (anim_time.powf(0.1), 0.0, anim_time),
28 Some(StageSection::Recover) => (1.0, anim_time.powf(4.0), 1.0),
29 _ => (0.0, 0.0, 0.0),
30 };
31
32 let pullback = 1.0 - movement2;
33
34 let subtract = global_time - timer;
35 let check = subtract - subtract.trunc();
36 let mirror = (check - 0.5).signum();
37 let twitch1 = mirror * (twitch * 20.0).cos() * pullback;
38 let twitch2 = mirror * (twitch * 20.0).sin() * pullback;
39
40 next.chest.scale = Vec3::one() * s_a.scaler;
41
42 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
43 next.head.orientation = Quaternion::rotation_z(twitch2 * 0.6);
44
45 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1);
46
47 next.mandible_l.position = Vec3::new(-s_a.mandible.0, s_a.mandible.1, s_a.mandible.2);
48 next.mandible_r.position = Vec3::new(s_a.mandible.0, s_a.mandible.1, s_a.mandible.2);
49
50 next.wing_fl.position = Vec3::new(-s_a.wing_f.0, s_a.wing_f.1, s_a.wing_f.2);
51 next.wing_fr.position = Vec3::new(s_a.wing_f.0, s_a.wing_f.1, s_a.wing_f.2);
52
53 next.wing_bl.position = Vec3::new(-s_a.wing_b.0, s_a.wing_b.1, s_a.wing_b.2);
54 next.wing_br.position = Vec3::new(s_a.wing_b.0, s_a.wing_b.1, s_a.wing_b.2);
55
56 next.leg_fl.position = Vec3::new(-s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
57 next.leg_fr.position = Vec3::new(s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
58 next.leg_fl.orientation =
59 Quaternion::rotation_z(s_a.leg_ori.0) * Quaternion::rotation_x(twitch1 * 0.8 + 0.4);
60 next.leg_fr.orientation =
61 Quaternion::rotation_z(-s_a.leg_ori.0) * Quaternion::rotation_x(-twitch1 * 0.8 - 0.4);
62
63 next.leg_fcl.position = Vec3::new(-s_a.leg_fc.0, s_a.leg_fc.1, s_a.leg_fc.2);
64 next.leg_fcr.position = Vec3::new(s_a.leg_fc.0, s_a.leg_fc.1, s_a.leg_fc.2);
65 next.leg_fcl.orientation =
66 Quaternion::rotation_z(s_a.leg_ori.1) * Quaternion::rotation_y(twitch2 * 0.8 + 0.4);
67 next.leg_fcr.orientation =
68 Quaternion::rotation_z(-s_a.leg_ori.1) * Quaternion::rotation_y(-twitch2 * 0.8 - 0.4);
69
70 next.leg_bcl.position = Vec3::new(-s_a.leg_bc.0, s_a.leg_bc.1, s_a.leg_bc.2);
71 next.leg_bcr.position = Vec3::new(s_a.leg_bc.0, s_a.leg_bc.1, s_a.leg_bc.2);
72 next.leg_bcl.orientation =
73 Quaternion::rotation_z(s_a.leg_ori.2) * Quaternion::rotation_y(twitch1 * 0.8 + 0.4);
74 next.leg_bcr.orientation =
75 Quaternion::rotation_z(-s_a.leg_ori.2) * Quaternion::rotation_y(-twitch1 * 0.8 - 0.4);
76
77 next.leg_bl.position = Vec3::new(-s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
78 next.leg_br.position = Vec3::new(s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
79 next.leg_bl.orientation =
80 Quaternion::rotation_z(s_a.leg_ori.3) * Quaternion::rotation_y(twitch2 * 0.8 + 0.4);
81 next.leg_br.orientation =
82 Quaternion::rotation_z(-s_a.leg_ori.3) * Quaternion::rotation_y(-twitch2 * 0.8 - 0.4);
83
84 next
85 }
86}