veloren_voxygen_anim/quadruped_medium/
leapmelee.rs1use super::{
2 super::{Animation, vek::*},
3 QuadrupedMediumSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6
7pub struct LeapMeleeAnimation;
8
9impl Animation for LeapMeleeAnimation {
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_leapmelee\0";
15
16 #[cfg_attr(
17 feature = "be-dyn-lib",
18 unsafe(export_name = "quadruped_medium_leapmelee")
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 let (movement1base, movement2base, movement3base, movement4) = match stage_section {
31 Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0, 0.0),
32 Some(StageSection::Movement) => (1.0, anim_time, 0.0, 0.0),
33 Some(StageSection::Action) => (1.0, 1.0, anim_time, 0.0),
34 Some(StageSection::Recover) => (0.0, 1.0, 1.0, anim_time.powi(4)),
35 _ => (0.0, 0.0, 0.0, 0.0),
36 };
37 let pullback = 1.0 - movement4;
38 let subtract = global_time - timer;
39 let check = subtract - subtract.trunc();
40 let mirror = (check - 0.5).signum();
41 let movement1abs = movement1base * pullback;
42 let movement2abs = movement2base * pullback;
43 let movement3abs = movement3base * pullback;
44
45 let twitch1 = (movement1base * 10.0).sin() * (1.0 - movement2base);
46 let twitch3 = (movement3base * 5.0).sin() * mirror;
47 let twitch1abs = twitch1 * mirror;
48
49 next.head.orientation = Quaternion::rotation_x(movement1abs * 0.2 + movement3abs * -0.7)
50 * Quaternion::rotation_y(twitch1abs * 0.3 + twitch3 * 0.7);
51
52 next.neck.orientation = Quaternion::rotation_x(movement1abs * -0.2 + movement1abs * -0.2)
53 * Quaternion::rotation_y(twitch1abs * 0.1);
54
55 next.jaw.orientation = Quaternion::rotation_x(movement1abs * -0.4 + twitch1 * 0.2);
56
57 next.tail.orientation = Quaternion::rotation_z(twitch1abs * 1.0);
58 next.torso_front.position = Vec3::new(
59 0.0,
60 s_a.torso_front.0 + movement1abs * -4.0,
61 s_a.torso_front.1,
62 );
63 next.torso_front.orientation =
64 Quaternion::rotation_x(movement1abs * 0.3 + movement2abs * -0.3 + movement3abs * 0.3)
65 * Quaternion::rotation_y(twitch1abs * -0.1);
66
67 next.torso_back.orientation =
68 Quaternion::rotation_x(movement1abs * -0.45) * Quaternion::rotation_y(twitch1abs * 0.1);
69
70 next.ears.orientation = Quaternion::rotation_x(twitch1 * 0.1);
71 next.leg_fl.orientation = Quaternion::rotation_x(movement1abs * 0.8 + movement2abs * 0.4)
72 * Quaternion::rotation_y(twitch1abs * 0.1);
73
74 next.leg_fr.orientation = Quaternion::rotation_x(movement1abs * 0.8 + movement2abs * 0.4)
75 * Quaternion::rotation_y(twitch1abs * 0.1);
76
77 next.leg_bl.orientation = Quaternion::rotation_x(movement1abs * 0.4 + movement2abs * -1.2);
78
79 next.leg_br.orientation = Quaternion::rotation_x(movement1abs * 0.4 + movement2abs * -1.2);
80
81 next.foot_fl.orientation = Quaternion::rotation_x(movement1abs * -0.9);
82
83 next.foot_fr.orientation = Quaternion::rotation_x(movement1abs * -0.9);
84
85 next.foot_bl.orientation = Quaternion::rotation_x(movement1abs * -1.1);
86
87 next.foot_br.orientation = Quaternion::rotation_x(movement1abs * -1.1);
88
89 next
90 }
91}