veloren_voxygen_anim/bird_medium/
breathe.rs1use super::{
2 super::{Animation, vek::*},
3 BirdMediumSkeleton, SkeletonAttr,
4};
5use common::{states::utils::StageSection, util::Dir};
6
7pub struct BreatheAnimation;
8
9type BreatheAnimationDependency = (
10 Vec3<f32>,
11 f32,
12 Vec3<f32>,
13 Vec3<f32>,
14 Option<StageSection>,
15 f32,
16 Dir,
17 bool,
18);
19
20impl Animation for BreatheAnimation {
21 type Dependency<'a> = BreatheAnimationDependency;
22 type Skeleton = BirdMediumSkeleton;
23
24 #[cfg(feature = "use-dyn-lib")]
25 const UPDATE_FN: &'static [u8] = b"bird_medium_breathe\0";
26
27 #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_medium_breathe")]
28 fn update_skeleton_inner<'a>(
29 skeleton: &Self::Skeleton,
30 (velocity,global_time, _orientation, _last_ori, stage_section, timer, look_dir, on_ground): Self::Dependency<'_>,
31 anim_time: f32,
32 _rate: &mut f32,
33 s_a: &SkeletonAttr,
34 ) -> Self::Skeleton {
35 let mut next = (*skeleton).clone();
36
37 let (movement1base, movement2base, movement3, twitch) = match stage_section {
38 Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0, 0.0),
39 Some(StageSection::Action) => (1.0, anim_time.min(1.0).powf(0.1), 0.0, anim_time),
40 Some(StageSection::Recover) => (1.0, 1.0, anim_time, 1.0),
41 _ => (0.0, 0.0, 0.0, 0.0),
42 };
43
44 let pullback = 1.0 - movement3;
45 let subtract = global_time - timer;
46 let check = subtract - subtract.trunc();
47 let mirror = (check - 0.5).signum();
48 let twitch2 = mirror * (twitch * 20.0).sin() * pullback;
49
50 let movement1abs = movement1base * pullback;
51 let movement2abs = movement2base * pullback;
52
53 let wave_slow_cos = (anim_time * 4.5).cos();
54
55 next.chest.position = Vec3::new(
56 0.0,
57 s_a.chest.0,
58 s_a.chest.1 + wave_slow_cos * 0.06 + twitch2 * 0.1,
59 );
60
61 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
62 next.head.orientation =
63 Quaternion::rotation_x(movement1abs * 0.5 - movement2abs * 0.5 + look_dir.z * 0.4);
64
65 if on_ground {
66 next.chest.orientation =
67 Quaternion::rotation_x(movement1abs * 0.2 - movement2abs * 0.5 + twitch2 * 0.03);
68 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + movement2abs * -3.0);
69 next.wing_in_l.position = Vec3::new(-s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
70 next.wing_in_r.position = Vec3::new(s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
71
72 next.wing_in_l.orientation =
73 Quaternion::rotation_y(
74 -1.0 + movement1abs * 0.8 - movement2abs * 0.4 + twitch2 * 0.03,
75 ) * Quaternion::rotation_z(0.2 - movement1abs * 0.8 + movement2abs * 0.4);
76 next.wing_in_r.orientation =
77 Quaternion::rotation_y(
78 1.0 - movement1abs * 0.8 + movement2abs * 0.4 + twitch2 * -0.03,
79 ) * Quaternion::rotation_z(-0.2 + movement1abs * 0.8 - movement2abs * 0.4);
80
81 next.wing_out_l.position = Vec3::new(-s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
82 next.wing_out_r.position = Vec3::new(s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
83 next.wing_out_l.orientation =
84 Quaternion::rotation_y(-0.2) * Quaternion::rotation_z(0.2);
85 next.wing_out_r.orientation =
86 Quaternion::rotation_y(0.2) * Quaternion::rotation_z(-0.2);
87
88 next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
89 next.tail.orientation =
90 Quaternion::rotation_x(-movement1abs * 0.1 + movement2abs * 0.1 + twitch2 * 0.1);
91 } else {
92 next.head.orientation = Quaternion::rotation_x(
93 movement1abs * 0.5
94 + movement2abs * (-0.5 + velocity.xy().magnitude() * 0.2).min(0.0)
95 + look_dir.z * 0.4,
96 );
97 }
98
99 next
100 }
101}