veloren_voxygen_anim/biped_large/
stunned.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedLargeSkeleton, SkeletonAttr,
4};
5use common::{
6    comp::item::tool::{AbilitySpec, ToolKind},
7    states::utils::StageSection,
8};
9use core::f32::consts::PI;
10
11pub struct StunnedAnimation;
12
13impl Animation for StunnedAnimation {
14    type Dependency<'a> = (
15        (Option<ToolKind>, Option<&'a AbilitySpec>),
16        Vec3<f32>,
17        f32,
18        Option<StageSection>,
19    );
20    type Skeleton = BipedLargeSkeleton;
21
22    #[cfg(feature = "use-dyn-lib")]
23    const UPDATE_FN: &'static [u8] = b"biped_large_stunned\0";
24
25    #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_stunned")]
26    fn update_skeleton_inner(
27        skeleton: &Self::Skeleton,
28        ((active_tool_kind, active_tool_spec), velocity, acc_vel, stage_section): Self::Dependency<
29            '_,
30        >,
31        anim_time: f32,
32        _rate: &mut f32,
33        s_a: &SkeletonAttr,
34    ) -> Self::Skeleton {
35        let mut next = (*skeleton).clone();
36        let speed = Vec2::<f32>::from(velocity).magnitude();
37
38        let lab: f32 = 0.65 * s_a.tempo; //.65
39
40        let (movement1base, movement2) = match stage_section {
41            Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0),
42            Some(StageSection::Recover) => (1.0, anim_time.powf(4.0)),
43            _ => (0.0, 0.0),
44        };
45        let pullback = 1.0 - movement2;
46        let movement1 = movement1base * pullback;
47        let torso = (anim_time * lab + 1.5 * PI).sin();
48        let speednorm = (speed / 12.0).powf(0.4);
49        let foothoril = (acc_vel * lab + PI * 1.45).sin() * speednorm;
50        let foothorir = (acc_vel * lab + PI * (0.45)).sin() * speednorm;
51        let footrotl = ((1.0 / (0.5 + (0.5) * ((acc_vel * lab + PI * 1.4).sin()).powi(2))).sqrt())
52            * ((acc_vel * lab + PI * 1.4).sin());
53
54        let footrotr = ((1.0 / (0.5 + (0.5) * ((acc_vel * lab + PI * 0.4).sin()).powi(2))).sqrt())
55            * ((acc_vel * lab + PI * 0.4).sin());
56        let slower = (anim_time * 1.0 + PI).sin();
57        let slow = (anim_time * 3.5 + PI).sin();
58
59        let footvertl = (anim_time * 16.0 * lab).sin();
60        let footvertr = (anim_time * 16.0 * lab + PI).sin();
61        let handhoril = (anim_time * 16.0 * lab + PI * 1.4).sin();
62        let handhorir = (anim_time * 16.0 * lab + PI * 0.4).sin();
63
64        let short = (acc_vel * lab).sin() * speednorm;
65
66        let shortalt = (anim_time * lab * 16.0 + PI / 2.0).sin();
67        next.second.position = Vec3::new(0.0, 0.0, 0.0);
68        next.second.orientation = Quaternion::rotation_x(0.0);
69        if s_a.beast {
70            next.jaw.position = Vec3::new(0.0, s_a.jaw.0, s_a.jaw.1);
71        } else {
72            next.jaw.position = Vec3::new(0.0, s_a.jaw.0 - slower * 0.12, s_a.jaw.1 + slow * 0.2);
73
74            next.hold.scale = Vec3::one() * 0.0;
75
76            next.main.position = Vec3::new(0.0, 0.0, 0.0);
77            next.main.orientation = Quaternion::rotation_x(0.0);
78
79            next.hand_l.position = Vec3::new(s_a.grip.1, 0.0, s_a.grip.0);
80            next.hand_r.position = Vec3::new(-s_a.grip.1, 0.0, s_a.grip.0);
81
82            next.hand_l.orientation = Quaternion::rotation_x(0.0);
83            next.hand_r.orientation = Quaternion::rotation_x(0.0);
84
85            next.head.orientation =
86                Quaternion::rotation_x(movement1 * -0.2) * Quaternion::rotation_z(movement1 * -0.7);
87            next.upper_torso.orientation = Quaternion::rotation_x(movement1 * 0.5);
88            next.lower_torso.orientation = Quaternion::rotation_x(movement1 * -0.5);
89
90            if speed > 0.5 {
91                next.shoulder_l.position = Vec3::new(
92                    -s_a.shoulder.0,
93                    s_a.shoulder.1,
94                    s_a.shoulder.2 - foothorir * 1.0,
95                );
96                next.shoulder_l.orientation =
97                    Quaternion::rotation_x(0.6 * speednorm + (footrotr * -0.2) * speednorm);
98
99                next.shoulder_r.position = Vec3::new(
100                    s_a.shoulder.0,
101                    s_a.shoulder.1,
102                    s_a.shoulder.2 - foothoril * 1.0,
103                );
104                next.shoulder_r.orientation =
105                    Quaternion::rotation_x(0.6 * speednorm + (footrotl * -0.2) * speednorm);
106            } else {
107                next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1) * 1.02;
108
109                next.lower_torso.orientation = Quaternion::rotation_x(0.0);
110                next.lower_torso.scale = Vec3::one() * 1.02;
111
112                next.jaw.position =
113                    Vec3::new(0.0, s_a.jaw.0 - slower * 0.12, s_a.jaw.1 + slow * 0.2);
114                next.jaw.orientation = Quaternion::rotation_x(-0.1);
115
116                next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
117                next.tail.orientation = Quaternion::rotation_z(slow * 0.2);
118
119                next.shoulder_l.position =
120                    Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
121                next.shoulder_l.orientation = Quaternion::rotation_x(0.3);
122
123                next.shoulder_r.position =
124                    Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
125                next.shoulder_r.orientation = Quaternion::rotation_x(0.3);
126            }
127
128            match active_tool_kind {
129                Some(ToolKind::Sword) => {
130                    next.control_l.position = Vec3::new(-1.0, 1.0, 1.0);
131                    next.control_r.position = Vec3::new(0.0, 2.0, -3.0);
132
133                    next.control.position = Vec3::new(
134                        -3.0,
135                        5.0 + s_a.grip.0 / 1.2,
136                        -4.0 + -s_a.grip.0 / 2.0 + short * -1.5,
137                    );
138
139                    next.control_l.orientation =
140                        Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_y(-0.2);
141                    next.control_r.orientation =
142                        Quaternion::rotation_x(PI / 2.2) * Quaternion::rotation_y(0.2);
143
144                    next.control.orientation =
145                        Quaternion::rotation_x(-0.2 + short * 0.2) * Quaternion::rotation_y(-0.1);
146                },
147                Some(ToolKind::Bow) => {
148                    next.control_l.position = Vec3::new(-1.0, -2.0, -3.0);
149                    next.control_r.position = Vec3::new(0.0, 4.0, 1.0);
150
151                    next.control.position = Vec3::new(
152                        -1.0,
153                        6.0 + s_a.grip.0 / 1.2,
154                        -5.0 + -s_a.grip.0 / 2.0 + short * -1.5,
155                    );
156
157                    next.control_l.orientation =
158                        Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_y(-0.2);
159                    next.control_r.orientation =
160                        Quaternion::rotation_x(PI / 2.2) * Quaternion::rotation_y(0.2);
161
162                    next.control.orientation = Quaternion::rotation_x(-0.2 + short * 0.2)
163                        * Quaternion::rotation_y(1.0)
164                        * Quaternion::rotation_z(-0.3);
165                },
166                Some(ToolKind::Hammer) | Some(ToolKind::Axe) => {
167                    next.control_l.position = Vec3::new(-1.0, 2.0, 12.0);
168                    next.control_r.position = Vec3::new(1.0, 2.0, -2.0);
169
170                    next.control.position = Vec3::new(
171                        4.0,
172                        0.0 + s_a.grip.0 / 1.0,
173                        -s_a.grip.0 / 0.8 + short * -1.5,
174                    );
175
176                    next.control_l.orientation =
177                        Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_y(-0.0);
178                    next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + 0.2);
179
180                    next.control.orientation =
181                        Quaternion::rotation_x(-1.0 + short * 0.2) * Quaternion::rotation_y(-1.8);
182                },
183                Some(ToolKind::Staff) => {
184                    next.control_l.position = Vec3::new(-1.0, 3.0, 12.0);
185                    next.control_r.position = Vec3::new(1.0, 2.0, 2.0);
186
187                    next.control.position = Vec3::new(
188                        -3.0,
189                        3.0 + s_a.grip.0 / 1.2,
190                        -11.0 + -s_a.grip.0 / 2.0 + short * -1.5,
191                    );
192
193                    next.control_l.orientation =
194                        Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_y(-0.5);
195                    next.control_r.orientation = Quaternion::rotation_x(PI / 2.5)
196                        * Quaternion::rotation_y(0.5)
197                        * Quaternion::rotation_z(0.0);
198
199                    next.control.orientation =
200                        Quaternion::rotation_x(-0.2 + short * 0.2) * Quaternion::rotation_y(-0.1);
201                },
202                Some(ToolKind::Natural) => {
203                    if let Some(AbilitySpec::Custom(spec)) = active_tool_spec {
204                        match spec.as_str() {
205                            "Wendigo Magic" => {
206                                next.control_l.position = Vec3::new(-9.0, 19.0, -13.0);
207                                next.control_r.position = Vec3::new(9.0, 19.0, -13.0);
208
209                                next.control_l.orientation = Quaternion::rotation_x(PI / 3.0)
210                                    * Quaternion::rotation_y(-0.15);
211                                next.control_r.orientation =
212                                    Quaternion::rotation_x(PI / 3.0) * Quaternion::rotation_y(0.15);
213                            },
214                            "Tidal Warrior" => {
215                                next.head.orientation = Quaternion::rotation_x(movement1 * -2.0);
216                                next.upper_torso.orientation =
217                                    Quaternion::rotation_z(movement1 * 1.0);
218                                next.lower_torso.orientation =
219                                    Quaternion::rotation_z(movement1 * -1.0);
220                                next.hand_l.position = Vec3::new(-14.0, 2.0, -4.0);
221                                next.hand_r.position = Vec3::new(14.0, 2.0, -4.0);
222
223                                next.hand_l.orientation = Quaternion::rotation_x(PI / 3.0)
224                                    * Quaternion::rotation_z(-0.35);
225                                next.hand_r.orientation =
226                                    Quaternion::rotation_x(PI / 3.0) * Quaternion::rotation_z(0.35);
227                            },
228                            "Beast Claws" | "Tursus Claws" | "Strigoi Claws" => {
229                                next.shoulder_l.position =
230                                    Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
231
232                                next.shoulder_r.position =
233                                    Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
234
235                                next.hand_l.position =
236                                    Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2 + torso * 0.6);
237
238                                next.hand_r.position =
239                                    Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2 + torso * 0.6);
240
241                                if speed < 0.5 {
242                                    next.head.position =
243                                        Vec3::new(0.0, s_a.head.0, s_a.head.1 + torso * 0.2) * 1.02;
244                                    next.head.orientation =
245                                        Quaternion::rotation_z(0.0) * Quaternion::rotation_x(0.0);
246
247                                    next.upper_torso.position = Vec3::new(
248                                        0.0,
249                                        s_a.upper_torso.0,
250                                        s_a.upper_torso.1 + torso * 0.5,
251                                    );
252
253                                    next.lower_torso.position = Vec3::new(
254                                        0.0,
255                                        s_a.lower_torso.0,
256                                        s_a.lower_torso.1 + torso * 0.15,
257                                    );
258
259                                    next.jaw.orientation = Quaternion::rotation_x(-0.1);
260
261                                    next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
262                                    next.tail.orientation = Quaternion::rotation_z(slow * 0.2);
263
264                                    next.second.orientation = Quaternion::rotation_x(PI);
265
266                                    next.main.position = Vec3::new(0.0, 0.0, 0.0);
267                                    next.main.orientation = Quaternion::rotation_y(0.0);
268
269                                    next.shoulder_l.position =
270                                        Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
271
272                                    next.hand_l.position = Vec3::new(
273                                        -s_a.hand.0,
274                                        s_a.hand.1,
275                                        s_a.hand.2 + torso * 0.6,
276                                    );
277
278                                    next.hand_r.position =
279                                        Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2 + torso * 0.6);
280
281                                    next.leg_l.position =
282                                        Vec3::new(-s_a.leg.0, s_a.leg.1, s_a.leg.2 + torso * 0.2);
283                                    next.leg_l.orientation =
284                                        Quaternion::rotation_z(0.0) * Quaternion::rotation_x(0.0);
285
286                                    next.leg_r.position =
287                                        Vec3::new(s_a.leg.0, s_a.leg.1, s_a.leg.2 + torso * 0.2);
288                                    next.leg_r.orientation =
289                                        Quaternion::rotation_z(0.0) * Quaternion::rotation_x(0.0);
290                                } else {
291                                    next.head.position =
292                                        Vec3::new(0.0, s_a.head.0, s_a.head.1) * 1.02;
293                                    next.head.orientation = Quaternion::rotation_z(short * -0.18)
294                                        * Quaternion::rotation_x(-0.05);
295                                    next.head.scale = Vec3::one() * 1.02;
296
297                                    next.upper_torso.position = Vec3::new(
298                                        0.0,
299                                        s_a.upper_torso.0,
300                                        s_a.upper_torso.1 + shortalt * -1.5,
301                                    );
302                                    next.upper_torso.orientation =
303                                        Quaternion::rotation_z(short * 0.18);
304
305                                    next.lower_torso.position =
306                                        Vec3::new(0.0, s_a.lower_torso.0, s_a.lower_torso.1);
307                                    next.lower_torso.orientation =
308                                        Quaternion::rotation_z(short * 0.15)
309                                            * Quaternion::rotation_x(0.14);
310                                    next.lower_torso.scale = Vec3::one() * 1.02;
311
312                                    next.jaw.position = Vec3::new(0.0, s_a.jaw.0, s_a.jaw.1);
313                                    next.jaw.orientation = Quaternion::rotation_x(0.0);
314                                    next.jaw.scale = Vec3::one() * 1.02;
315
316                                    next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
317                                    next.tail.orientation = Quaternion::rotation_x(shortalt * 0.3);
318
319                                    next.second.position = Vec3::new(0.0, 0.0, 0.0);
320                                    next.second.orientation = Quaternion::rotation_x(PI)
321                                        * Quaternion::rotation_y(0.0)
322                                        * Quaternion::rotation_z(0.0);
323                                    next.second.scale = Vec3::one() * 0.0;
324
325                                    next.control.position = Vec3::new(0.0, 0.0, 0.0);
326                                    next.control.orientation = Quaternion::rotation_z(0.0);
327
328                                    next.main.position = Vec3::new(0.0, 0.0, 0.0);
329                                    next.main.orientation = Quaternion::rotation_y(0.0);
330
331                                    next.shoulder_l.position = Vec3::new(
332                                        -s_a.shoulder.0,
333                                        s_a.shoulder.1 + foothoril * -3.0,
334                                        s_a.shoulder.2,
335                                    );
336                                    next.shoulder_l.orientation =
337                                        Quaternion::rotation_x(footrotl * -0.36)
338                                            * Quaternion::rotation_y(0.1)
339                                            * Quaternion::rotation_z(footrotl * 0.3);
340
341                                    next.shoulder_r.position = Vec3::new(
342                                        s_a.shoulder.0,
343                                        s_a.shoulder.1 + foothorir * -3.0,
344                                        s_a.shoulder.2,
345                                    );
346                                    next.shoulder_r.orientation =
347                                        Quaternion::rotation_x(footrotr * -0.36)
348                                            * Quaternion::rotation_y(-0.1)
349                                            * Quaternion::rotation_z(footrotr * -0.3);
350
351                                    next.hand_l.position = Vec3::new(
352                                        -1.0 + -s_a.hand.0,
353                                        s_a.hand.1 + foothoril * -4.0,
354                                        s_a.hand.2 + foothoril * 1.0,
355                                    );
356                                    next.hand_l.orientation =
357                                        Quaternion::rotation_x(0.15 + (handhoril * -1.2).max(-0.3))
358                                            * Quaternion::rotation_y(handhoril * -0.1);
359
360                                    next.hand_r.position = Vec3::new(
361                                        1.0 + s_a.hand.0,
362                                        s_a.hand.1 + foothorir * -4.0,
363                                        s_a.hand.2 + foothorir * 1.0,
364                                    );
365                                    next.hand_r.orientation =
366                                        Quaternion::rotation_x(0.15 + (handhorir * -1.2).max(-0.3))
367                                            * Quaternion::rotation_y(handhorir * 0.1);
368                                    next.hand_r.scale = Vec3::one() * 1.04;
369
370                                    next.leg_l.position =
371                                        Vec3::new(-s_a.leg.0, s_a.leg.1, s_a.leg.2) * 0.98;
372                                    next.leg_l.orientation = Quaternion::rotation_z(short * 0.18)
373                                        * Quaternion::rotation_x(foothoril * 0.3);
374                                    next.leg_r.position =
375                                        Vec3::new(s_a.leg.0, s_a.leg.1, s_a.leg.2) * 0.98;
376
377                                    next.leg_r.orientation = Quaternion::rotation_z(short * 0.18)
378                                        * Quaternion::rotation_x(foothorir * 0.3);
379
380                                    next.foot_l.position = Vec3::new(
381                                        -s_a.foot.0,
382                                        s_a.foot.1 + foothoril * 8.5,
383                                        s_a.foot.2 + ((footvertl * 6.5).max(0.0)),
384                                    );
385                                    next.foot_l.orientation =
386                                        Quaternion::rotation_x(-0.5 + footrotl * 0.85);
387
388                                    next.foot_r.position = Vec3::new(
389                                        s_a.foot.0,
390                                        s_a.foot.1 + foothorir * 8.5,
391                                        s_a.foot.2 + ((footvertr * 6.5).max(0.0)),
392                                    );
393                                    next.foot_r.orientation =
394                                        Quaternion::rotation_x(-0.5 + footrotr * 0.85);
395
396                                    next.torso.orientation = Quaternion::rotation_x(-0.25);
397                                }
398                            },
399                            "Minotaur" => {
400                                next.control_l.position = Vec3::new(0.0, 4.0, 5.0);
401                                next.control_r.position = Vec3::new(0.0, 4.0, 5.0);
402                                next.weapon_l.position = Vec3::new(-12.0, -6.0, -18.0);
403                                next.weapon_r.position = Vec3::new(12.0, -6.0, -18.0);
404
405                                next.weapon_l.orientation = Quaternion::rotation_x(-PI / 2.0 - 0.1);
406                                next.weapon_r.orientation = Quaternion::rotation_x(-PI / 2.0 - 0.1);
407
408                                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0);
409                                next.control_r.orientation = Quaternion::rotation_x(PI / 2.0);
410
411                                next.control.orientation =
412                                    Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0);
413                                next.shoulder_l.orientation = Quaternion::rotation_x(-0.3);
414
415                                next.shoulder_r.orientation = Quaternion::rotation_x(-0.3);
416                            },
417                            _ => {},
418                        }
419                    }
420                },
421                _ => {},
422            }
423        }
424
425        if s_a.float {
426            next.upper_torso.position = Vec3::new(
427                0.0,
428                s_a.upper_torso.0,
429                s_a.upper_torso.1 + slower * 1.0 + 4.0,
430            );
431            next.foot_l.orientation = Quaternion::rotation_x(-0.5 + slow * 0.1);
432            next.foot_r.orientation = Quaternion::rotation_x(-0.5 + slow * 0.1);
433        }
434
435        next
436    }
437}