veloren_voxygen_anim/character/
music.rs1use super::{
2 super::{Animation, vek::*},
3 CharacterSkeleton, SkeletonAttr,
4};
5use common::{
6 comp::item::{Hands, ToolKind},
7 states::utils::AbilityInfo,
8};
9use std::{f32::consts::PI, ops::Mul};
10
11pub struct MusicAnimation;
12
13type MusicAnimationDependency<'a> = (
14 (Option<Hands>, Option<Hands>),
15 (Option<AbilityInfo>, f32),
16 Vec3<f32>,
17 Option<&'a str>,
18);
19impl Animation for MusicAnimation {
20 type Dependency<'a> = MusicAnimationDependency<'a>;
21 type Skeleton = CharacterSkeleton;
22
23 #[cfg(feature = "use-dyn-lib")]
24 const UPDATE_FN: &'static [u8] = b"character_music\0";
25
26 #[cfg_attr(feature = "be-dyn-lib", export_name = "character_music")]
27 fn update_skeleton_inner(
28 skeleton: &Self::Skeleton,
29 (_hands, (ability_info, global_time), rel_vel, ability_id): Self::Dependency<'_>,
30 anim_time: f32,
31 rate: &mut f32,
32 s_a: &SkeletonAttr,
33 ) -> Self::Skeleton {
34 let mut next = (*skeleton).clone();
35
36 *rate = 2.0;
37
38 let lab: f32 = 1.0;
39 let short = ((5.0 / (3.0 + 2.0 * ((anim_time * lab * 6.0).sin()).powi(2))).sqrt())
40 * ((anim_time * lab * 6.0).sin());
41 let noisea = (anim_time * 11.0 + PI / 6.0).sin();
42 let noiseb = (anim_time * 19.0 + PI / 4.0).sin();
43
44 let shorte = (anim_time * lab * 6.0).sin();
45
46 let shortealt = (anim_time * lab * 6.0 + PI / 2.0).sin();
47
48 let foot = ((0.1 / (1.0 + (4.0) * ((anim_time * lab * 8.0).sin()).powi(2))).sqrt())
49 * ((anim_time * lab * 8.0).sin());
50
51 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + shortealt * 1.5);
53 next.chest.orientation = Quaternion::rotation_z(short * 0.35)
54 * Quaternion::rotation_y(shorte * 0.08)
55 * Quaternion::rotation_x(foot * 0.07);
56
57 next.belt.position = Vec3::new(0.0, s_a.belt.0, s_a.belt.1);
58 next.belt.orientation = Quaternion::rotation_z(shorte * 0.25);
59
60 next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
61 next.back.orientation =
62 Quaternion::rotation_x(-0.25 + shorte * 0.1 + noisea * 0.1 + noiseb * 0.1);
63
64 next.shorts.position = Vec3::new(0.0, s_a.shorts.0, s_a.shorts.1);
65 next.shorts.orientation = Quaternion::rotation_z(foot * 0.35);
66
67 if rel_vel.magnitude() < 0.1 {
69 next.foot_l.position = Vec3::new(
70 -s_a.foot.0 + foot * 0.8,
71 1.5 + -s_a.foot.1 + foot * -4.0,
72 s_a.foot.2,
73 );
74 next.foot_l.orientation =
75 Quaternion::rotation_x(foot * -0.3) * Quaternion::rotation_z(short * -0.15);
76
77 next.foot_r.position = Vec3::new(
78 s_a.foot.0 + foot * 0.8,
79 1.5 + -s_a.foot.1 + foot * 4.0,
80 s_a.foot.2,
81 );
82 next.foot_r.orientation =
83 Quaternion::rotation_x(foot * 0.3) * Quaternion::rotation_z(short * 0.15);
84 };
85 next.shoulder_l.position = Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
86 next.shoulder_l.orientation = Quaternion::rotation_x(shorte * 0.15);
87
88 next.shoulder_r.position = Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
89 next.shoulder_r.orientation = Quaternion::rotation_x(shorte * -0.15);
90
91 next.lantern.orientation = match ability_id {
92 Some("common.abilities.music.kora" | "common.abilities.music.banjo") => {
93 Quaternion::rotation_x(shorte * 0.2) * Quaternion::rotation_y(shorte * 0.2)
94 },
95 _ => Quaternion::rotation_x(shorte * 0.7 + 0.4) * Quaternion::rotation_y(shorte * 0.4),
96 };
97
98 next.torso.position = Vec3::new(0.0, -3.3, 0.0);
99 next.torso.orientation = Quaternion::rotation_z(short * -0.2);
100
101 let head_look = Vec2::new(
102 (global_time + anim_time / 6.0).floor().mul(7331.0).sin() * 0.3,
103 (global_time + anim_time / 6.0).floor().mul(1337.0).sin() * 0.15,
104 );
105
106 match ability_info.and_then(|a| a.tool) {
107 Some(ToolKind::Instrument) => {
108 let head_bop = match ability_id {
110 Some(
111 "common.abilities.music.flute"
112 | "common.abilities.music.glass_flute"
113 | "common.abilities.music.melodica",
114 ) => 0.2,
115 Some(
116 "common.abilities.music.guitar"
117 | "common.abilities.music.dark_guitar"
118 | "common.abilities.music.lute"
119 | "common.abilities.music.kora"
120 | "common.abilities.music.banjo"
121 | "common.abilities.music.sitar",
122 ) => 0.5,
123
124 Some(
125 "common.abilities.music.lyre"
126 | "common.abilities.music.icy_talharpa"
127 | "common.abilities.music.shamisen"
128 | "common.abilities.music.kalimba"
129 | "common.abilities.music.steeltonguedrum",
130 ) => 0.3,
131 _ => 1.0,
132 };
133 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
134 next.head.orientation = Quaternion::rotation_z((short * head_bop) * -0.6)
135 * Quaternion::rotation_x(
136 0.2 + head_look.y.max(0.0) + (shorte * head_bop).abs() * -0.2,
137 );
138 match ability_id {
140 Some("common.abilities.music.double_bass") => {
141 next.hand_l.position = Vec3::new(
142 3.5 - s_a.hand.0,
143 7.0 + s_a.hand.1 + shortealt * -3.0,
144 8.0 + s_a.hand.2 + shortealt * -0.75,
145 );
146 next.hand_l.orientation = Quaternion::rotation_x(2.4 + foot * 0.15)
147 * Quaternion::rotation_y(-0.5);
148
149 next.hand_r.position = Vec3::new(
150 -2.0 + s_a.hand.0,
151 4.0 + s_a.hand.1 + shortealt * 6.0,
152 4.0 + s_a.hand.2 + shortealt * 0.75,
153 );
154 next.hand_r.orientation = Quaternion::rotation_x(1.4 + foot * -0.15)
155 * Quaternion::rotation_y(0.4);
156
157 next.main.position = Vec3::new(-4.0, 6.0, 16.0);
158 next.main.orientation = Quaternion::rotation_x(0.1)
159 * Quaternion::rotation_y(3.0)
160 * Quaternion::rotation_z(PI / -3.0);
161 },
162 Some("common.abilities.music.kora") => {
163 next.hand_l.position = Vec3::new(
164 5.0 - s_a.hand.0 + shortealt * 1.0,
165 8.0 + s_a.hand.1 + shortealt * -1.0,
166 5.0 + s_a.hand.2 + shortealt * -0.5,
167 );
168 next.hand_l.orientation = Quaternion::rotation_x(1.2 + foot * 0.15)
169 * Quaternion::rotation_y(-0.5 - foot * 0.3);
170
171 next.hand_r.position = Vec3::new(
172 -4.5 + s_a.hand.0 - shortealt * 1.0,
173 8.0 + s_a.hand.1 + shortealt * 1.0,
174 4.0 + s_a.hand.2 + shortealt * 0.5,
175 );
176 next.hand_r.orientation = Quaternion::rotation_x(1.4 + foot * -0.15)
177 * Quaternion::rotation_y(0.4 + foot * 0.3);
178
179 next.main.position = Vec3::new(0.0, 16.0, 14.0);
180 next.main.orientation = Quaternion::rotation_x(-0.5)
181 * Quaternion::rotation_y(3.0)
182 * Quaternion::rotation_z(1.3);
183 },
184 Some("common.abilities.music.flute" | "common.abilities.music.glass_flute") => {
185 next.hand_l.position = Vec3::new(
186 4.0 - s_a.hand.0,
187 6.0 + s_a.hand.1 + shortealt * -0.5,
188 4.0 + s_a.hand.2 + shortealt * -0.75,
189 );
190 next.hand_l.orientation = Quaternion::rotation_x(2.4 + foot * 0.15)
191 * Quaternion::rotation_y(-0.9);
192
193 next.hand_r.position = Vec3::new(
194 -4.5 + s_a.hand.0,
195 4.0 + s_a.hand.1 + shortealt * 2.0,
196 2.0 + s_a.hand.2 + shortealt * 0.75,
197 );
198 next.hand_r.orientation = Quaternion::rotation_x(1.4 + foot * -0.15)
199 * Quaternion::rotation_y(0.6);
200
201 next.main.position = Vec3::new(-2.5, 10.0, -11.0);
202 next.main.orientation = Quaternion::rotation_x(3.5)
203 * Quaternion::rotation_y(PI)
204 * Quaternion::rotation_z(0.05);
205 },
206 Some(
207 "common.abilities.music.guitar" | "common.abilities.music.dark_guitar",
208 ) => {
209 next.hand_l.position = Vec3::new(
210 1.0 - s_a.hand.0,
211 6.0 + s_a.hand.1 + shortealt * -1.0,
212 2.0 + s_a.hand.2 + shortealt * -1.5,
213 );
214 next.hand_l.orientation = Quaternion::rotation_x(1.8 + foot * 0.15)
215 * Quaternion::rotation_y(-0.6)
216 * Quaternion::rotation_z(0.8);
217
218 next.hand_r.position = Vec3::new(
219 -2.0 + s_a.hand.0 - shortealt * 1.25,
220 6.0 + s_a.hand.1 + shortealt * 2.0,
221 3.0 + s_a.hand.2 + shortealt * 0.25,
222 );
223 next.hand_r.orientation = Quaternion::rotation_x(1.0 + foot * -0.15)
224 * Quaternion::rotation_y(0.6);
225
226 next.main.position = Vec3::new(-14.0, 6.0, 5.0);
227 next.main.orientation = Quaternion::rotation_x(0.1)
228 * Quaternion::rotation_y(2.0)
229 * Quaternion::rotation_z(PI / -3.0);
230 },
231 Some(
232 "common.abilities.music.lyre"
233 | "common.abilities.music.wildskin_drum"
234 | "common.abilities.music.steeltonguedrum"
235 | "common.abilities.music.icy_talharpa",
236 ) => {
237 next.hand_l.position = Vec3::new(
238 3.0 - s_a.hand.0,
239 4.0 + s_a.hand.1 + shortealt * -0.1,
240 1.0 + s_a.hand.2 + shortealt * -0.2,
241 );
242 next.hand_l.orientation = Quaternion::rotation_x(1.4 + foot * 0.15)
243 * Quaternion::rotation_y(-0.6);
244
245 next.hand_r.position = Vec3::new(
246 -4.0 + s_a.hand.0 + shortealt * 2.0,
247 5.0 + s_a.hand.1 - shortealt * 3.0,
248 2.0 + s_a.hand.2 + shortealt * 0.75,
249 );
250 next.hand_r.orientation = Quaternion::rotation_x(1.4 + foot * -0.15)
251 * Quaternion::rotation_y(0.9);
252
253 next.main.position = Vec3::new(8.0, 14.0, -6.0);
254 next.main.orientation = Quaternion::rotation_x(0.2)
255 * Quaternion::rotation_y(-0.75)
256 * Quaternion::rotation_z(0.20);
257 },
258 Some("common.abilities.music.kalimba") => {
259 next.hand_l.position = Vec3::new(
260 3.0 - s_a.hand.0,
261 4.0 + s_a.hand.1 + shortealt * -0.1,
262 1.0 + s_a.hand.2 + shortealt * -0.2,
263 );
264 next.hand_l.orientation = Quaternion::rotation_x(1.4 + foot * 0.15)
265 * Quaternion::rotation_y(-0.6);
266
267 next.hand_r.position = Vec3::new(
268 -2.0 + s_a.hand.0 + shortealt * 2.0,
269 5.0 + s_a.hand.1 - shortealt * 3.0,
270 2.0 + s_a.hand.2 + shortealt * 0.75,
271 );
272 next.hand_r.orientation = Quaternion::rotation_x(1.4 + foot * -0.15)
273 * Quaternion::rotation_y(0.9);
274
275 next.main.position = Vec3::new(8.0, 12.0, -8.0);
276 next.main.orientation = Quaternion::rotation_x(0.2)
277 * Quaternion::rotation_y(-0.75)
278 * Quaternion::rotation_z(PI - 0.2);
279 },
280 Some(
281 "common.abilities.music.lute"
282 | "common.abilities.music.shamisen"
283 | "common.abilities.music.banjo",
284 ) => {
285 next.hand_l.position = Vec3::new(
286 2.0 - s_a.hand.0,
287 5.0 + s_a.hand.1 + shortealt * -1.0,
288 2.0 + s_a.hand.2 + shortealt * -1.5,
289 );
290 next.hand_l.orientation = Quaternion::rotation_x(1.8 + foot * 0.15)
291 * Quaternion::rotation_y(-0.6)
292 * Quaternion::rotation_z(0.8);
293
294 next.hand_r.position = Vec3::new(
295 -1.0 + s_a.hand.0 - shortealt * 1.25,
296 6.0 + s_a.hand.1 + shortealt * 2.0,
297 2.0 + s_a.hand.2 + shortealt * 0.25,
298 );
299 next.hand_r.orientation = Quaternion::rotation_x(1.0 + foot * -0.15)
300 * Quaternion::rotation_y(0.6);
301
302 next.main.position = Vec3::new(-14.0, 6.0, 4.0);
303 next.main.orientation = Quaternion::rotation_x(0.1)
304 * Quaternion::rotation_y(2.0)
305 * Quaternion::rotation_z(PI / -3.0);
306 },
307 Some("common.abilities.music.melodica") => {
308 next.hand_l.position = Vec3::new(
309 4.0 - s_a.hand.0,
310 6.0 + s_a.hand.1 + shortealt * -0.5,
311 4.0 + s_a.hand.2 + shortealt * -0.75,
312 );
313 next.hand_l.orientation = Quaternion::rotation_x(2.4 + foot * 0.15)
314 * Quaternion::rotation_y(-0.9);
315
316 next.hand_r.position = Vec3::new(
317 -3.5 + s_a.hand.0,
318 4.0 + s_a.hand.1 + shortealt * 2.0,
319 2.0 + s_a.hand.2 + shortealt * 0.75,
320 );
321 next.hand_r.orientation = Quaternion::rotation_x(1.4 + foot * -0.15)
322 * Quaternion::rotation_y(0.6);
323
324 next.main.position = Vec3::new(-1.0, 2.0, 16.0);
325 next.main.orientation = Quaternion::rotation_x(0.3)
326 * Quaternion::rotation_y(PI)
327 * Quaternion::rotation_z(PI / -2.0);
328 },
329 Some("common.abilities.music.washboard") => {
330 next.hand_l.position = Vec3::new(
331 3.0 - s_a.hand.0,
332 4.0 + s_a.hand.1 + shortealt * -0.1,
333 1.0 + s_a.hand.2 + shortealt * -0.2,
334 );
335 next.hand_l.orientation = Quaternion::rotation_x(1.4 + foot * 0.15)
336 * Quaternion::rotation_y(-0.6);
337
338 next.hand_r.position = Vec3::new(
339 -4.0 + s_a.hand.0 + shortealt * 2.0,
340 5.0 + s_a.hand.1 - shortealt * 3.0,
341 2.0 + s_a.hand.2 + shortealt * 0.75,
342 );
343 next.hand_r.orientation = Quaternion::rotation_x(1.4 + foot * -0.15)
344 * Quaternion::rotation_y(0.9);
345
346 next.main.position = Vec3::new(8.0, 14.0, -6.0);
347 next.main.orientation = Quaternion::rotation_x(0.2)
348 * Quaternion::rotation_y(-0.75)
349 * Quaternion::rotation_z(0.20);
350 },
351 Some("common.abilities.music.sitar") => {
352 next.hand_l.position = Vec3::new(
353 2.0 - s_a.hand.0,
354 6.0 + s_a.hand.1 + shortealt * -1.0,
355 1.0 + s_a.hand.2 + shortealt * -1.5,
356 );
357 next.hand_l.orientation = Quaternion::rotation_x(1.8 + foot * 0.15)
358 * Quaternion::rotation_y(-0.6)
359 * Quaternion::rotation_z(0.8);
360
361 next.hand_r.position = Vec3::new(
362 -2.0 + s_a.hand.0 - shortealt * 1.25,
363 6.0 + s_a.hand.1 + shortealt * 2.0,
364 2.0 + s_a.hand.2 + shortealt * 0.25,
365 );
366 next.hand_r.orientation = Quaternion::rotation_x(1.0 + foot * -0.15)
367 * Quaternion::rotation_y(0.6);
368
369 next.main.position = Vec3::new(-15.0, 6.0, 4.0);
370 next.main.orientation = Quaternion::rotation_x(0.1)
371 * Quaternion::rotation_y(2.0)
372 * Quaternion::rotation_z(PI / -3.0);
373 },
374 _ => {},
375 }
376 },
377 _ => {},
378 }
379
380 if skeleton.holding_lantern {
381 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1 + 5.0, s_a.hand.2 + 12.0);
382 next.hand_r.orientation = Quaternion::rotation_x(2.25) * Quaternion::rotation_z(0.9);
383
384 next.lantern.position = Vec3::new(-0.5, -0.5, 5.5);
385 next.lantern.orientation = next.hand_r.orientation.inverse();
386 }
387
388 next
389 }
390}