veloren_voxygen_anim/biped_large/
chargemelee.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 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        match active_tool_kind {
104            Some(ToolKind::Natural) => match ability_id {
105                Some("common.abilities.custom.minotaur.cleave") => {
106                    next.upper_torso.orientation =
107                        Quaternion::rotation_x(move1 * 0.3 + move2 * -0.9);
108                    next.lower_torso.orientation =
109                        Quaternion::rotation_x(move1 * -0.3 + move2 * 0.9);
110                    next.head.orientation = Quaternion::rotation_x(move1 * -0.5 + move2 * 0.5);
111
112                    next.control_l.position = Vec3::new(0.0, 4.0, 5.0);
113                    next.control_r.position = Vec3::new(0.0, 4.0, 5.0);
114                    next.weapon_l.position = Vec3::new(
115                        -12.0 + move2 * 5.0,
116                        -6.0 + move1 * 22.0 + move2 * 8.0,
117                        -18.0 + move1 * 16.0 + move2 * -19.0,
118                    );
119                    next.weapon_r.position = Vec3::new(
120                        12.0 + move2 * -5.0,
121                        -6.0 + move1 * 22.0 + move2 * 8.0,
122                        -18.0 + move1 * 14.0 + move2 * -19.0,
123                    );
124                    next.torso.position = Vec3::new(0.0, move2 * 7.06, 0.0);
125                    next.second.scale = Vec3::one() * 1.0;
126
127                    next.weapon_l.orientation =
128                        Quaternion::rotation_x(-1.67 + move1 * 2.8 + tension * 0.03 + move2 * -2.3)
129                            * Quaternion::rotation_y(move1 * 0.3 + move2 * 0.5);
130                    next.weapon_r.orientation = Quaternion::rotation_x(
131                        -1.67 + move1 * 1.6 + tension * -0.03 + move2 * -0.7,
132                    ) * Quaternion::rotation_y(
133                        move1 * -0.3 + move2 * -0.5,
134                    ) * Quaternion::rotation_z(0.0);
135
136                    next.control_l.orientation =
137                        Quaternion::rotation_x(PI / 2.0 + move1 * 0.2 + move2 * 0.1);
138                    next.control_r.orientation =
139                        Quaternion::rotation_x(PI / 2.0 + move1 * 0.4 + move2 * -0.4);
140
141                    next.control.orientation =
142                        Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0);
143                    next.shoulder_l.orientation = Quaternion::rotation_x(-0.3 + move1 * 1.0);
144
145                    next.shoulder_r.orientation = Quaternion::rotation_x(-0.3 + move1 * 1.0);
146                },
147                Some("common.abilities.custom.husk_brute.chargedmelee") => {
148                    next.second.scale = Vec3::one() * 0.0;
149
150                    next.head.orientation = Quaternion::rotation_x(move1 * 0.3 + move2 * -0.6);
151                    next.jaw.position = Vec3::new(0.0, s_a.jaw.0, s_a.jaw.1);
152                    next.jaw.orientation = Quaternion::rotation_x(move2 * -0.3);
153                    next.control_l.position = Vec3::new(-0.5, 4.0, 1.0);
154                    next.control_r.position = Vec3::new(-0.5, 4.0, 1.0);
155                    next.control_l.orientation = Quaternion::rotation_x(PI / 2.0);
156                    next.control_r.orientation = Quaternion::rotation_x(PI / 2.0);
157                    next.weapon_l.position =
158                        Vec3::new(-12.0 + (move1 * 10.0).min(6.0), -1.0, -15.0);
159                    next.weapon_r.position =
160                        Vec3::new(12.0 + (move1 * -10.0).max(-6.0), -1.0, -15.0);
161
162                    next.weapon_l.orientation = Quaternion::rotation_x(-PI / 2.0 - 0.1)
163                        * Quaternion::rotation_z(move1 * -0.8);
164                    next.weapon_r.orientation = Quaternion::rotation_x(-PI / 2.0 - 0.1)
165                        * Quaternion::rotation_z(move1 * 0.8);
166
167                    next.shoulder_l.orientation =
168                        Quaternion::rotation_x(-0.3 + move1 * 2.8 + move2 * -2.8);
169
170                    next.shoulder_r.orientation =
171                        Quaternion::rotation_x(-0.3 + move1 * 2.8 + move2 * -2.8);
172
173                    next.control.orientation = Quaternion::rotation_x(move1 * 2.5 + move2 * -2.0);
174
175                    next.upper_torso.position =
176                        Vec3::new(0.0, s_a.upper_torso.0, s_a.upper_torso.1);
177                    next.upper_torso.orientation =
178                        Quaternion::rotation_x(move1 * 0.2 + move2 * -0.6);
179                    next.lower_torso.orientation =
180                        Quaternion::rotation_x(move1 * -0.2 + move2 * 0.6);
181
182                    if speed < 0.1 {
183                        next.foot_l.position = Vec3::new(
184                            -s_a.foot.0,
185                            s_a.foot.1 + move1 * -7.0 + move2 * 7.0,
186                            s_a.foot.2,
187                        );
188                        next.foot_l.orientation =
189                            Quaternion::rotation_x(move1 * -0.8 + move2 * 0.8)
190                                * Quaternion::rotation_z(move1 * 0.3 + move2 * -0.3);
191
192                        next.foot_r.position = Vec3::new(
193                            s_a.foot.0,
194                            s_a.foot.1 + move1 * 5.0 + move2 * -5.0,
195                            s_a.foot.2,
196                        );
197                        next.foot_r.orientation =
198                            Quaternion::rotation_y(move1 * -0.3 + move2 * 0.3)
199                                * Quaternion::rotation_z(move1 * 0.4 + move2 * -0.4);
200                    }
201                    next.main.orientation = Quaternion::rotation_y(move1 * 0.4 + move2 * -0.6)
202                        * Quaternion::rotation_x(move2 * -0.4);
203                },
204                Some("common.abilities.custom.tursus.tusk_stab") => {
205                    next.second.scale = Vec3::one() * 0.0;
206                    next.head.position = Vec3::new(
207                        0.0,
208                        s_a.head.0 + move1 * 15.0,
209                        s_a.head.1 + move1 * 6.0 + move2 * -4.0,
210                    );
211                    next.head.orientation = Quaternion::rotation_x(move1 * 1.3 + move2 * -0.7);
212                    next.jaw.position = Vec3::new(0.0, s_a.jaw.0, s_a.jaw.1);
213                    next.jaw.orientation = Quaternion::rotation_x(move2 * -0.3);
214                    next.control_l.position = Vec3::new(-0.5, 4.0, 1.0);
215                    next.control_r.position = Vec3::new(-0.5, 4.0, 1.0);
216                    next.control_l.orientation = Quaternion::rotation_x(PI / 2.0);
217                    next.control_r.orientation = Quaternion::rotation_x(PI / 2.0);
218                    next.weapon_l.position =
219                        Vec3::new(-16.0 + (move1 * 10.0).min(6.0), -1.0, -15.0);
220                    next.weapon_r.position =
221                        Vec3::new(16.0 + (move1 * -10.0).max(-6.0), -1.0, -15.0);
222
223                    next.weapon_l.orientation = Quaternion::rotation_x(-PI / 2.0 - 0.1)
224                        * Quaternion::rotation_z(move1 * -0.8);
225                    next.weapon_r.orientation = Quaternion::rotation_x(-PI / 2.0 - 0.1)
226                        * Quaternion::rotation_z(move1 * 0.8);
227
228                    next.shoulder_l.orientation =
229                        Quaternion::rotation_x(-0.3 + move1 * -0.4 + move2 * 0.4);
230
231                    next.shoulder_r.orientation =
232                        Quaternion::rotation_x(-0.3 + move1 * -0.4 + move2 * 0.4);
233
234                    next.control.orientation = Quaternion::rotation_x(move1 * -0.7 + move2 * 0.7);
235
236                    next.upper_torso.position =
237                        Vec3::new(0.0, s_a.upper_torso.0, s_a.upper_torso.1);
238                    next.upper_torso.orientation =
239                        Quaternion::rotation_x(move1 * 0.6 + move2 * -1.1);
240                    next.lower_torso.orientation =
241                        Quaternion::rotation_x(move1 * -0.2 + move2 * 0.6);
242
243                    if speed < 0.1 {
244                        next.foot_l.position = Vec3::new(
245                            -s_a.foot.0,
246                            s_a.foot.1 + move1 * -7.0 + move2 * 7.0,
247                            s_a.foot.2,
248                        );
249                        next.foot_l.orientation =
250                            Quaternion::rotation_x(move1 * -0.8 + move2 * 0.8)
251                                * Quaternion::rotation_z(move1 * 0.3 + move2 * -0.3);
252
253                        next.foot_r.position = Vec3::new(
254                            s_a.foot.0,
255                            s_a.foot.1 + move1 * 5.0 + move2 * -5.0,
256                            s_a.foot.2,
257                        );
258                        next.foot_r.orientation =
259                            Quaternion::rotation_y(move1 * -0.3 + move2 * 0.3)
260                                * Quaternion::rotation_z(move1 * 0.4 + move2 * -0.4);
261                    }
262                },
263                _ => {},
264            },
265            _ => {},
266        }
267
268        next
269    }
270}