veloren_voxygen_anim/quadruped_low/
breathe.rs1use super::{
2 super::{Animation, vek::*},
3 QuadrupedLowSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6use std::f32::consts::PI;
8
9pub struct BreatheAnimation;
10
11impl Animation for BreatheAnimation {
12 type Dependency<'a> = (f32, f32, Option<StageSection>, f32);
13 type Skeleton = QuadrupedLowSkeleton;
14
15 #[cfg(feature = "use-dyn-lib")]
16 const UPDATE_FN: &'static [u8] = b"quadruped_low_breathe\0";
17
18 #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_low_breathe")]
19 fn update_skeleton_inner(
20 skeleton: &Self::Skeleton,
21 (velocity, global_time, stage_section, timer): Self::Dependency<'_>,
22 anim_time: f32,
23 _rate: &mut f32,
24 s_a: &SkeletonAttr,
25 ) -> Self::Skeleton {
26 let mut next = (*skeleton).clone();
27 let speed = (Vec2::<f32>::from(velocity).magnitude()).min(24.0);
28
29 let (movement1base, _movement2base, movement3, twitch) = match stage_section {
30 Some(StageSection::Buildup) => (anim_time.sqrt(), 0.0, 0.0, 0.0),
31 Some(StageSection::Action) => (1.0, anim_time.min(1.0), 0.0, anim_time),
32 Some(StageSection::Recover) => (1.0, 1.0, anim_time, 1.0),
33 _ => (0.0, 0.0, 0.0, 0.0),
34 };
35 let pullback = 1.0 - movement3;
36 let subtract = global_time - timer;
37 let check = subtract - subtract.trunc();
38 let mirror = (check - 0.5).signum();
39 let twitch2 = mirror * (twitch * 20.0).sin() * pullback;
40 let twitch2alt = mirror * (twitch * 20.0 + PI / 2.0).sin() * pullback;
41
42 let movement1abs = movement1base * pullback;
43
44 next.head_c_upper.orientation =
46 Quaternion::rotation_x(movement1abs * 0.3 + twitch2alt * 0.02);
47
48 next.head_c_lower.orientation =
49 Quaternion::rotation_x(movement1abs * -0.3) * Quaternion::rotation_y(twitch2 * 0.02);
50
51 next.jaw_c.orientation = Quaternion::rotation_x(movement1abs * -0.7 + twitch2 * 0.1);
52
53 next.head_l_upper.orientation =
55 Quaternion::rotation_x(movement1abs * 0.3 + twitch2alt * 0.02);
56
57 next.head_l_lower.orientation =
58 Quaternion::rotation_x(movement1abs * -0.3) * Quaternion::rotation_y(twitch2 * 0.02);
59
60 next.jaw_l.orientation = Quaternion::rotation_x(movement1abs * -0.7 + twitch2 * 0.1);
61
62 next.head_r_upper.orientation =
64 Quaternion::rotation_x(movement1abs * 0.3 + twitch2alt * 0.02);
65
66 next.head_r_lower.orientation =
67 Quaternion::rotation_x(movement1abs * -0.3) * Quaternion::rotation_y(twitch2 * 0.02);
68
69 next.jaw_r.orientation = Quaternion::rotation_x(movement1abs * -0.7 + twitch2 * 0.1);
70
71 next.chest.orientation =
72 Quaternion::rotation_y(twitch2 * -0.02) * Quaternion::rotation_z(0.0);
73 if s_a.tongue_for_tail {
74 next.tail_front.scale = Vec3::one() * 0.1;
75 next.tail_rear.scale = Vec3::one() * 0.1;
76 } else {
77 next.tail_front.orientation =
78 Quaternion::rotation_x(0.15 + movement1abs * -0.15 + twitch2alt * 0.02)
79 * Quaternion::rotation_z(0.0);
80
81 next.tail_rear.orientation =
82 Quaternion::rotation_x(-0.12 + movement1abs * -0.2 + twitch2alt * 0.08)
83 * Quaternion::rotation_z(0.0);
84 }
85 if speed < 0.5 {
86 next.foot_fl.orientation = Quaternion::rotation_y(twitch2 * 0.02);
87
88 next.foot_fr.orientation = Quaternion::rotation_y(twitch2 * 0.02);
89
90 next.foot_bl.orientation = Quaternion::rotation_y(twitch2 * 0.02);
91
92 next.foot_br.orientation = Quaternion::rotation_y(twitch2 * 0.02);
93 };
94 next
95 }
96}