veloren_voxygen_anim/biped_small/
summon.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedSmallSkeleton, SkeletonAttr,
4};
5use common::{comp::item::ToolKind, states::utils::StageSection};
6use std::f32::consts::PI;
7
8pub struct SummonAnimation;
9
10type SummonAnimationDependency<'a> = (
11    Option<&'a str>,
12    Option<ToolKind>,
13    Vec3<f32>,
14    Vec3<f32>,
15    Vec3<f32>,
16    f32,
17    Vec3<f32>,
18    f32,
19    Option<StageSection>,
20    f32,
21);
22
23impl Animation for SummonAnimation {
24    type Dependency<'a> = SummonAnimationDependency<'a>;
25    type Skeleton = BipedSmallSkeleton;
26
27    #[cfg(feature = "use-dyn-lib")]
28    const UPDATE_FN: &'static [u8] = b"biped_small_summon\0";
29
30    #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "biped_small_summon"))]
31    fn update_skeleton_inner(
32        skeleton: &Self::Skeleton,
33        (
34            ability_id,
35            active_tool_kind,
36            _velocity,
37            _orientation,
38            _last_ori,
39            global_time,
40            _avg_vel,
41            _acc_vel,
42            stage_section,
43            timer,
44        ): Self::Dependency<'_>,
45        anim_time: f32,
46        _rate: &mut f32,
47        s_a: &SkeletonAttr,
48    ) -> Self::Skeleton {
49        let mut next = (*skeleton).clone();
50
51        let anim_time = anim_time.min(1.0);
52        let (move1base, twitch, twitch2, move2base, move3) = match stage_section {
53            Some(StageSection::Buildup) => {
54                (anim_time.sqrt(), (anim_time * 5.0).sin(), 0.0, 0.0, 0.0)
55            },
56            Some(StageSection::Action) => {
57                (1.0, 1.0, (anim_time * 10.0).sin(), anim_time.powi(4), 0.0)
58            },
59            Some(StageSection::Recover) => (1.0, 1.0, 1.0, 1.0, anim_time),
60            _ => (0.0, 0.0, 0.0, 0.0, 0.0),
61        };
62        let pullback = 1.0 - move3;
63        let twitch = twitch * pullback;
64        let twitch2 = twitch2 * pullback;
65        let subtract = global_time - timer;
66        let check = subtract - subtract.trunc();
67        let mirror = (check - 0.5).signum();
68        let move1 = move1base * pullback * mirror;
69        let move2 = move2base * pullback * mirror;
70        let move1abs = move1base * pullback;
71        let move2abs = move2base * pullback;
72        next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
73        next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
74        next.main.position = Vec3::new(0.0, 0.0, 0.0);
75        next.main.orientation = Quaternion::rotation_x(0.0);
76        next.hand_l.orientation = Quaternion::rotation_x(0.0);
77        next.hand_r.orientation = Quaternion::rotation_x(0.0);
78        match active_tool_kind {
79            Some(ToolKind::Staff) => match ability_id {
80                Some("common.abilities.custom.dwarves.flamekeeper.summon_lavathrower") => {
81                    next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 3.0, 3.0);
82                    next.control_r.position = Vec3::new(
83                        12.0 + s_a.grip.0 * 2.0,
84                        -4.0 + move1abs * -20.0,
85                        3.0 + twitch * 2.0 + twitch2 * 2.0,
86                    );
87
88                    next.control.position = Vec3::new(
89                        -5.0 + move1abs * -5.0,
90                        -1.0 + s_a.grip.2 + move1abs * -8.0,
91                        -2.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + twitch2 * -2.0,
92                    );
93                    next.chest.position =
94                        Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + twitch2 + move2abs * 2.0);
95                    next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
96                        * Quaternion::rotation_y(-0.3)
97                        * Quaternion::rotation_z(-0.3);
98                    next.control_r.orientation = Quaternion::rotation_x(
99                        PI / 2.0 + s_a.grip.0 * 0.2 + twitch * 0.2 + twitch2 * 0.2,
100                    ) * Quaternion::rotation_y(
101                        -0.4 + s_a.grip.0 * 0.2 + move1abs * -2.0,
102                    ) * Quaternion::rotation_z(move1abs * 0.5);
103
104                    next.control.orientation = Quaternion::rotation_x(-0.3)
105                        * Quaternion::rotation_y(0.0)
106                        * Quaternion::rotation_z(0.5 + move1abs * 1.0);
107                    next.chest.orientation =
108                        Quaternion::rotation_x(0.0) * Quaternion::rotation_z(0.0);
109                    next.head.orientation =
110                        Quaternion::rotation_z(twitch * 0.2 + twitch2 * 0.4 + move2abs * -0.5)
111                            * Quaternion::rotation_x(move2abs * 0.7);
112                },
113                Some("common.abilities.custom.ashen_warrior.staff.flame_wall") => {
114                    let slow = (global_time * 4.0).sin();
115                    let (move1base, move2base, move3base) = match stage_section {
116                        Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
117                        Some(StageSection::Action) => (1.0, anim_time, 0.0),
118                        Some(StageSection::Recover) => (1.0, 1.0, anim_time),
119                        _ => (0.0, 0.0, 0.0),
120                    };
121
122                    let pullback = 1.0 - move3base;
123                    let move1 = move1base * pullback;
124
125                    next.control.position +=
126                        Vec3::new(-8.0, 8.0, 10.0) * move1 + Vec3::new(0.5, 0.5, 2.0) * slow;
127                    next.control.orientation.rotate_z(0.15 * slow);
128                    next.control.orientation.rotate_x(-PI / 10.0 * move1);
129                    next.control_l.position += Vec3::new(7.0, -2.0, 0.0) * move1;
130                    next.control_l.orientation.rotate_x(PI / 1.3 * move1);
131                    next.control_l.orientation.rotate_z(-PI / 4.0 * move1);
132                    next.control_r.position += Vec3::new(4.0, -2.0, 0.0) * move1;
133                    next.control_r.orientation.rotate_x(PI / 1.3 * move1);
134                    next.control_r.orientation.rotate_z(PI / 2.0 * move1);
135
136                    next.chest.orientation.rotate_z(2.0 * PI * move2base);
137                    next.foot_l.position += Vec3::new(
138                        (2.0 * PI * move2base + PI).cos() + 1.0,
139                        (2.0 * PI * move2base + PI).sin(),
140                        0.0,
141                    ) * 3.0;
142                    next.foot_l.orientation.rotate_z(2.0 * PI * move2base);
143                    next.foot_r.position += Vec3::new(
144                        (2.0 * PI * move2base).cos() - 1.0,
145                        (2.0 * PI * move2base).sin(),
146                        0.0,
147                    ) * 3.0;
148                    next.foot_r.orientation.rotate_z(2.0 * PI * move2base);
149                },
150                Some("common.abilities.custom.ashen_warrior.staff.summon_crux") => {
151                    let slow = (global_time * 4.0).sin();
152                    let (move1base, _, move3base) = match stage_section {
153                        Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
154                        Some(StageSection::Action) => (1.0, anim_time, 0.0),
155                        Some(StageSection::Recover) => (1.0, 1.0, anim_time),
156                        _ => (0.0, 0.0, 0.0),
157                    };
158
159                    let pullback = 1.0 - move3base;
160                    let move1 = move1base * pullback;
161
162                    next.main.position = Vec3::new(-10.0, 5.0, 0.0);
163                    next.main.orientation = Quaternion::rotation_x(0.0);
164                    next.hand_l.position = Vec3::new(s_a.grip.0 * 5.0, 0.0, 2.0);
165                    next.hand_l.orientation = Quaternion::rotation_x(PI / 2.0);
166                    next.hand_r.position = Vec3::new(-s_a.grip.0 * 5.0, 0.0, 2.0);
167                    next.hand_r.orientation = Quaternion::rotation_x(PI / 2.0);
168
169                    next.head.position += Vec3::new(0.0, -4.0, 0.0) * move1;
170                    next.head.orientation.rotate_x(PI / 10.0 * move1);
171                    next.chest.orientation.rotate_x(PI / 10.0 * move1);
172                    next.hand_l.orientation.rotate_x(PI / 10.0 * move1);
173                    next.hand_l.orientation.rotate_y(PI / 10.0 * move1);
174                    next.hand_r.orientation.rotate_x(PI / 10.0 * move1);
175                    next.hand_r.orientation.rotate_y(-PI / 10.0 * move1);
176                    next.main.position += Vec3::new(0.0, 0.0, 2.0) * move1;
177                    next.main.orientation.rotate_y(PI / 10.0 * move1);
178                    next.control.position +=
179                        Vec3::new(0.0, 4.0, 10.0) * move1 + Vec3::new(0.5, 0.5, 2.0) * slow;
180                },
181                _ => {
182                    next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
183                    next.control_r.position = Vec3::new(
184                        7.0 + s_a.grip.0 * 2.0,
185                        -4.0 + move1abs * -14.0,
186                        3.0 + twitch * 2.0 + twitch2 * 2.0,
187                    );
188
189                    next.control.position = Vec3::new(
190                        -5.0 + move1abs * -5.0,
191                        -1.0 + s_a.grip.2 + move1abs * -8.0,
192                        -2.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + twitch2 * -2.0,
193                    );
194                    next.chest.position =
195                        Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + twitch2 + move2abs * 3.0);
196                    next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
197                        * Quaternion::rotation_y(-0.3)
198                        * Quaternion::rotation_z(-0.3);
199                    next.control_r.orientation = Quaternion::rotation_x(
200                        PI / 2.0 + s_a.grip.0 * 0.2 + twitch * 0.2 + twitch2 * 0.2,
201                    ) * Quaternion::rotation_y(
202                        -0.4 + s_a.grip.0 * 0.2 + move1abs * -2.0,
203                    ) * Quaternion::rotation_z(move1abs * 0.5);
204
205                    next.control.orientation = Quaternion::rotation_x(-0.3)
206                        * Quaternion::rotation_y(0.0)
207                        * Quaternion::rotation_z(0.5 + move1abs * 1.0);
208                    next.chest.orientation =
209                        Quaternion::rotation_x(0.0) * Quaternion::rotation_z(0.0);
210                    next.head.orientation =
211                        Quaternion::rotation_z(twitch * 0.2 + twitch2 * 0.4 + move2abs * -0.5)
212                            * Quaternion::rotation_x(move2abs * 0.7);
213                },
214            },
215            Some(ToolKind::Sword) => {
216                next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 3.0, 3.0);
217                next.control_r.position =
218                    Vec3::new(12.0 + s_a.grip.0 * 2.0, -4.0 + move1abs * -14.0, 3.0);
219
220                next.control.position = Vec3::new(
221                    -5.0 + move1abs * -5.0,
222                    -1.0 + s_a.grip.2 + move1abs * -8.0,
223                    s_a.grip.2 / 2.0,
224                );
225                next.chest.position =
226                    Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + twitch2 + move2abs * 2.0);
227                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
228                    * Quaternion::rotation_y(-0.3)
229                    * Quaternion::rotation_z(-0.3);
230                next.control_r.orientation = Quaternion::rotation_x(
231                    PI / 2.0 + s_a.grip.0 * 0.2 + twitch * 0.2 + twitch2 * 0.2,
232                ) * Quaternion::rotation_y(
233                    -0.4 + s_a.grip.0 * 0.2 + move1abs * -2.0,
234                ) * Quaternion::rotation_z(move1abs * 0.5);
235
236                next.chest.position = Vec3::new(
237                    0.0,
238                    s_a.chest.0,
239                    s_a.chest.1 + move1abs * 6.0 + twitch2 + move2abs * 3.0,
240                );
241                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
242                    * Quaternion::rotation_y(-0.3)
243                    * Quaternion::rotation_z(-0.3);
244                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
245                    * Quaternion::rotation_y(-0.3)
246                    * Quaternion::rotation_z(0.3);
247                next.control.orientation = Quaternion::rotation_x(-0.3)
248                    * Quaternion::rotation_y(0.0)
249                    * Quaternion::rotation_z(0.5 + move1abs * 1.0);
250                next.chest.orientation = Quaternion::rotation_x(0.0) * Quaternion::rotation_z(0.0);
251                next.head.orientation =
252                    Quaternion::rotation_z(twitch * 0.2 + twitch2 * 0.4 + move2abs * -0.5)
253                        * Quaternion::rotation_x(move2abs * 0.4);
254            },
255            _ => {
256                next.chest.orientation = Quaternion::rotation_x(move2abs * -1.0)
257                    * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
258                next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
259                next.hand_l.orientation = Quaternion::rotation_x(1.2);
260                next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
261                next.hand_r.orientation = Quaternion::rotation_x(1.2);
262            },
263        }
264        next
265    }
266}