veloren_voxygen_anim/biped_small/
alpha.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedSmallSkeleton, SkeletonAttr, biped_small_alpha_axe, biped_small_alpha_dagger,
4    biped_small_alpha_spear, biped_small_wield_bow, biped_small_wield_sword,
5    init_biped_small_alpha,
6};
7use common::{comp::item::ToolKind, states::utils::StageSection};
8use std::f32::consts::PI;
9
10pub struct AlphaAnimation;
11
12type AlphaAnimationDependency<'a> = (
13    Option<&'a str>,
14    Option<ToolKind>,
15    Vec3<f32>,
16    Vec3<f32>,
17    Vec3<f32>,
18    f32,
19    Vec3<f32>,
20    f32,
21    Option<StageSection>,
22    f32,
23);
24
25impl Animation for AlphaAnimation {
26    type Dependency<'a> = AlphaAnimationDependency<'a>;
27    type Skeleton = BipedSmallSkeleton;
28
29    #[cfg(feature = "use-dyn-lib")]
30    const UPDATE_FN: &'static [u8] = b"biped_small_alpha\0";
31
32    #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_small_alpha")]
33
34    fn update_skeleton_inner(
35        skeleton: &Self::Skeleton,
36        (
37            ability_id,
38            active_tool_kind,
39            velocity,
40            _orientation,
41            _last_ori,
42            global_time,
43            _avg_vel,
44            acc_vel,
45            stage_section,
46            timer,
47        ): Self::Dependency<'_>,
48        anim_time: f32,
49        _rate: &mut f32,
50        s_a: &SkeletonAttr,
51    ) -> Self::Skeleton {
52        let mut next = (*skeleton).clone();
53        let speed = Vec2::<f32>::from(velocity).magnitude();
54        let speednorm = speed / 9.4;
55        let speednormcancel = 1.0 - speednorm;
56
57        let anim_time = anim_time.min(1.0);
58        let (move1base, move2base, move3) = match stage_section {
59            Some(StageSection::Buildup) => (anim_time.sqrt(), 0.0, 0.0),
60            Some(StageSection::Action) => (1.0, anim_time.powi(4), 0.0),
61            Some(StageSection::Recover) => (1.0, 1.0, anim_time),
62            _ => (0.0, 0.0, 0.0),
63        };
64        let pullback = 1.0 - move3;
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
73        init_biped_small_alpha(&mut next, s_a);
74
75        match active_tool_kind {
76            Some(ToolKind::Spear) => {
77                biped_small_alpha_spear(
78                    &mut next,
79                    s_a,
80                    move1abs,
81                    move2abs,
82                    anim_time,
83                    speednormcancel,
84                );
85            },
86            Some(ToolKind::Axe | ToolKind::Hammer | ToolKind::Pick | ToolKind::Shovel) => {
87                biped_small_alpha_axe(&mut next, s_a, move1abs, move2abs);
88            },
89            Some(ToolKind::Dagger) => {
90                biped_small_alpha_dagger(&mut next, s_a, move1abs, move2abs);
91            },
92            Some(ToolKind::Sword) => {
93                let slow = (anim_time * 2.0).sin();
94                biped_small_wield_sword(&mut next, s_a, speednorm, slow);
95
96                next.chest.orientation.rotate_z(1.2 * move1abs);
97                next.head.orientation.rotate_z(-0.6 * move1abs);
98                next.pants.orientation.rotate_z(-0.6 * move1abs);
99                next.control.orientation.rotate_x(0.8 * move1abs);
100                next.control.orientation.rotate_y(-0.4 * move1abs);
101
102                next.chest.orientation.rotate_z(-3.0 * move2abs);
103                next.head.orientation.rotate_z(1.5 * move2abs);
104                next.pants.orientation.rotate_z(2.0 * move2abs);
105                next.control.orientation.rotate_x(-3.0 * move2abs);
106            },
107            Some(ToolKind::Staff) => match ability_id {
108                Some("common.abilities.custom.dwarves.flamekeeper.flamecrush") => {
109                    next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
110                    next.control_r.position = Vec3::new(12.0 + s_a.grip.0 * 2.0, -4.0, 3.0);
111
112                    next.control.position = Vec3::new(
113                        -9.0 + move1 * 5.0 + move2 * -5.0,
114                        2.0 + s_a.grip.2,
115                        -2.0 + -s_a.grip.2 / 2.5
116                            + s_a.grip.0 * -2.0
117                            + move1abs * 6.0
118                            + move2abs * -3.0,
119                    );
120
121                    next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
122                        * Quaternion::rotation_y(-0.3)
123                        * Quaternion::rotation_z(-0.3);
124                    next.control_r.orientation =
125                        Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
126                            * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2)
127                            * Quaternion::rotation_z(-0.0);
128
129                    next.control.orientation =
130                        Quaternion::rotation_x(-0.3 + move1abs * 1.0 + move2abs * -2.0)
131                            * Quaternion::rotation_y(0.0)
132                            * Quaternion::rotation_z(0.5);
133                    next.chest.orientation =
134                        Quaternion::rotation_x(move1abs * 0.5 + move2abs * -1.0)
135                            * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
136                    next.head.orientation = Quaternion::rotation_z(move1 * -0.8 + move2 * 0.8);
137                },
138                _ => {
139                    next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
140                    next.control_r.position = Vec3::new(7.0 + s_a.grip.0 * 2.0, -4.0, 3.0);
141
142                    next.control.position = Vec3::new(
143                        -5.0 + move1 * 5.0 + move2 * -5.0,
144                        -1.0 + s_a.grip.2,
145                        -2.0 + -s_a.grip.2 / 2.5
146                            + s_a.grip.0 * -2.0
147                            + move1abs * 6.0
148                            + move2abs * -3.0,
149                    );
150
151                    next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
152                        * Quaternion::rotation_y(-0.3)
153                        * Quaternion::rotation_z(-0.3);
154                    next.control_r.orientation =
155                        Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
156                            * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2)
157                            * Quaternion::rotation_z(-0.0);
158
159                    next.control.orientation =
160                        Quaternion::rotation_x(-0.3 + move1abs * 1.0 + move2abs * -2.0)
161                            * Quaternion::rotation_y(0.0)
162                            * Quaternion::rotation_z(0.5);
163                    next.chest.orientation =
164                        Quaternion::rotation_x(move1abs * 0.5 + move2abs * -1.0)
165                            * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
166                    next.head.orientation = Quaternion::rotation_z(move1 * -0.8 + move2 * 0.8);
167                },
168            },
169            Some(ToolKind::Bow) => match ability_id {
170                Some("common.abilities.haniwa.archer.kick") => {
171                    let fastacc = (acc_vel * 2.0).sin();
172                    biped_small_wield_bow(&mut next, s_a, anim_time, speed, fastacc);
173
174                    next.chest.orientation.rotate_z(move1abs * 1.1);
175                    next.control.orientation.rotate_z(move1abs * -0.9);
176                    next.control.position += Vec3::new(7.0, 1.0, 0.0) * move1abs;
177                    next.head.orientation.rotate_z(move1abs * -0.8);
178                    next.foot_l.orientation.rotate_z(move1abs * 1.1);
179
180                    next.chest.orientation.rotate_z(move2abs * -2.3);
181                    next.control.orientation.rotate_z(move2abs * 1.9);
182                    next.control.position += Vec3::new(-7.0, -1.0, 0.0) * move2abs;
183                    next.head.orientation.rotate_z(move2abs * 0.9);
184                    next.foot_l.orientation.rotate_y(move2abs * 1.3);
185                    next.foot_l.orientation.rotate_z(move2abs * -2.9);
186                    next.foot_l.position += Vec3::new(3.0, 8.0, 4.0) * move2abs;
187                },
188                _ => {},
189            },
190            Some(ToolKind::Natural) => {
191                let tension = match stage_section {
192                    Some(StageSection::Buildup) => (anim_time * 10.0).sin(),
193                    Some(StageSection::Action) => 1.0,
194                    Some(StageSection::Recover) => 1.0,
195                    _ => 0.0,
196                };
197                next.chest.orientation =
198                    Quaternion::rotation_x(move1abs * 1.0 + move2abs * -1.5 + tension * 0.2);
199                next.pants.orientation = Quaternion::rotation_x(move1abs * -0.5 + move2abs * 0.5);
200                next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
201                next.hand_l.orientation =
202                    Quaternion::rotation_x(1.2 + move1abs * 1.5 + move2abs * -1.0)
203                        * Quaternion::rotation_y(tension * 0.5);
204                next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
205                next.hand_r.orientation =
206                    Quaternion::rotation_x(1.2 + move1abs * 1.5 + move2abs * -1.0)
207                        * Quaternion::rotation_y(tension * -0.5);
208            },
209            _ => {
210                next.chest.orientation = Quaternion::rotation_x(move2abs * -1.0)
211                    * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
212                next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
213                next.hand_l.orientation = Quaternion::rotation_x(1.2);
214                next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
215                next.hand_r.orientation = Quaternion::rotation_x(1.2);
216            },
217        }
218        next
219    }
220}