veloren_voxygen_anim/character/
swimwield.rs1use 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", 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 let short = ((5.0 / (1.5 + 3.5 * ((anim_time * lab * 16.0).sin()).powi(2))).sqrt())
56 * ((anim_time * lab * 16.0).sin());
57 let noisea = (anim_time * 11.0 + PI / 6.0).sin();
58 let noiseb = (anim_time * 19.0 + PI / 4.0).sin();
59
60 next.foot_l.position = Vec3::new(
61 -s_a.foot.0,
62 s_a.foot.1 + foothoril * 1.5 * intensity,
63 -10.0 + s_a.foot.2 + footrotl * 3.0 * intensity,
64 );
65 next.foot_l.orientation = Quaternion::rotation_x(-0.8 + footrotl * 0.4 * intensity);
66
67 next.foot_r.position = Vec3::new(
68 s_a.foot.0,
69 s_a.foot.1 + foothorir * 1.5 * intensity,
70 -10.0 + s_a.foot.2 + footrotr * 3.0 * intensity,
71 );
72 next.foot_r.orientation = Quaternion::rotation_x(-0.8 + footrotr * 0.4 * intensity);
73
74 next.hold.scale = Vec3::one() * 0.0;
75
76 if velocity > 0.01 {
77 next.torso.position = Vec3::new(0.0, 0.0, 11.0);
78 next.torso.orientation = Quaternion::rotation_x(velocity * -0.05);
79
80 next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
81 next.back.orientation = Quaternion::rotation_x(
82 (-0.5 + short * 0.3 + noisea * 0.3 + noiseb * 0.3).min(-0.1),
83 );
84 next.back.scale = Vec3::one() * 1.02;
85 } else {
86 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + u_slow * 0.1);
87 next.head.orientation =
88 Quaternion::rotation_z(head_look.x) * Quaternion::rotation_x(head_look.y.abs());
89 next.head.scale = Vec3::one() * s_a.head_scale;
90
91 next.chest.position =
92 Vec3::new(0.0 + slowalt * 0.5, s_a.chest.0, s_a.chest.1 + u_slow * 0.5);
93 next.torso.position = Vec3::new(0.0, 0.0, 0.0);
94
95 next.foot_l.position = Vec3::new(-s_a.foot.0, -2.0 + s_a.foot.1, s_a.foot.2);
96
97 next.foot_r.position = Vec3::new(s_a.foot.0, 2.0 + s_a.foot.1, s_a.foot.2);
98
99 next.chest.orientation =
100 Quaternion::rotation_y(u_slowalt * 0.04) * Quaternion::rotation_z(0.25);
101
102 next.belt.position = Vec3::new(0.0, s_a.belt.0, s_a.belt.1);
103 next.belt.orientation =
104 Quaternion::rotation_y(u_slowalt * 0.03) * Quaternion::rotation_z(0.22);
105 next.belt.scale = Vec3::one() * 1.02;
106
107 next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
108 next.back.orientation = Quaternion::rotation_x(-0.2);
109 next.back.scale = Vec3::one() * 1.02;
110 next.shorts.position = Vec3::new(0.0, s_a.shorts.0, s_a.shorts.1);
111 next.shorts.orientation = Quaternion::rotation_z(0.3);
112 }
113
114 let main_tool = if let (None, Some(Hands::Two)) = hands {
115 second_tool_kind
116 } else {
117 active_tool_kind
118 };
119
120 match main_tool {
121 Some(ToolKind::Sword) => {
122 next.hand_l.position = Vec3::new(-0.75, -1.0, -2.5);
123 next.hand_l.orientation =
124 Quaternion::rotation_x(1.47) * Quaternion::rotation_y(-0.2);
125 next.hand_l.scale = Vec3::one() * 1.04;
126 next.hand_r.position = Vec3::new(0.75, -1.5, -5.5);
127 next.hand_r.orientation =
128 Quaternion::rotation_x(1.47) * Quaternion::rotation_y(0.3);
129 next.hand_r.scale = Vec3::one() * 1.04;
130 next.main.position = Vec3::new(0.0, 0.0, -3.0);
131 next.main.orientation = Quaternion::rotation_x(-0.1)
132 * Quaternion::rotation_y(0.0)
133 * Quaternion::rotation_z(0.0);
134
135 next.control.position = Vec3::new(-7.0, 6.0, 6.0);
136 next.control.orientation = Quaternion::rotation_x(u_slow * 0.15)
137 * Quaternion::rotation_y(0.0)
138 * Quaternion::rotation_z(u_slowalt * 0.08);
139 },
140 Some(ToolKind::Dagger) => {
141 let hand_scale = 1.12;
142
143 next.control.position = Vec3::new(0.0, 0.0, 0.0);
144
145 next.hand_l.position = Vec3::new(0.0, 0.0, 0.0);
146 next.hand_l.orientation = Quaternion::rotation_x(0.0 * PI)
147 * Quaternion::rotation_y(0.0 * PI)
148 * Quaternion::rotation_z(0.0 * PI);
149 next.hand_l.scale = Vec3::one() * hand_scale;
150
151 next.main.position = Vec3::new(0.0, 0.0, 0.0);
152 next.main.orientation = Quaternion::rotation_x(0.0 * PI)
153 * Quaternion::rotation_y(0.0 * PI)
154 * Quaternion::rotation_z(0.0 * PI);
155
156 next.control_l.position = Vec3::new(-7.0, 0.0, 0.0);
157
158 next.hand_r.position = Vec3::new(0.0, 0.0, 0.0);
159 next.hand_r.orientation = Quaternion::rotation_x(0.0 * PI)
160 * Quaternion::rotation_y(0.0 * PI)
161 * Quaternion::rotation_z(0.0 * PI);
162 next.hand_r.scale = Vec3::one() * hand_scale;
163
164 next.second.position = Vec3::new(0.0, 0.0, 0.0);
165 next.second.orientation = Quaternion::rotation_x(0.0 * PI)
166 * Quaternion::rotation_y(0.0 * PI)
167 * Quaternion::rotation_z(0.0 * PI);
168
169 next.control_r.position = Vec3::new(7.0, 0.0, 0.0);
170 },
171 Some(ToolKind::Axe) => {
172 if velocity < 0.5 {
173 next.head.position =
174 Vec3::new(0.0, -3.5 + s_a.head.0, s_a.head.1 + u_slow * 0.1);
175 next.head.orientation = Quaternion::rotation_z(head_look.x)
176 * Quaternion::rotation_x(0.35 + head_look.y.abs());
177 next.head.scale = Vec3::one() * s_a.head_scale;
178 next.chest.orientation = Quaternion::rotation_x(-0.35)
179 * Quaternion::rotation_y(u_slowalt * 0.04)
180 * Quaternion::rotation_z(0.15);
181 next.belt.position = Vec3::new(0.0, 1.0 + s_a.belt.0, s_a.belt.1);
182 next.belt.orientation = Quaternion::rotation_x(0.15)
183 * Quaternion::rotation_y(u_slowalt * 0.03)
184 * Quaternion::rotation_z(0.15);
185 next.shorts.position = Vec3::new(0.0, 1.0 + s_a.shorts.0, s_a.shorts.1);
186 next.shorts.orientation =
187 Quaternion::rotation_x(0.15) * Quaternion::rotation_z(0.25);
188 next.control.orientation = Quaternion::rotation_x(1.8)
189 * Quaternion::rotation_y(-0.5)
190 * Quaternion::rotation_z(PI - 0.2);
191 } else {
192 next.control.orientation = Quaternion::rotation_x(2.1)
193 * Quaternion::rotation_y(-0.4)
194 * Quaternion::rotation_z(PI - 0.2);
195 }
196 next.hand_l.position = Vec3::new(-0.5, 0.0, 4.0);
197 next.hand_l.orientation = Quaternion::rotation_x(PI / 2.0)
198 * Quaternion::rotation_z(0.0)
199 * Quaternion::rotation_y(0.0);
200 next.hand_l.scale = Vec3::one() * 1.04;
201 next.hand_r.position = Vec3::new(0.5, 0.0, -2.5);
202 next.hand_r.orientation = Quaternion::rotation_x(PI / 2.0)
203 * Quaternion::rotation_z(0.0)
204 * Quaternion::rotation_y(0.0);
205 next.hand_r.scale = Vec3::one() * 1.04;
206 next.main.position = Vec3::new(-0.0, -2.0, -1.0);
207 next.main.orientation = Quaternion::rotation_x(0.0)
208 * Quaternion::rotation_y(0.0)
209 * Quaternion::rotation_z(0.0);
210
211 next.control.position = Vec3::new(-3.0, 11.0, 3.0);
212 },
213 Some(ToolKind::Hammer) => {
214 next.hand_l.position = Vec3::new(-12.0, 0.0, 0.0);
215 next.hand_l.orientation =
216 Quaternion::rotation_x(-0.0) * Quaternion::rotation_y(0.0);
217 next.hand_l.scale = Vec3::one() * 1.04;
218 next.hand_r.position = Vec3::new(2.0, 0.0, 0.0);
219 next.hand_r.orientation = Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0);
220 next.hand_r.scale = Vec3::one() * 1.04;
221 next.main.position = Vec3::new(0.0, 0.0, 0.0);
222 next.main.orientation = Quaternion::rotation_x(0.0)
223 * Quaternion::rotation_y(-PI / 2.0)
224 * Quaternion::rotation_z(PI / 2.0);
225
226 next.control.position = Vec3::new(6.0, 7.0, 1.0);
227 next.control.orientation = Quaternion::rotation_x(0.3 + u_slow * 0.15)
228 * Quaternion::rotation_y(0.0)
229 * Quaternion::rotation_z(u_slowalt * 0.08);
230 },
231 Some(ToolKind::Staff) | Some(ToolKind::Sceptre) => {
232 next.hand_l.position = Vec3::new(1.5, 0.5, -4.0);
233 next.hand_l.orientation =
234 Quaternion::rotation_x(1.47) * Quaternion::rotation_y(-0.3);
235 next.hand_l.scale = Vec3::one() * 1.04;
236 next.hand_r.position = Vec3::new(8.0, 4.0, 2.0);
237 next.hand_r.orientation = Quaternion::rotation_x(1.8)
238 * Quaternion::rotation_y(0.5)
239 * Quaternion::rotation_z(-0.27);
240 next.hand_r.scale = Vec3::one() * 1.04;
241 next.main.position = Vec3::new(12.0, 8.4, 13.2);
242 next.main.orientation = Quaternion::rotation_x(-0.3)
243 * Quaternion::rotation_y(PI + 0.3)
244 * Quaternion::rotation_z(0.9);
245
246 next.control.position = Vec3::new(-14.0, 1.8, 3.0);
247 next.control.orientation = Quaternion::rotation_x(u_slow * 0.2)
248 * Quaternion::rotation_y(-0.2)
249 * Quaternion::rotation_z(u_slowalt * 0.1);
250 },
251 Some(ToolKind::Shield) => {
252 let hand_scale = 1.12;
253
254 next.control.position = Vec3::new(0.0, 0.0, 0.0);
255
256 next.hand_l.position = Vec3::new(0.0, 0.0, 0.0);
257 next.hand_l.orientation = Quaternion::rotation_x(0.0 * PI)
258 * Quaternion::rotation_y(0.0 * PI)
259 * Quaternion::rotation_z(0.0 * PI);
260 next.hand_l.scale = Vec3::one() * hand_scale;
261
262 next.main.position = Vec3::new(0.0, 0.0, 0.0);
263 next.main.orientation = Quaternion::rotation_x(0.0 * PI)
264 * Quaternion::rotation_y(0.0 * PI)
265 * Quaternion::rotation_z(0.0 * PI);
266
267 next.control_l.position = Vec3::new(-7.0, 0.0, 0.0);
268
269 next.hand_r.position = Vec3::new(0.0, 0.0, 0.0);
270 next.hand_r.orientation = Quaternion::rotation_x(0.0 * PI)
271 * Quaternion::rotation_y(0.0 * PI)
272 * Quaternion::rotation_z(0.0 * PI);
273 next.hand_r.scale = Vec3::one() * hand_scale;
274
275 next.second.position = Vec3::new(0.0, 0.0, 0.0);
276 next.second.orientation = Quaternion::rotation_x(0.0 * PI)
277 * Quaternion::rotation_y(0.0 * PI)
278 * Quaternion::rotation_z(0.0 * PI);
279
280 next.control_r.position = Vec3::new(7.0, 0.0, 0.0);
281 },
282 Some(ToolKind::Bow) => {
283 next.hand_l.position = Vec3::new(2.0, 1.5, 0.0);
284 next.hand_l.orientation = Quaternion::rotation_x(1.20)
285 * Quaternion::rotation_y(-0.6)
286 * Quaternion::rotation_z(-0.3);
287 next.hand_l.scale = Vec3::one() * 1.04;
288 next.hand_r.position = Vec3::new(5.9, 4.5, -5.0);
289 next.hand_r.orientation = Quaternion::rotation_x(1.20)
290 * Quaternion::rotation_y(-0.6)
291 * Quaternion::rotation_z(-0.3);
292 next.hand_r.scale = Vec3::one() * 1.04;
293 next.main.position = Vec3::new(3.0, 2.0, -13.0);
294 next.main.orientation = Quaternion::rotation_x(-0.3)
295 * Quaternion::rotation_y(0.3)
296 * Quaternion::rotation_z(-0.6);
297
298 next.hold.position = Vec3::new(1.2, -1.0, -5.2);
299 next.hold.orientation = Quaternion::rotation_x(-1.7)
300 * Quaternion::rotation_y(0.0)
301 * Quaternion::rotation_z(-0.1);
302 next.hold.scale = Vec3::one() * 1.0;
303
304 next.control.position = Vec3::new(-7.0, 6.0, 6.0);
305 next.control.orientation =
306 Quaternion::rotation_x(u_slow * 0.2) * Quaternion::rotation_z(u_slowalt * 0.1);
307 },
308 Some(ToolKind::Debug) => {
309 next.hand_l.position = Vec3::new(-7.0, 4.0, 3.0);
310 next.hand_l.orientation = Quaternion::rotation_x(1.27)
311 * Quaternion::rotation_y(0.0)
312 * Quaternion::rotation_z(0.0);
313 next.hand_l.scale = Vec3::one() * 1.04;
314 next.hand_r.position = Vec3::new(7.0, 2.5, -1.25);
315 next.hand_r.orientation = Quaternion::rotation_x(1.27)
316 * Quaternion::rotation_y(0.0)
317 * Quaternion::rotation_z(-0.3);
318 next.hand_r.scale = Vec3::one() * 1.04;
319 next.main.position = Vec3::new(5.0, 8.75, -2.0);
320 next.main.orientation = Quaternion::rotation_x(-0.3)
321 * Quaternion::rotation_y(-1.27)
322 * Quaternion::rotation_z(0.0);
323 next.control.position = Vec3::new(0.0, 6.0, 6.0);
324 next.control.orientation =
325 Quaternion::rotation_x(u_slow * 0.2) * Quaternion::rotation_z(u_slowalt * 0.1);
326 },
327 _ => {},
328 }
329
330 if let (None, Some(Hands::Two)) = hands {
331 next.second = next.main;
332 }
333
334 next
335 }
336}