veloren_voxygen_anim/biped_large/
chargemelee.rs1use 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 ChargeMeleeAnimation;
12
13impl Animation for ChargeMeleeAnimation {
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_chargemelee\0";
27
28 #[cfg_attr(
29 feature = "be-dyn-lib",
30 unsafe(export_name = "biped_large_chargemelee")
31 )]
32 fn update_skeleton_inner(
33 skeleton: &Self::Skeleton,
34 (
35 active_tool_kind,
36 _second_tool,
37 velocity,
38 _global_time,
39 stage_section,
40 acc_vel,
41 ability_id,
42 ): Self::Dependency<'_>,
43 anim_time: f32,
44 rate: &mut f32,
45 s_a: &SkeletonAttr,
46 ) -> Self::Skeleton {
47 *rate = 1.0;
48 let mut next = (*skeleton).clone();
49 let speed = Vec2::<f32>::from(velocity).magnitude();
50
51 let lab: f32 = 0.65 * s_a.tempo;
52 let speednorm = (speed / 12.0).powf(0.4);
53 let foothoril = (acc_vel * lab + PI * 1.45).sin() * speednorm;
54 let foothorir = (acc_vel * lab + PI * (0.45)).sin() * speednorm;
55 let footrotl = ((1.0 / (0.5 + (0.5) * ((acc_vel * lab + PI * 1.4).sin()).powi(2))).sqrt())
56 * ((acc_vel * lab + PI * 1.4).sin());
57
58 let footrotr = ((1.0 / (0.5 + (0.5) * ((acc_vel * lab + PI * 0.4).sin()).powi(2))).sqrt())
59 * ((acc_vel * lab + PI * 0.4).sin());
60 let (move1base, move2base, movement3, tension) = match stage_section {
61 Some(StageSection::Charge) => (
62 (anim_time.powf(0.25)).min(1.0),
63 0.0,
64 0.0,
65 (anim_time * 100.0).sin(),
66 ),
67 Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0, 0.0),
68 Some(StageSection::Recover) => (1.0, 1.0, anim_time.powi(4), 0.0),
69 _ => (0.0, 0.0, 0.0, 0.0),
70 };
71
72 let pullback = 1.0 - movement3;
73 let move1 = move1base * pullback;
74 let move2 = move2base * pullback;
75 next.second.position = Vec3::new(0.0, 0.0, 0.0);
76 next.second.orientation = Quaternion::rotation_x(0.0);
77 next.shoulder_l.position = Vec3::new(
78 -s_a.shoulder.0,
79 s_a.shoulder.1,
80 s_a.shoulder.2 - foothorir * 1.0,
81 );
82 next.shoulder_l.orientation =
83 Quaternion::rotation_x(move1 * 0.8 + 0.6 * speednorm + (footrotr * -0.2) * speednorm);
84
85 next.shoulder_r.position = Vec3::new(
86 s_a.shoulder.0,
87 s_a.shoulder.1,
88 s_a.shoulder.2 - foothoril * 1.0,
89 );
90 next.shoulder_r.orientation =
91 Quaternion::rotation_x(move1 * 0.8 + 0.6 * speednorm + (footrotl * -0.2) * speednorm);
92 next.torso.orientation = Quaternion::rotation_z(0.0);
93
94 next.main.position = Vec3::new(0.0, 0.0, 0.0);
95 next.main.orientation = Quaternion::rotation_x(0.0);
96
97 next.hand_l.position = Vec3::new(0.0, 0.0, s_a.grip.0);
98 next.hand_r.position = Vec3::new(0.0, 0.0, s_a.grip.0);
99
100 next.hand_l.orientation = Quaternion::rotation_x(0.0);
101 next.hand_r.orientation = Quaternion::rotation_x(0.0);
102
103 #[expect(clippy::single_match)]
104 match active_tool_kind {
105 Some(ToolKind::Natural) => match ability_id {
106 Some("common.abilities.custom.minotaur.cleave") => {
107 next.upper_torso.orientation =
108 Quaternion::rotation_x(move1 * 0.3 + move2 * -0.9);
109 next.lower_torso.orientation =
110 Quaternion::rotation_x(move1 * -0.3 + move2 * 0.9);
111 next.head.orientation = Quaternion::rotation_x(move1 * -0.5 + move2 * 0.5);
112
113 next.control_l.position = Vec3::new(0.0, 4.0, 5.0);
114 next.control_r.position = Vec3::new(0.0, 4.0, 5.0);
115 next.weapon_l.position = Vec3::new(
116 -12.0 + move2 * 5.0,
117 -6.0 + move1 * 22.0 + move2 * 8.0,
118 -18.0 + move1 * 16.0 + move2 * -19.0,
119 );
120 next.weapon_r.position = Vec3::new(
121 12.0 + move2 * -5.0,
122 -6.0 + move1 * 22.0 + move2 * 8.0,
123 -18.0 + move1 * 14.0 + move2 * -19.0,
124 );
125 next.torso.position = Vec3::new(0.0, move2 * 7.06, 0.0);
126 next.second.scale = Vec3::one() * 1.0;
127
128 next.weapon_l.orientation =
129 Quaternion::rotation_x(-1.67 + move1 * 2.8 + tension * 0.03 + move2 * -2.3)
130 * Quaternion::rotation_y(move1 * 0.3 + move2 * 0.5);
131 next.weapon_r.orientation = Quaternion::rotation_x(
132 -1.67 + move1 * 1.6 + tension * -0.03 + move2 * -0.7,
133 ) * Quaternion::rotation_y(
134 move1 * -0.3 + move2 * -0.5,
135 ) * Quaternion::rotation_z(0.0);
136
137 next.control_l.orientation =
138 Quaternion::rotation_x(PI / 2.0 + move1 * 0.2 + move2 * 0.1);
139 next.control_r.orientation =
140 Quaternion::rotation_x(PI / 2.0 + move1 * 0.4 + move2 * -0.4);
141
142 next.control.orientation =
143 Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0);
144 next.shoulder_l.orientation = Quaternion::rotation_x(-0.3 + move1 * 1.0);
145
146 next.shoulder_r.orientation = Quaternion::rotation_x(-0.3 + move1 * 1.0);
147 },
148 Some("common.abilities.custom.husk_brute.chargedmelee") => {
149 next.second.scale = Vec3::one() * 0.0;
150
151 next.head.orientation = Quaternion::rotation_x(move1 * 0.3 + move2 * -0.6);
152 next.jaw.position = Vec3::new(0.0, s_a.jaw.0, s_a.jaw.1);
153 next.jaw.orientation = Quaternion::rotation_x(move2 * -0.3);
154 next.control_l.position = Vec3::new(-0.5, 4.0, 1.0);
155 next.control_r.position = Vec3::new(-0.5, 4.0, 1.0);
156 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0);
157 next.control_r.orientation = Quaternion::rotation_x(PI / 2.0);
158 next.weapon_l.position =
159 Vec3::new(-12.0 + (move1 * 10.0).min(6.0), -1.0, -15.0);
160 next.weapon_r.position =
161 Vec3::new(12.0 + (move1 * -10.0).max(-6.0), -1.0, -15.0);
162
163 next.weapon_l.orientation = Quaternion::rotation_x(-PI / 2.0 - 0.1)
164 * Quaternion::rotation_z(move1 * -0.8);
165 next.weapon_r.orientation = Quaternion::rotation_x(-PI / 2.0 - 0.1)
166 * Quaternion::rotation_z(move1 * 0.8);
167
168 next.shoulder_l.orientation =
169 Quaternion::rotation_x(-0.3 + move1 * 2.8 + move2 * -2.8);
170
171 next.shoulder_r.orientation =
172 Quaternion::rotation_x(-0.3 + move1 * 2.8 + move2 * -2.8);
173
174 next.control.orientation = Quaternion::rotation_x(move1 * 2.5 + move2 * -2.0);
175
176 next.upper_torso.position =
177 Vec3::new(0.0, s_a.upper_torso.0, s_a.upper_torso.1);
178 next.upper_torso.orientation =
179 Quaternion::rotation_x(move1 * 0.2 + move2 * -0.6);
180 next.lower_torso.orientation =
181 Quaternion::rotation_x(move1 * -0.2 + move2 * 0.6);
182
183 if speed < 0.1 {
184 next.foot_l.position = Vec3::new(
185 -s_a.foot.0,
186 s_a.foot.1 + move1 * -7.0 + move2 * 7.0,
187 s_a.foot.2,
188 );
189 next.foot_l.orientation =
190 Quaternion::rotation_x(move1 * -0.8 + move2 * 0.8)
191 * Quaternion::rotation_z(move1 * 0.3 + move2 * -0.3);
192
193 next.foot_r.position = Vec3::new(
194 s_a.foot.0,
195 s_a.foot.1 + move1 * 5.0 + move2 * -5.0,
196 s_a.foot.2,
197 );
198 next.foot_r.orientation =
199 Quaternion::rotation_y(move1 * -0.3 + move2 * 0.3)
200 * Quaternion::rotation_z(move1 * 0.4 + move2 * -0.4);
201 }
202 next.main.orientation = Quaternion::rotation_y(move1 * 0.4 + move2 * -0.6)
203 * Quaternion::rotation_x(move2 * -0.4);
204 },
205 Some("common.abilities.custom.tursus.tusk_stab") => {
206 next.second.scale = Vec3::one() * 0.0;
207 next.head.position = Vec3::new(
208 0.0,
209 s_a.head.0 + move1 * 15.0,
210 s_a.head.1 + move1 * 6.0 + move2 * -4.0,
211 );
212 next.head.orientation = Quaternion::rotation_x(move1 * 1.3 + move2 * -0.7);
213 next.jaw.position = Vec3::new(0.0, s_a.jaw.0, s_a.jaw.1);
214 next.jaw.orientation = Quaternion::rotation_x(move2 * -0.3);
215 next.control_l.position = Vec3::new(-0.5, 4.0, 1.0);
216 next.control_r.position = Vec3::new(-0.5, 4.0, 1.0);
217 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0);
218 next.control_r.orientation = Quaternion::rotation_x(PI / 2.0);
219 next.weapon_l.position =
220 Vec3::new(-16.0 + (move1 * 10.0).min(6.0), -1.0, -15.0);
221 next.weapon_r.position =
222 Vec3::new(16.0 + (move1 * -10.0).max(-6.0), -1.0, -15.0);
223
224 next.weapon_l.orientation = Quaternion::rotation_x(-PI / 2.0 - 0.1)
225 * Quaternion::rotation_z(move1 * -0.8);
226 next.weapon_r.orientation = Quaternion::rotation_x(-PI / 2.0 - 0.1)
227 * Quaternion::rotation_z(move1 * 0.8);
228
229 next.shoulder_l.orientation =
230 Quaternion::rotation_x(-0.3 + move1 * -0.4 + move2 * 0.4);
231
232 next.shoulder_r.orientation =
233 Quaternion::rotation_x(-0.3 + move1 * -0.4 + move2 * 0.4);
234
235 next.control.orientation = Quaternion::rotation_x(move1 * -0.7 + move2 * 0.7);
236
237 next.upper_torso.position =
238 Vec3::new(0.0, s_a.upper_torso.0, s_a.upper_torso.1);
239 next.upper_torso.orientation =
240 Quaternion::rotation_x(move1 * 0.6 + move2 * -1.1);
241 next.lower_torso.orientation =
242 Quaternion::rotation_x(move1 * -0.2 + move2 * 0.6);
243
244 if speed < 0.1 {
245 next.foot_l.position = Vec3::new(
246 -s_a.foot.0,
247 s_a.foot.1 + move1 * -7.0 + move2 * 7.0,
248 s_a.foot.2,
249 );
250 next.foot_l.orientation =
251 Quaternion::rotation_x(move1 * -0.8 + move2 * 0.8)
252 * Quaternion::rotation_z(move1 * 0.3 + move2 * -0.3);
253
254 next.foot_r.position = Vec3::new(
255 s_a.foot.0,
256 s_a.foot.1 + move1 * 5.0 + move2 * -5.0,
257 s_a.foot.2,
258 );
259 next.foot_r.orientation =
260 Quaternion::rotation_y(move1 * -0.3 + move2 * 0.3)
261 * Quaternion::rotation_z(move1 * 0.4 + move2 * -0.4);
262 }
263 },
264 _ => {},
265 },
266 _ => {},
267 }
268
269 next
270 }
271}