veloren_voxygen_anim/biped_large/
spritesummon.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedLargeSkeleton, SkeletonAttr,
4};
5use common::{
6    comp::item::{AbilitySpec, ToolKind},
7    states::utils::StageSection,
8};
9use std::f32::consts::PI;
10
11pub struct SpriteSummonAnimation;
12
13type SpriteSummonAnimationDependency<'a> = (
14    Option<ToolKind>,
15    (Option<ToolKind>, Option<&'a AbilitySpec>),
16    f32,
17    f32,
18    Option<StageSection>,
19    Option<&'a str>,
20);
21impl Animation for SpriteSummonAnimation {
22    type Dependency<'a> = SpriteSummonAnimationDependency<'a>;
23    type Skeleton = BipedLargeSkeleton;
24
25    #[cfg(feature = "use-dyn-lib")]
26    const UPDATE_FN: &'static [u8] = b"biped_large_sprite_summon\0";
27
28    #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_sprite_summon")]
29    fn update_skeleton_inner(
30        skeleton: &Self::Skeleton,
31        (
32            active_tool_kind,
33            _second_tool_kind,
34            _global_time,
35            velocity,
36            stage_section,
37            ability_id,
38        ): Self::Dependency<'_>,
39        anim_time: f32,
40        rate: &mut f32,
41        s_a: &SkeletonAttr,
42    ) -> Self::Skeleton {
43        *rate = 1.0;
44        let mut next = (*skeleton).clone();
45
46        next.main.position = Vec3::new(0.0, 0.0, 0.0);
47        next.main.orientation = Quaternion::rotation_x(0.0);
48
49        next.hand_l.position = Vec3::new(0.0, 0.0, s_a.grip.0);
50        next.hand_r.position = Vec3::new(0.0, 0.0, s_a.grip.0);
51
52        next.hand_l.orientation = Quaternion::rotation_x(0.0);
53        next.hand_r.orientation = Quaternion::rotation_x(0.0);
54
55        match active_tool_kind {
56            Some(ToolKind::Axe | ToolKind::Hammer | ToolKind::Sceptre) => {
57                let (move1base, move2, move3) = match stage_section {
58                    Some(StageSection::Buildup) => ((anim_time.powf(0.25)), 0.0, 0.0),
59                    Some(StageSection::Action) => (1.0, (anim_time), 0.0),
60                    Some(StageSection::Recover) => (1.0, 1.0, anim_time),
61                    _ => (0.0, 0.0, 0.0),
62                };
63                let pullback = 1.0 - move3;
64                let move1 = move1base * pullback;
65                let move2 = move2 * pullback;
66                let move2cyc = (move2 * 10.0).sin() * pullback;
67
68                next.shoulder_r.orientation =
69                    Quaternion::rotation_y(move1 * 0.5) * Quaternion::rotation_x(move1 * 0.5);
70                next.shoulder_l.orientation =
71                    Quaternion::rotation_y(move1 * 0.5) * Quaternion::rotation_x(move1 * 0.5);
72                next.head.orientation = Quaternion::rotation_x(move1 * -0.2)
73                    * Quaternion::rotation_z(move1 * -0.6 + move2 * 1.2);
74
75                next.main.position = Vec3::new(0.0, 0.0, 0.0);
76                next.main.orientation = Quaternion::rotation_x(0.0);
77
78                next.hand_l.position = Vec3::new(s_a.grip.1, 0.0, s_a.grip.0);
79                next.hand_r.position = Vec3::new(-s_a.grip.1, 0.0, s_a.grip.0);
80
81                next.hand_l.orientation = Quaternion::rotation_x(0.0);
82                next.hand_r.orientation = Quaternion::rotation_x(0.0);
83
84                next.main.orientation = Quaternion::rotation_x(move2 * -0.5);
85
86                next.control_l.position =
87                    Vec3::new(-1.0 + move1 * 16.0, 2.0, 12.0 + move1 * 20.0 + move2 * 20.0);
88                next.control_r.position = Vec3::new(1.0, 2.0 + move1 * 3.0, -2.0);
89
90                next.control.position = Vec3::new(
91                    4.0 + move1 * 5.0 + move2 * 10.0,
92                    0.0 + s_a.grip.0 / 1.0 + move1 * 5.0 + move2 * -5.0,
93                    -s_a.grip.0 / 0.8 + move1 * -2.0,
94                );
95
96                next.control_l.orientation =
97                    Quaternion::rotation_x(PI / 2.0 + move1 * -0.2 + move2 * 0.9)
98                        * Quaternion::rotation_z(move1 * -3.0 + move2cyc * 0.15);
99                next.control_r.orientation =
100                    Quaternion::rotation_x(PI / 2.0 + 0.2 + move1 * -0.35 + move2 * -0.5)
101                        * Quaternion::rotation_y(move1 * 0.5)
102                        * Quaternion::rotation_z(0.0);
103                next.control.orientation = Quaternion::rotation_x(-1.0 + move1 * -1.8)
104                    * Quaternion::rotation_y(-1.8 + move1 * -0.0)
105                    * Quaternion::rotation_z(0.0 + move1 * -2.5);
106
107                next.torso.position = Vec3::new(0.0, 0.0, 0.0);
108                next.upper_torso.orientation = Quaternion::rotation_z(move1 * -0.5 + move2 * 0.5)
109                    * Quaternion::rotation_y(move2 * 0.1);
110
111                next.lower_torso.orientation = Quaternion::rotation_z(move1 * 0.5 + move2 * -0.5)
112                    * Quaternion::rotation_y(move2 * -0.1);
113            },
114            Some(ToolKind::Natural) => match ability_id {
115                Some(
116                    "common.abilities.custom.harvester.ensnaringvines_sparse"
117                    | "common.abilities.custom.harvester.ensnaringvines_dense",
118                ) => {
119                    let (move1, move1pow, move2, move3) = match stage_section {
120                        Some(StageSection::Buildup) => (anim_time, anim_time.powf(0.1), 0.0, 0.0),
121                        Some(StageSection::Action) => {
122                            (1.0, 1.0, (anim_time.powf(4.0) * 80.0).min(1.0), 0.0)
123                        },
124                        Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time),
125                        _ => (0.0, 0.0, 0.0, 0.0),
126                    };
127
128                    let speed = Vec2::<f32>::from(velocity).magnitude();
129
130                    let pullback = 1.0 - move3;
131                    let move1 = move1 * pullback;
132                    let move1pow = move1pow * pullback;
133                    let move2 = move2 * pullback;
134
135                    next.head.orientation = Quaternion::rotation_x(move1 * 0.2);
136                    next.jaw.position = Vec3::new(0.0, s_a.jaw.0, s_a.jaw.1);
137                    next.jaw.orientation = Quaternion::rotation_x(move2 * -0.3);
138
139                    let twist = move1 * 0.8 + move3 * -0.8;
140                    next.upper_torso.position = Vec3::new(
141                        0.0,
142                        s_a.upper_torso.0,
143                        s_a.upper_torso.1 + move1 * 1.0 + move2 * -1.0,
144                    );
145                    next.upper_torso.orientation =
146                        Quaternion::rotation_x(move1 * 0.8 + move2 * -1.1)
147                            * Quaternion::rotation_z(twist * -0.2 + move1 * -0.1 + move2 * 0.3);
148
149                    next.lower_torso.orientation =
150                        Quaternion::rotation_x(move1 * -0.8 + move2 * 1.1)
151                            * Quaternion::rotation_z(-twist + move1 * 0.4);
152
153                    next.control_l.position = Vec3::new(1.0, 2.0, 8.0);
154                    next.control_r.position = Vec3::new(1.0, 1.0, -2.0);
155
156                    next.control.position = Vec3::new(
157                        -7.0 + move1pow * 7.0,
158                        0.0 + s_a.grip.0 / 1.0 + move1pow * 12.0,
159                        -s_a.grip.0 / 0.8 + move1pow * 20.0 + move2 * -3.0,
160                    );
161
162                    next.control_l.orientation =
163                        Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_z(PI);
164                    next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + 0.2)
165                        * Quaternion::rotation_y(-1.0)
166                        * Quaternion::rotation_z(0.0);
167
168                    next.control.orientation =
169                        Quaternion::rotation_x(-1.4 + move1pow * 2.2 + move2 * -0.6)
170                            * Quaternion::rotation_y(-PI);
171
172                    next.shoulder_l.position =
173                        Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
174                    next.shoulder_l.orientation = Quaternion::rotation_x(-0.4 + move1pow * 1.6);
175                    next.shoulder_r.orientation =
176                        Quaternion::rotation_y(0.4) * Quaternion::rotation_x(0.4 + move1pow * 1.0);
177
178                    if speed == 0.0 {
179                        next.leg_l.orientation = Quaternion::rotation_x(move1 * 0.8 + move2 * -0.8);
180
181                        next.foot_l.position = Vec3::new(
182                            -s_a.foot.0,
183                            s_a.foot.1,
184                            s_a.foot.2 + move1 * 4.0 + move2 * -4.0,
185                        );
186                        next.foot_l.orientation =
187                            Quaternion::rotation_x(move1 * -0.6 + move2 * 0.6);
188                    }
189                },
190                Some("common.abilities.custom.minotaur.ironspike_targeted") => {
191                    let (move1base, move2, move3) = match stage_section {
192                        Some(StageSection::Buildup) => ((anim_time.powf(0.25)), 0.0, 0.0),
193                        Some(StageSection::Action) => (1.0, (anim_time), 0.0),
194                        Some(StageSection::Recover) => (1.0, 1.0, anim_time),
195                        _ => (0.0, 0.0, 0.0),
196                    };
197                    let pullback = 1.0 - move3;
198                    let move1 = move1base * pullback;
199                    let move2 = move2 * pullback;
200                    let move2cyc = (move2 * 10.0).sin() * pullback;
201
202                    next.shoulder_r.orientation =
203                        Quaternion::rotation_y(move1 * 0.5) * Quaternion::rotation_x(move1 * 0.5);
204                    next.shoulder_l.orientation =
205                        Quaternion::rotation_y(move1 * 0.5) * Quaternion::rotation_x(move1 * 0.5);
206                    next.head.orientation = Quaternion::rotation_x(move1 * -0.2)
207                        * Quaternion::rotation_z(move1 * -0.6 + move2 * 1.2);
208
209                    next.main.position = Vec3::new(0.0, 0.0, 0.0);
210                    next.main.orientation = Quaternion::rotation_x(0.0);
211
212                    next.hand_l.position = Vec3::new(s_a.grip.1, 0.0, s_a.grip.0);
213                    next.hand_r.position = Vec3::new(-s_a.grip.1, 0.0, s_a.grip.0);
214
215                    next.hand_l.orientation = Quaternion::rotation_x(0.0);
216                    next.hand_r.orientation = Quaternion::rotation_x(0.0);
217
218                    next.main.orientation = Quaternion::rotation_x(move2 * -0.5);
219
220                    next.control_l.position =
221                        Vec3::new(-1.0 + move1 * 16.0, 2.0, 12.0 + move1 * 20.0 + move2 * 20.0);
222                    next.control_r.position = Vec3::new(1.0, 2.0 + move1 * 3.0, -2.0);
223
224                    next.control.position = Vec3::new(
225                        4.0 + move1 * 5.0 + move2 * 10.0,
226                        0.0 + s_a.grip.0 / 1.0 + move1 * 5.0 + move2 * -5.0,
227                        -s_a.grip.0 / 0.8 + move1 * -2.0,
228                    );
229
230                    next.control_l.orientation =
231                        Quaternion::rotation_x(PI / 2.0 + move1 * -0.2 + move2 * 0.9)
232                            * Quaternion::rotation_z(move1 * -3.0 + move2cyc * 0.15);
233                    next.control_r.orientation =
234                        Quaternion::rotation_x(PI / 2.0 + 0.2 + move1 * -0.35 + move2 * -0.5)
235                            * Quaternion::rotation_y(move1 * 0.5)
236                            * Quaternion::rotation_z(0.0);
237                    next.control.orientation = Quaternion::rotation_x(-1.0 + move1 * -1.8)
238                        * Quaternion::rotation_y(-1.8 + move1 * -0.0)
239                        * Quaternion::rotation_z(0.0 + move1 * -2.5);
240
241                    next.torso.position = Vec3::new(0.0, 0.0, 0.0);
242                    next.upper_torso.orientation =
243                        Quaternion::rotation_z(move1 * -0.5 + move2 * 0.5)
244                            * Quaternion::rotation_y(move2 * 0.1);
245
246                    next.lower_torso.orientation =
247                        Quaternion::rotation_z(move1 * 0.5 + move2 * -0.5)
248                            * Quaternion::rotation_y(move2 * -0.1);
249                },
250                _ => {},
251            },
252            _ => {},
253        }
254        next
255    }
256}