Skip to main content

veloren_voxygen_anim/character/
swimwield.rs

1use super::{
2    super::{Animation, vek::*},
3    CharacterSkeleton, SkeletonAttr,
4};
5use common::comp::item::{Hands, ToolKind};
6use core::{f32::consts::PI, ops::Mul};
7
8pub struct SwimWieldAnimation;
9
10impl Animation for SwimWieldAnimation {
11    type Dependency<'a> = (
12        Option<ToolKind>,
13        Option<ToolKind>,
14        (Option<Hands>, Option<Hands>),
15        f32,
16        f32,
17    );
18    type Skeleton = CharacterSkeleton;
19
20    #[cfg(feature = "use-dyn-lib")]
21    const UPDATE_FN: &'static [u8] = b"character_swimwield\0";
22
23    #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "character_swimwield"))]
24    fn update_skeleton_inner(
25        skeleton: &Self::Skeleton,
26        (active_tool_kind, second_tool_kind, hands, velocity, global_time): Self::Dependency<'_>,
27        anim_time: f32,
28        rate: &mut f32,
29        s_a: &SkeletonAttr,
30    ) -> Self::Skeleton {
31        let mut next = (*skeleton).clone();
32        *rate = 1.0;
33        let lab: f32 = 1.0;
34        let speed = Vec3::<f32>::from(velocity).magnitude();
35        *rate = 1.0;
36        let intensity = if speed > 0.5 { 1.0 } else { 0.3 };
37        let footrotl = ((1.0 / (0.2 + (0.8) * ((anim_time * 6.0 * lab + PI * 1.4).sin()).powi(2)))
38            .sqrt())
39            * ((anim_time * 6.0 * lab + PI * 1.4).sin());
40
41        let footrotr = ((1.0 / (0.2 + (0.8) * ((anim_time * 6.0 * lab + PI * 0.4).sin()).powi(2)))
42            .sqrt())
43            * ((anim_time * 6.0 * lab + PI * 0.4).sin());
44
45        let head_look = Vec2::new(
46            (global_time + anim_time / 3.0).floor().mul(7331.0).sin() * 0.2,
47            (global_time + anim_time / 3.0).floor().mul(1337.0).sin() * 0.1,
48        );
49
50        let slowalt = (anim_time * 6.0 + PI).cos();
51        let u_slow = (anim_time * 1.0 + PI).sin();
52        let foothoril = (anim_time * 6.0 * lab + PI * 1.45).sin();
53        let foothorir = (anim_time * 6.0 * lab + PI * (0.45)).sin();
54        let u_slowalt = (anim_time * 3.0 + PI).cos();
55
56        next.foot_l.position = Vec3::new(
57            -s_a.foot.0,
58            s_a.foot.1 + foothoril * 1.5 * intensity,
59            -10.0 + s_a.foot.2 + footrotl * 3.0 * intensity,
60        );
61        next.foot_l.orientation = Quaternion::rotation_x(-0.8 + footrotl * 0.4 * intensity);
62
63        next.foot_r.position = Vec3::new(
64            s_a.foot.0,
65            s_a.foot.1 + foothorir * 1.5 * intensity,
66            -10.0 + s_a.foot.2 + footrotr * 3.0 * intensity,
67        );
68        next.foot_r.orientation = Quaternion::rotation_x(-0.8 + footrotr * 0.4 * intensity);
69
70        next.hold.scale = Vec3::one() * 0.0;
71
72        if velocity > 0.01 {
73            next.torso.position = Vec3::new(0.0, 0.0, 11.0);
74            next.torso.orientation = Quaternion::rotation_x(velocity * -0.05);
75
76            next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
77            next.back.scale = Vec3::one() * 1.02;
78        } else {
79            next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + u_slow * 0.1);
80            next.head.orientation =
81                Quaternion::rotation_z(head_look.x) * Quaternion::rotation_x(head_look.y.abs());
82            next.head.scale = Vec3::one() * s_a.head_scale;
83
84            next.chest.position =
85                Vec3::new(0.0 + slowalt * 0.5, s_a.chest.0, s_a.chest.1 + u_slow * 0.5);
86            next.torso.position = Vec3::new(0.0, 0.0, 0.0);
87
88            next.foot_l.position = Vec3::new(-s_a.foot.0, -2.0 + s_a.foot.1, s_a.foot.2);
89
90            next.foot_r.position = Vec3::new(s_a.foot.0, 2.0 + s_a.foot.1, s_a.foot.2);
91
92            next.chest.orientation =
93                Quaternion::rotation_y(u_slowalt * 0.04) * Quaternion::rotation_z(0.25);
94
95            next.belt.position = Vec3::new(0.0, s_a.belt.0, s_a.belt.1);
96            next.belt.orientation =
97                Quaternion::rotation_y(u_slowalt * 0.03) * Quaternion::rotation_z(0.22);
98            next.belt.scale = Vec3::one() * 1.02;
99
100            next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
101            next.back.orientation = Quaternion::rotation_x(-0.2);
102            next.back.scale = Vec3::one() * 1.02;
103            next.shorts.position = Vec3::new(0.0, s_a.shorts.0, s_a.shorts.1);
104            next.shorts.orientation = Quaternion::rotation_z(0.3);
105        }
106
107        let main_tool = if let (None, Some(Hands::Two)) = hands {
108            second_tool_kind
109        } else {
110            active_tool_kind
111        };
112
113        match main_tool {
114            Some(ToolKind::Sword) => {
115                next.hand_l.position = Vec3::new(-0.75, -1.0, -2.5);
116                next.hand_l.orientation =
117                    Quaternion::rotation_x(1.47) * Quaternion::rotation_y(-0.2);
118                next.hand_l.scale = Vec3::one() * 1.04;
119                next.hand_r.position = Vec3::new(0.75, -1.5, -5.5);
120                next.hand_r.orientation =
121                    Quaternion::rotation_x(1.47) * Quaternion::rotation_y(0.3);
122                next.hand_r.scale = Vec3::one() * 1.04;
123                next.main.position = Vec3::new(0.0, 0.0, -3.0);
124                next.main.orientation = Quaternion::rotation_x(-0.1)
125                    * Quaternion::rotation_y(0.0)
126                    * Quaternion::rotation_z(0.0);
127
128                next.control.position = Vec3::new(-7.0, 6.0, 6.0);
129                next.control.orientation = Quaternion::rotation_x(u_slow * 0.15)
130                    * Quaternion::rotation_y(0.0)
131                    * Quaternion::rotation_z(u_slowalt * 0.08);
132            },
133            Some(ToolKind::Dagger) => {
134                let hand_scale = 1.12;
135
136                next.control.position = Vec3::new(0.0, 0.0, 0.0);
137
138                next.hand_l.position = Vec3::new(0.0, 0.0, 0.0);
139                next.hand_l.orientation = Quaternion::rotation_x(0.0 * PI)
140                    * Quaternion::rotation_y(0.0 * PI)
141                    * Quaternion::rotation_z(0.0 * PI);
142                next.hand_l.scale = Vec3::one() * hand_scale;
143
144                next.main.position = Vec3::new(0.0, 0.0, 0.0);
145                next.main.orientation = Quaternion::rotation_x(0.0 * PI)
146                    * Quaternion::rotation_y(0.0 * PI)
147                    * Quaternion::rotation_z(0.0 * PI);
148
149                next.control_l.position = Vec3::new(-7.0, 0.0, 0.0);
150
151                next.hand_r.position = Vec3::new(0.0, 0.0, 0.0);
152                next.hand_r.orientation = Quaternion::rotation_x(0.0 * PI)
153                    * Quaternion::rotation_y(0.0 * PI)
154                    * Quaternion::rotation_z(0.0 * PI);
155                next.hand_r.scale = Vec3::one() * hand_scale;
156
157                next.second.position = Vec3::new(0.0, 0.0, 0.0);
158                next.second.orientation = Quaternion::rotation_x(0.0 * PI)
159                    * Quaternion::rotation_y(0.0 * PI)
160                    * Quaternion::rotation_z(0.0 * PI);
161
162                next.control_r.position = Vec3::new(7.0, 0.0, 0.0);
163            },
164            Some(ToolKind::Axe) => {
165                if velocity < 0.5 {
166                    next.head.position =
167                        Vec3::new(0.0, -3.5 + s_a.head.0, s_a.head.1 + u_slow * 0.1);
168                    next.head.orientation = Quaternion::rotation_z(head_look.x)
169                        * Quaternion::rotation_x(0.35 + head_look.y.abs());
170                    next.head.scale = Vec3::one() * s_a.head_scale;
171                    next.chest.orientation = Quaternion::rotation_x(-0.35)
172                        * Quaternion::rotation_y(u_slowalt * 0.04)
173                        * Quaternion::rotation_z(0.15);
174                    next.belt.position = Vec3::new(0.0, 1.0 + s_a.belt.0, s_a.belt.1);
175                    next.belt.orientation = Quaternion::rotation_x(0.15)
176                        * Quaternion::rotation_y(u_slowalt * 0.03)
177                        * Quaternion::rotation_z(0.15);
178                    next.shorts.position = Vec3::new(0.0, 1.0 + s_a.shorts.0, s_a.shorts.1);
179                    next.shorts.orientation =
180                        Quaternion::rotation_x(0.15) * Quaternion::rotation_z(0.25);
181                    next.control.orientation = Quaternion::rotation_x(1.8)
182                        * Quaternion::rotation_y(-0.5)
183                        * Quaternion::rotation_z(PI - 0.2);
184                } else {
185                    next.control.orientation = Quaternion::rotation_x(2.1)
186                        * Quaternion::rotation_y(-0.4)
187                        * Quaternion::rotation_z(PI - 0.2);
188                }
189                next.hand_l.position = Vec3::new(-0.5, 0.0, 4.0);
190                next.hand_l.orientation = Quaternion::rotation_x(PI / 2.0)
191                    * Quaternion::rotation_z(0.0)
192                    * Quaternion::rotation_y(0.0);
193                next.hand_l.scale = Vec3::one() * 1.04;
194                next.hand_r.position = Vec3::new(0.5, 0.0, -2.5);
195                next.hand_r.orientation = Quaternion::rotation_x(PI / 2.0)
196                    * Quaternion::rotation_z(0.0)
197                    * Quaternion::rotation_y(0.0);
198                next.hand_r.scale = Vec3::one() * 1.04;
199                next.main.position = Vec3::new(-0.0, -2.0, -1.0);
200                next.main.orientation = Quaternion::rotation_x(0.0)
201                    * Quaternion::rotation_y(0.0)
202                    * Quaternion::rotation_z(0.0);
203
204                next.control.position = Vec3::new(-3.0, 11.0, 3.0);
205            },
206            Some(ToolKind::Staff) | Some(ToolKind::Sceptre) => {
207                next.hand_l.position = Vec3::new(1.5, 0.5, -4.0);
208                next.hand_l.orientation =
209                    Quaternion::rotation_x(1.47) * Quaternion::rotation_y(-0.3);
210                next.hand_l.scale = Vec3::one() * 1.04;
211                next.hand_r.position = Vec3::new(8.0, 4.0, 2.0);
212                next.hand_r.orientation = Quaternion::rotation_x(1.8)
213                    * Quaternion::rotation_y(0.5)
214                    * Quaternion::rotation_z(-0.27);
215                next.hand_r.scale = Vec3::one() * 1.04;
216                next.main.position = Vec3::new(12.0, 8.4, 13.2);
217                next.main.orientation = Quaternion::rotation_x(-0.3)
218                    * Quaternion::rotation_y(PI + 0.3)
219                    * Quaternion::rotation_z(0.9);
220
221                next.control.position = Vec3::new(-14.0, 1.8, 3.0);
222                next.control.orientation = Quaternion::rotation_x(u_slow * 0.2)
223                    * Quaternion::rotation_y(-0.2)
224                    * Quaternion::rotation_z(u_slowalt * 0.1);
225            },
226            Some(ToolKind::Shield) => {
227                let hand_scale = 1.12;
228
229                next.control.position = Vec3::new(0.0, 0.0, 0.0);
230
231                next.hand_l.position = Vec3::new(0.0, 0.0, 0.0);
232                next.hand_l.orientation = Quaternion::rotation_x(0.0 * PI)
233                    * Quaternion::rotation_y(0.0 * PI)
234                    * Quaternion::rotation_z(0.0 * PI);
235                next.hand_l.scale = Vec3::one() * hand_scale;
236
237                next.main.position = Vec3::new(0.0, 0.0, 0.0);
238                next.main.orientation = Quaternion::rotation_x(0.0 * PI)
239                    * Quaternion::rotation_y(0.0 * PI)
240                    * Quaternion::rotation_z(0.0 * PI);
241
242                next.control_l.position = Vec3::new(-7.0, 0.0, 0.0);
243
244                next.hand_r.position = Vec3::new(0.0, 0.0, 0.0);
245                next.hand_r.orientation = Quaternion::rotation_x(0.0 * PI)
246                    * Quaternion::rotation_y(0.0 * PI)
247                    * Quaternion::rotation_z(0.0 * PI);
248                next.hand_r.scale = Vec3::one() * hand_scale;
249
250                next.second.position = Vec3::new(0.0, 0.0, 0.0);
251                next.second.orientation = Quaternion::rotation_x(0.0 * PI)
252                    * Quaternion::rotation_y(0.0 * PI)
253                    * Quaternion::rotation_z(0.0 * PI);
254
255                next.control_r.position = Vec3::new(7.0, 0.0, 0.0);
256            },
257            Some(ToolKind::Bow) => {
258                next.hand_l.position = Vec3::new(2.0, 1.5, 0.0);
259                next.hand_l.orientation = Quaternion::rotation_x(1.20)
260                    * Quaternion::rotation_y(-0.6)
261                    * Quaternion::rotation_z(-0.3);
262                next.hand_l.scale = Vec3::one() * 1.04;
263                next.hand_r.position = Vec3::new(5.9, 4.5, -5.0);
264                next.hand_r.orientation = Quaternion::rotation_x(1.20)
265                    * Quaternion::rotation_y(-0.6)
266                    * Quaternion::rotation_z(-0.3);
267                next.hand_r.scale = Vec3::one() * 1.04;
268                next.main.position = Vec3::new(3.0, 2.0, -3.0);
269                next.main.orientation = Quaternion::rotation_x(-0.3)
270                    * Quaternion::rotation_y(0.3)
271                    * Quaternion::rotation_z(-0.6);
272
273                next.hold.position = Vec3::new(1.2, -1.0, -5.2);
274                next.hold.orientation = Quaternion::rotation_x(-1.7)
275                    * Quaternion::rotation_y(0.0)
276                    * Quaternion::rotation_z(-0.1);
277                next.hold.scale = Vec3::one() * 1.0;
278
279                next.control.position = Vec3::new(-7.0, 6.0, 6.0);
280                next.control.orientation =
281                    Quaternion::rotation_x(u_slow * 0.2) * Quaternion::rotation_z(u_slowalt * 0.1);
282            },
283            Some(ToolKind::Debug) => {
284                next.hand_l.position = Vec3::new(-7.0, 4.0, 3.0);
285                next.hand_l.orientation = Quaternion::rotation_x(1.27)
286                    * Quaternion::rotation_y(0.0)
287                    * Quaternion::rotation_z(0.0);
288                next.hand_l.scale = Vec3::one() * 1.04;
289                next.hand_r.position = Vec3::new(7.0, 2.5, -1.25);
290                next.hand_r.orientation = Quaternion::rotation_x(1.27)
291                    * Quaternion::rotation_y(0.0)
292                    * Quaternion::rotation_z(-0.3);
293                next.hand_r.scale = Vec3::one() * 1.04;
294                next.main.position = Vec3::new(5.0, 8.75, -2.0);
295                next.main.orientation = Quaternion::rotation_x(-0.3)
296                    * Quaternion::rotation_y(-1.27)
297                    * Quaternion::rotation_z(0.0);
298                next.control.position = Vec3::new(0.0, 6.0, 6.0);
299                next.control.orientation =
300                    Quaternion::rotation_x(u_slow * 0.2) * Quaternion::rotation_z(u_slowalt * 0.1);
301            },
302            Some(_) => {
303                next.hand_l.position = Vec3::new(-12.0, 0.0, 0.0);
304                next.hand_l.orientation =
305                    Quaternion::rotation_x(-0.0) * Quaternion::rotation_y(0.0);
306                next.hand_l.scale = Vec3::one() * 1.04;
307                next.hand_r.position = Vec3::new(2.0, 0.0, 0.0);
308                next.hand_r.orientation = Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0);
309                next.hand_r.scale = Vec3::one() * 1.04;
310                next.main.position = Vec3::new(0.0, 0.0, 0.0);
311                next.main.orientation = Quaternion::rotation_x(0.0)
312                    * Quaternion::rotation_y(-PI / 2.0)
313                    * Quaternion::rotation_z(PI / 2.0);
314
315                next.control.position = Vec3::new(6.0, 7.0, 1.0);
316                next.control.orientation = Quaternion::rotation_x(0.3 + u_slow * 0.15)
317                    * Quaternion::rotation_y(0.0)
318                    * Quaternion::rotation_z(u_slowalt * 0.08);
319            },
320            _ => {},
321        }
322
323        if let (None, Some(Hands::Two)) = hands {
324            next.second = next.main;
325        }
326
327        next
328    }
329}