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