veloren_voxygen_anim/bird_medium/
fly.rs1use super::{
2 super::{Animation, vek::*},
3 BirdMediumSkeleton, SkeletonAttr,
4};
5
6pub struct FlyAnimation;
7
8impl Animation for FlyAnimation {
9 type Dependency<'a> = (Vec3<f32>, Vec3<f32>, Vec3<f32>);
10 type Skeleton = BirdMediumSkeleton;
11
12 #[cfg(feature = "use-dyn-lib")]
13 const UPDATE_FN: &'static [u8] = b"bird_medium_fly\0";
14
15 #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_medium_fly")]
16 fn update_skeleton_inner<'a>(
17 skeleton: &Self::Skeleton,
18 (velocity, orientation, last_ori): Self::Dependency<'_>,
19 anim_time: f32,
20 _rate: &mut f32,
21 s_a: &SkeletonAttr,
22 ) -> Self::Skeleton {
23 let mut next = (*skeleton).clone();
24
25 let slow = (anim_time * 2.0).sin();
26 let fast = (anim_time * 4.0).sin();
27
28 let freq = 8.0;
30 let off1 = 0.0;
31 let off2 = -1.7;
32 let off3 = -2.0;
33 let off4 = -2.4;
34 let flap1 = 7.0 / 16.0 * (freq * anim_time + off1).sin()
35 + 7.0 / 64.0 * (freq * 2.0 * anim_time + off1).sin()
36 + 1.0 / 48.0 * (freq * 3.0 * anim_time + off1).sin();
37 let flap2 = 7.0 / 16.0 * (freq * anim_time + off2).sin()
38 + 7.0 / 64.0 * (freq * 2.0 * anim_time + off2).sin()
39 + 1.0 / 48.0 * (freq * 3.0 * anim_time + off2).sin();
40 let flap3 = 7.0 / 16.0 * (freq * anim_time + off3).sin()
41 + 7.0 / 64.0 * (freq * 2.0 * anim_time + off3).sin()
42 + 1.0 / 48.0 * (freq * 3.0 * anim_time + off3).sin();
43 let flap4 = 7.0 / 16.0 * (freq * anim_time + off4).sin()
44 + 7.0 / 64.0 * (freq * 2.0 * anim_time + off4).sin()
45 + 1.0 / 48.0 * (freq * 3.0 * anim_time + off4).sin();
46
47 let ori: Vec2<f32> = Vec2::from(orientation);
48 let last_ori = Vec2::from(last_ori);
49 let tilt = if vek::Vec2::new(ori, last_ori)
50 .map(|o| o.magnitude_squared())
51 .map(|m| m > 0.001 && m.is_finite())
52 .reduce_and()
53 && ori.angle_between(last_ori).is_finite()
54 {
55 ori.angle_between(last_ori).min(0.2)
56 * last_ori.determine_side(Vec2::zero(), ori).signum()
57 } else {
58 0.0
59 } * 1.3;
60
61 next.head.scale = Vec3::one() * 0.99;
62 next.leg_l.scale = Vec3::one() * s_a.scaler * 0.99;
63 next.leg_r.scale = Vec3::one() * s_a.scaler * 0.99;
64 next.chest.scale = Vec3::one() * s_a.scaler * 0.99;
65 next.tail.scale = Vec3::one() * 1.01;
66
67 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
68
69 next.head.orientation = Quaternion::rotation_x(
70 (-0.5 + 0.2 * velocity.xy().magnitude() / 5.0).min(-0.3) + fast * 0.05,
71 );
72
73 if velocity.z > 2.0 || velocity.xy().magnitude() < 12.0 {
74 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 - flap4 * 1.5);
75 next.chest.orientation = Quaternion::rotation_x(
76 (0.2 - 0.2 * velocity.xy().magnitude() / 5.0).max(-0.2) - flap1 * 0.2,
77 ) * Quaternion::rotation_y(tilt * 1.8 + fast * 0.01);
78
79 next.wing_in_l.position = Vec3::new(-s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
80 next.wing_in_r.position = Vec3::new(s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
81
82 next.wing_in_l.orientation =
83 Quaternion::rotation_y(-flap1 * 1.9 + 0.2) * Quaternion::rotation_x(0.4);
84 next.wing_in_r.orientation =
85 Quaternion::rotation_y(flap1 * 1.9 - 0.2) * Quaternion::rotation_x(0.4);
86
87 next.wing_out_l.position = Vec3::new(-s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
88 next.wing_out_r.position = Vec3::new(s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
89
90 next.wing_out_l.orientation = Quaternion::rotation_y(-flap3 * 1.2 - 0.3);
91 next.wing_out_r.orientation = Quaternion::rotation_y(flap3 * 1.2 + 0.3);
92
93 next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
94 next.tail.orientation =
95 Quaternion::rotation_x(-flap2 * 0.2 + 0.1) * Quaternion::rotation_z(tilt * 1.0);
96
97 next.leg_l.position = Vec3::new(-s_a.leg.0, s_a.leg.1, s_a.leg.2 - flap4 * 1.5);
98 next.leg_l.orientation = Quaternion::rotation_x(
99 (-1.0 * velocity.xy().magnitude() / 5.0).max(-1.2) + flap1 * -0.1,
100 ) * Quaternion::rotation_y(tilt * 1.6 + fast * 0.01);
101 next.leg_r.position = Vec3::new(s_a.leg.0, s_a.leg.1, s_a.leg.2 - flap4 * 1.5);
102 next.leg_r.orientation = Quaternion::rotation_x(
103 (-1.0 * velocity.xy().magnitude() / 5.0).max(-1.2) + flap1 * -0.1,
104 ) * Quaternion::rotation_y(tilt * 1.6 + fast * 0.01);
105 } else {
106 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + slow * 0.05);
107 next.chest.orientation =
108 Quaternion::rotation_x(-0.2 + slow * 0.05 + (0.8 * velocity.z / 80.0).min(0.8))
109 * Quaternion::rotation_y(tilt * 1.8 + fast * 0.01);
110
111 next.wing_in_l.position = Vec3::new(-s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
112 next.wing_in_r.position = Vec3::new(s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
113
114 next.wing_in_l.orientation =
115 Quaternion::rotation_y(0.1 + slow * 0.04 + (0.8 * velocity.z / 80.0).min(0.8))
116 * Quaternion::rotation_x(0.4);
117 next.wing_in_r.orientation =
118 Quaternion::rotation_y(-0.1 + slow * -0.04 - (0.8 * velocity.z / 80.0).min(0.8))
119 * Quaternion::rotation_x(0.4);
120
121 next.wing_out_l.position = Vec3::new(-s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
122 next.wing_out_r.position = Vec3::new(s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
123 next.wing_out_l.orientation =
124 Quaternion::rotation_y(0.1 + slow * 0.04 + (0.4 * velocity.z / 80.0).min(0.2));
125 next.wing_out_r.orientation =
126 Quaternion::rotation_y(-0.1 + slow * -0.04 - (0.4 * velocity.z / 80.0).min(0.2));
127
128 next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
129 next.tail.orientation =
130 Quaternion::rotation_x(0.04 - slow * 0.04) * Quaternion::rotation_z(tilt * 1.0);
131
132 next.leg_l.position = Vec3::new(-s_a.leg.0, s_a.leg.1, s_a.leg.2 + 1.0 + slow * 0.05);
133 next.leg_l.orientation = Quaternion::rotation_x(-1.2 + slow * -0.05)
134 * Quaternion::rotation_y(tilt * 1.6 + fast * 0.01);
135 next.leg_r.position = Vec3::new(s_a.leg.0, s_a.leg.1, s_a.leg.2 + 1.0 + slow * 0.05);
136 next.leg_r.orientation = Quaternion::rotation_x(-1.2 + slow * -0.05)
137 * Quaternion::rotation_y(tilt * 1.6 + fast * 0.01);
138 }
139
140 next
141 }
142}