veloren_voxygen_anim/quadruped_small/
alpha.rs1use super::{
2 super::{Animation, vek::*},
3 QuadrupedSmallSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6pub struct AlphaAnimation;
9
10impl Animation for AlphaAnimation {
11 type Dependency<'a> = (f32, StageSection, f32);
12 type Skeleton = QuadrupedSmallSkeleton;
13
14 #[cfg(feature = "use-dyn-lib")]
15 const UPDATE_FN: &'static [u8] = b"quadruped_small_alpha\0";
16
17 #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_small_alpha")]
18 fn update_skeleton_inner(
19 skeleton: &Self::Skeleton,
20 (global_time, stage_section, timer): Self::Dependency<'_>,
21 anim_time: f32,
22 _rate: &mut f32,
23 _s_a: &SkeletonAttr,
24 ) -> Self::Skeleton {
25 let mut next = (*skeleton).clone();
26
27 let (movement1base, movement2base, movement3) = match stage_section {
28 StageSection::Buildup => (anim_time.sqrt(), 0.0, 0.0),
29 StageSection::Action => (1.0, anim_time.powi(4), 0.0),
30 StageSection::Recover => (1.0, 1.0, anim_time),
31 _ => (0.0, 0.0, 0.0),
32 };
33 let pullback = 1.0 - movement3;
34 let subtract = global_time - timer;
35 let check = subtract - subtract.trunc();
36 let mirror = (check - 0.5).signum();
37 let movement1 = mirror * movement1base * pullback;
38 let movement2 = mirror * movement2base * pullback;
39 let movement1abs = movement1base * pullback;
40 let movement2abs = movement2base * pullback;
41
42 next.head.orientation = Quaternion::rotation_x(movement1abs * -0.7 + movement2abs * 2.0)
43 * Quaternion::rotation_y(movement1 * -0.6 + movement2 * 1.2);
44
45 next.chest.orientation = Quaternion::rotation_y(movement1 * -0.08 + movement2 * 0.15)
46 * Quaternion::rotation_z(movement1 * 0.2 + movement2 * -0.6);
47
48 next.tail.orientation = Quaternion::rotation_x(movement1abs * 0.5 + movement2abs * -1.0)
49 * Quaternion::rotation_z(movement1 * -0.4 + movement2 * -0.2);
50
51 next
52 }
53}