veloren_voxygen_anim/biped_large/
dash.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 DashAnimation;
12
13impl Animation for DashAnimation {
14    type Dependency<'a> = (
15        Option<ToolKind>,
16        (Option<ToolKind>, Option<&'a AbilitySpec>),
17        Vec3<f32>,
18        f32,
19        Option<StageSection>,
20        f32,
21        Option<&'a str>,
22    );
23    type Skeleton = BipedLargeSkeleton;
24
25    #[cfg(feature = "use-dyn-lib")]
26    const UPDATE_FN: &'static [u8] = b"biped_large_dash\0";
27
28    #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_dash")]
29    fn update_skeleton_inner(
30        skeleton: &Self::Skeleton,
31        (
32            active_tool_kind,
33            _second_tool,
34            velocity,
35            _global_time,
36            stage_section,
37            acc_vel,
38            ability_id,
39        ): Self::Dependency<'_>,
40        anim_time: f32,
41        rate: &mut f32,
42        s_a: &SkeletonAttr,
43    ) -> Self::Skeleton {
44        *rate = 1.0;
45        let mut next = (*skeleton).clone();
46        let lab: f32 = 0.65 * s_a.tempo;
47        let speed = Vec2::<f32>::from(velocity).magnitude();
48
49        let speednorm = (speed.min(16.0) / 12.0).powf(0.4);
50        let foothoril = (acc_vel * lab + PI * 1.45).sin() * speednorm;
51        let foothorir = (acc_vel * lab + PI * (0.45)).sin() * speednorm;
52        let footrotl = ((1.0 / (0.5 + (0.5) * ((acc_vel * lab + PI * 1.4).sin()).powi(2))).sqrt())
53            * ((acc_vel * lab + PI * 1.4).sin());
54
55        let footrotr = ((1.0 / (0.5 + (0.5) * ((acc_vel * lab + PI * 0.4).sin()).powi(2))).sqrt())
56            * ((acc_vel * lab + PI * 0.4).sin());
57
58        next.main.position = Vec3::new(0.0, 0.0, 0.0);
59        next.main.orientation = Quaternion::rotation_x(0.0);
60
61        next.hand_l.position = Vec3::new(0.0, 0.0, s_a.grip.0);
62        next.hand_r.position = Vec3::new(0.0, 0.0, s_a.grip.0);
63        next.second.position = Vec3::new(0.0, 0.0, 0.0);
64        next.second.orientation = Quaternion::rotation_x(0.0);
65        next.hand_l.orientation = Quaternion::rotation_x(0.0);
66        next.hand_r.orientation = Quaternion::rotation_x(0.0);
67        let (move1base, motion, move2base, move3base, move4) = match stage_section {
68            Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0, 0.0, 0.0),
69            Some(StageSection::Charge) => (
70                1.0,
71                (acc_vel * lab).sin(),
72                (anim_time.powf(4.0)).min(1.0),
73                0.0,
74                0.0,
75            ),
76            Some(StageSection::Action) => (1.0, 1.0, 1.0, anim_time.powf(4.0), 0.0),
77            Some(StageSection::Recover) => (1.1, 1.0, 1.0, 1.0, anim_time.powf(4.0)),
78            _ => (0.0, 0.0, 0.0, 0.0, 0.0),
79        };
80        let pullback = 1.0 - move4;
81        let move1 = move1base * pullback;
82        let move2 = move2base * pullback;
83        let move3 = move3base * pullback;
84
85        next.shoulder_l.position = Vec3::new(
86            -s_a.shoulder.0,
87            s_a.shoulder.1,
88            s_a.shoulder.2 - foothorir * 1.0,
89        );
90        next.shoulder_l.orientation =
91            Quaternion::rotation_x(0.6 * speednorm + (footrotr * -0.2) * speednorm);
92
93        next.shoulder_r.position = Vec3::new(
94            s_a.shoulder.0,
95            s_a.shoulder.1,
96            s_a.shoulder.2 - foothoril * 1.0,
97        );
98        next.shoulder_r.orientation =
99            Quaternion::rotation_x(0.6 * speednorm + (footrotl * -0.2) * speednorm);
100        next.torso.orientation = Quaternion::rotation_z(0.0);
101        match active_tool_kind {
102            Some(ToolKind::Sword) => match ability_id {
103                Some("common.abilities.adlet.elder.dash") => {
104                    next.head.orientation = Quaternion::rotation_x(move1 * 0.2 + move3 * 0.1)
105                        * Quaternion::rotation_z(move1 * -0.1 + move3 * -0.2);
106                    next.upper_torso.orientation =
107                        Quaternion::rotation_x(move1 * -0.2 + move3 * 0.3)
108                            * Quaternion::rotation_z(move1 * 0.2 + move3 * -0.2);
109                    next.control_l.position = Vec3::new(0.0, 2.0, -2.0);
110                    next.control_r.position = Vec3::new(0.0, 2.0, -2.0);
111                    next.weapon_l.position =
112                        Vec3::new(-5.5 + move1 * -4.0 + move2 * 6.0, 5.0, -18.0);
113                    next.weapon_r.position =
114                        Vec3::new(6.5 + move1 * 4.0 + move2 * -6.0, 5.0, -18.0);
115                    next.second.scale = Vec3::one() * 1.0;
116
117                    next.weapon_l.orientation = Quaternion::rotation_x(-1.67 + move1 * 0.4)
118                        * Quaternion::rotation_z(move2 * -0.5);
119                    next.weapon_r.orientation = Quaternion::rotation_x(-1.67 + move1 * 0.3)
120                        * Quaternion::rotation_z(move2 * 0.5);
121
122                    next.control_l.orientation = Quaternion::rotation_x(PI / 2.0);
123                    next.control_r.orientation = Quaternion::rotation_x(PI / 2.0);
124
125                    next.control.orientation = Quaternion::rotation_x(move1 * PI + move2 * -PI);
126                    next.shoulder_l.orientation = Quaternion::rotation_x(move1 * PI + move2 * -PI);
127                    next.shoulder_r.orientation = Quaternion::rotation_x(move1 * PI + move2 * -PI);
128                },
129                _ => {
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                    next.head.orientation = Quaternion::rotation_x(move1 * -0.25)
133                        * Quaternion::rotation_z(move1 * -0.2 + move2 * 0.6);
134                    next.control.position = Vec3::new(
135                        -3.0 + move1 * -2.0 + move2 * 2.0,
136                        5.0 + s_a.grip.0 / 1.2 + move1 * -4.0 + move2 * 2.0 + move3 * 8.0,
137                        -4.0 + -s_a.grip.0 / 2.0 + move2 * -5.0 + move3 * 5.0,
138                    );
139                    next.upper_torso.orientation =
140                        Quaternion::rotation_x(move2 * -0.2 + move3 * 0.2)
141                            * Quaternion::rotation_z(move1 * 0.8 + move3 * -0.7);
142                    next.lower_torso.orientation =
143                        Quaternion::rotation_x(move2 * 0.2 + move3 * -0.2)
144                            * Quaternion::rotation_z(move1 * -0.8 + move3 * 0.7);
145                    next.control_l.orientation =
146                        Quaternion::rotation_x(PI / 2.0 + move1 * -0.5 + move2 * 1.5)
147                            * Quaternion::rotation_y(-0.2);
148                    next.control_r.orientation =
149                        Quaternion::rotation_x(PI / 2.2 + move1 * -0.5 + move2 * 1.5)
150                            * Quaternion::rotation_y(0.2)
151                            * Quaternion::rotation_z(0.0);
152
153                    next.control.orientation =
154                        Quaternion::rotation_x(-0.2 + move1 * 0.5 + move2 * -1.5 + move3 * -0.2)
155                            * Quaternion::rotation_y(
156                                -0.1 + move1 * -0.5 + move2 * 1.5 + move3 * -1.0,
157                            )
158                            * Quaternion::rotation_z(-move3 * -1.5);
159                },
160            },
161            Some(ToolKind::Axe) => {
162                next.control_l.position = Vec3::new(-1.0, 2.0, 12.0 + move3 * 3.0);
163                next.control_r.position = Vec3::new(1.0, 2.0, -2.0);
164
165                next.control.position = Vec3::new(
166                    4.0 + move1 * -3.0 + move3 * -5.0,
167                    (s_a.grip.0 / 1.0) + move1 * -1.0 + move3 * 1.0 + footrotl * 2.0,
168                    (-s_a.grip.0 / 0.8) + move1 * 2.0 + move3 * -3.0,
169                );
170                next.head.orientation = Quaternion::rotation_x(move1 * -0.5 + move3 * 0.5)
171                    * Quaternion::rotation_z(move1 * 0.3 + move3 * 0.3);
172                next.upper_torso.orientation = Quaternion::rotation_x(move1 * -0.4 + move3 * 0.9)
173                    * Quaternion::rotation_z(move1 * 0.6 + move3 * -1.5);
174                next.lower_torso.orientation = Quaternion::rotation_y(move1 * -0.2 + move3 * -0.1)
175                    * Quaternion::rotation_x(move1 * 0.4 + move3 * -0.7 + footrotr * 0.1)
176                    * Quaternion::rotation_z(move1 * -0.6 + move3 * 1.6);
177
178                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + move3 * 0.3)
179                    * Quaternion::rotation_y(move1 * 0.7);
180                next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + 0.2 + move3 * -0.2)
181                    * Quaternion::rotation_y(0.0)
182                    * Quaternion::rotation_z(0.0);
183
184                next.control.orientation =
185                    Quaternion::rotation_x(-1.0 + move1 * -0.2 + move3 * -0.2)
186                        * Quaternion::rotation_y(-1.8 + move1 * -0.2 + move3 * -0.2)
187                        * Quaternion::rotation_z(move1 * -0.8 + move3 * -0.1);
188            },
189            Some(ToolKind::Natural) => match ability_id {
190                Some("common.abilities.custom.minotaur.charge") => {
191                    next.head.orientation = Quaternion::rotation_x(move1 * 0.4 + move3 * 0.5)
192                        * Quaternion::rotation_z(move1 * -0.3 + move3 * -0.3);
193                    next.upper_torso.orientation =
194                        Quaternion::rotation_x(move1 * -0.4 + move3 * 0.9)
195                            * Quaternion::rotation_z(move1 * 0.6 + move3 * -1.5);
196                    next.lower_torso.orientation =
197                        Quaternion::rotation_y(move1 * -0.2 + move3 * -0.1)
198                            * Quaternion::rotation_x(move1 * 0.4 + move3 * -0.7 + footrotr * 0.1)
199                            * Quaternion::rotation_z(move1 * -0.6 + move3 * 1.6);
200                    next.control_l.position = Vec3::new(0.0, 4.0, 5.0);
201                    next.control_r.position = Vec3::new(0.0, 4.0, 5.0);
202                    next.weapon_l.position = Vec3::new(-12.0 + move1 * -3.0, -6.0, -18.0);
203                    next.weapon_r.position =
204                        Vec3::new(12.0 + move1 * -3.0, -6.0 + move1 * 2.0, -18.0 + move1 * 2.0);
205                    next.second.scale = Vec3::one() * 1.0;
206
207                    next.weapon_l.orientation = Quaternion::rotation_x(-1.67 + move1 * 0.4)
208                        * Quaternion::rotation_y(move1 * 0.4 + move2 * 0.2)
209                        * Quaternion::rotation_z(move3 * -0.5);
210                    next.weapon_r.orientation = Quaternion::rotation_x(-1.67 + move1 * 0.3)
211                        * Quaternion::rotation_y(move1 * 0.6 + move2 * -0.6)
212                        * Quaternion::rotation_z(move3 * -0.5);
213
214                    next.control_l.orientation = Quaternion::rotation_x(PI / 2.0);
215                    next.control_r.orientation = Quaternion::rotation_x(PI / 2.0);
216
217                    next.control.orientation =
218                        Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0);
219                    next.shoulder_l.orientation = Quaternion::rotation_x(-0.3);
220
221                    next.shoulder_r.orientation = Quaternion::rotation_x(-0.3);
222                },
223                Some("common.abilities.custom.tidalwarrior.scuttle") => {
224                    next.head.orientation =
225                        Quaternion::rotation_x(0.0) * Quaternion::rotation_z(move1 * -0.3);
226                    next.upper_torso.orientation = Quaternion::rotation_x(move1 * -0.1)
227                        * Quaternion::rotation_z(move1 * PI / 2.0);
228                    next.lower_torso.orientation = Quaternion::rotation_x(move1 * 0.1)
229                        * Quaternion::rotation_x(move1 * -0.1)
230                        * Quaternion::rotation_z(move1 * -0.2);
231
232                    next.hand_l.position = Vec3::new(-14.0, 2.0 + motion * 1.5, -4.0);
233
234                    next.hand_l.orientation = Quaternion::rotation_x(PI / 3.0 + move1 * 1.0)
235                        * Quaternion::rotation_y(0.0)
236                        * Quaternion::rotation_z(-0.35 + motion * -0.6);
237                    next.hand_r.position = Vec3::new(14.0, 2.0 + motion * -1.5, -4.0);
238
239                    next.hand_r.orientation = Quaternion::rotation_x(PI / 3.0 + move1 * 1.0)
240                        * Quaternion::rotation_y(0.0)
241                        * Quaternion::rotation_z(0.35 + motion * 0.6);
242
243                    next.shoulder_l.orientation = Quaternion::rotation_x(move1 * 0.8);
244
245                    next.shoulder_r.orientation = Quaternion::rotation_x(move1 * 0.8);
246                },
247                _ => {},
248            },
249            Some(ToolKind::Hammer) => match ability_id {
250                Some("common.abilities.custom.cyclops.dash") => {
251                    next.control_l.position = Vec3::new(-1.0, 2.0, 12.0 + move3 * 3.0);
252                    next.control_r.position = Vec3::new(1.0, 2.0, -2.0);
253
254                    next.control.position = Vec3::new(
255                        4.0 + move1 * -3.0 + move3 * -5.0,
256                        (s_a.grip.0 / 1.0) + move1 * -1.0 + move3 * 1.0 + footrotl * 2.0,
257                        (-s_a.grip.0 / 0.8) + move1 * 2.0 + move3 * -3.0,
258                    );
259                    next.head.orientation = Quaternion::rotation_x(move1 * -0.5 + move3 * 0.5)
260                        * Quaternion::rotation_z(move1 * 0.3 + move3 * 0.3);
261                    next.upper_torso.orientation =
262                        Quaternion::rotation_x(move1 * -0.4 + move3 * 0.9)
263                            * Quaternion::rotation_z(move1 * 0.6 + move3 * -1.5);
264                    next.lower_torso.orientation =
265                        Quaternion::rotation_y(move1 * -0.2 + move3 * -0.1)
266                            * Quaternion::rotation_x(move1 * 0.4 + move3 * -0.7 + footrotr * 0.1)
267                            * Quaternion::rotation_z(move1 * -0.6 + move3 * 1.6);
268
269                    next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + move3 * 0.3)
270                        * Quaternion::rotation_y(move1 * 0.7);
271                    next.control_r.orientation =
272                        Quaternion::rotation_x(PI / 2.0 + 0.2 + move3 * -0.2)
273                            * Quaternion::rotation_y(0.0)
274                            * Quaternion::rotation_z(0.0);
275
276                    next.control.orientation =
277                        Quaternion::rotation_x(-1.0 + move1 * -0.2 + move3 * -0.2)
278                            * Quaternion::rotation_y(-1.8 + move1 * -0.2 + move3 * -0.2)
279                            * Quaternion::rotation_z(move1 * -0.8 + move3 * -0.1);
280                },
281                _ => {},
282            },
283            _ => {},
284        }
285
286        next
287    }
288}