veloren_voxygen_anim/character/
staggered.rs

1use super::{
2    super::{Animation, vek::*},
3    CharacterSkeleton, SkeletonAttr,
4};
5use common::{
6    comp::item::{Hands, ToolKind},
7    states::utils::StageSection,
8};
9use core::f32::consts::PI;
10
11pub struct StaggeredAnimation;
12
13type StaggeredAnimationDependency = (
14    Option<ToolKind>,
15    Option<ToolKind>,
16    (Option<Hands>, Option<Hands>),
17    f32,
18    f32,
19    Option<StageSection>,
20    f32,
21    bool,
22);
23impl Animation for StaggeredAnimation {
24    type Dependency<'a> = StaggeredAnimationDependency;
25    type Skeleton = CharacterSkeleton;
26
27    #[cfg(feature = "use-dyn-lib")]
28    const UPDATE_FN: &'static [u8] = b"character_staggered\0";
29
30    #[cfg_attr(feature = "be-dyn-lib", export_name = "character_staggered")]
31    fn update_skeleton_inner(
32        skeleton: &Self::Skeleton,
33        (
34            active_tool_kind,
35            second_tool_kind,
36            hands,
37            _velocity,
38            global_time,
39            stage_section,
40            timer,
41            wield_status,
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
50        let (movement1base, movement2) = match stage_section {
51            Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0),
52            Some(StageSection::Recover) => (1.0, anim_time.powf(4.0)),
53            _ => (0.0, 0.0),
54        };
55        let pullback = 1.0 - movement2;
56        let subtract = global_time - timer;
57        let check = subtract - subtract.trunc();
58        let mirror = (check - 0.5).signum();
59        let movement1 = movement1base * pullback * mirror;
60        let movement1abs = movement1base * pullback;
61        next.second.position = Vec3::new(0.0, 0.0, 0.0);
62        next.second.orientation = Quaternion::rotation_z(0.0);
63        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
64        next.head.orientation =
65            Quaternion::rotation_x(movement1abs * -0.2) * Quaternion::rotation_z(movement1 * -0.3);
66        next.shorts.orientation =
67            Quaternion::rotation_x(movement1abs * 0.2) * Quaternion::rotation_z(movement1 * -0.3);
68        next.belt.orientation =
69            Quaternion::rotation_x(movement1abs * 0.1) * Quaternion::rotation_z(movement1 * -0.2);
70        next.shorts.position = Vec3::new(0.0, s_a.shorts.0 + movement1abs * 1.0, s_a.shorts.1);
71        next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + movement1abs * -4.0);
72        next.chest.orientation =
73            Quaternion::rotation_x(movement1abs * -0.1) * Quaternion::rotation_z(movement1 * 1.3);
74        if wield_status {
75            next.main.position = Vec3::new(0.0, 0.0, 0.0);
76            next.main.orientation = Quaternion::rotation_x(0.0);
77            next.second.position = Vec3::new(0.0, 0.0, 0.0);
78            next.second.orientation = Quaternion::rotation_z(0.0);
79            match (hands, active_tool_kind, second_tool_kind) {
80                ((Some(Hands::Two), _), tool, _) | ((None, Some(Hands::Two)), _, tool) => {
81                    match tool {
82                        Some(ToolKind::Sword) => {
83                            next.hand_l.position = Vec3::new(s_a.shl.0, s_a.shl.1, s_a.shl.2);
84                            next.hand_l.orientation = Quaternion::rotation_x(s_a.shl.3)
85                                * Quaternion::rotation_y(s_a.shl.4);
86                            next.hand_r.position = Vec3::new(s_a.shr.0, s_a.shr.1, s_a.shr.2);
87                            next.hand_r.orientation = Quaternion::rotation_x(s_a.shr.3)
88                                * Quaternion::rotation_y(s_a.shr.4);
89
90                            next.control.position = Vec3::new(s_a.sc.0, s_a.sc.1, s_a.sc.2);
91                            next.control.orientation = Quaternion::rotation_x(s_a.sc.3);
92                        },
93                        Some(ToolKind::Axe) => {
94                            next.hand_l.position = Vec3::new(s_a.ahl.0, s_a.ahl.1, s_a.ahl.2);
95                            next.hand_l.orientation = Quaternion::rotation_x(s_a.ahl.3)
96                                * Quaternion::rotation_y(s_a.ahl.4);
97                            next.hand_r.position = Vec3::new(s_a.ahr.0, s_a.ahr.1, s_a.ahr.2);
98                            next.hand_r.orientation = Quaternion::rotation_x(s_a.ahr.3)
99                                * Quaternion::rotation_z(s_a.ahr.5);
100
101                            next.control.position = Vec3::new(s_a.ac.0, s_a.ac.1, s_a.ac.2);
102                            next.control.orientation = Quaternion::rotation_x(s_a.ac.3)
103                                * Quaternion::rotation_y(s_a.ac.4)
104                                * Quaternion::rotation_z(s_a.ac.5);
105                        },
106                        Some(ToolKind::Hammer | ToolKind::Pick | ToolKind::Shovel) => {
107                            next.hand_l.position = Vec3::new(s_a.hhl.0, s_a.hhl.1, s_a.hhl.2);
108                            next.hand_l.orientation = Quaternion::rotation_x(s_a.hhl.3)
109                                * Quaternion::rotation_y(s_a.hhl.4)
110                                * Quaternion::rotation_z(s_a.hhl.5);
111                            next.hand_r.position = Vec3::new(s_a.hhr.0, s_a.hhr.1, s_a.hhr.2);
112                            next.hand_r.orientation = Quaternion::rotation_x(s_a.hhr.3)
113                                * Quaternion::rotation_y(s_a.hhr.4)
114                                * Quaternion::rotation_z(s_a.hhr.5);
115
116                            next.control.position = Vec3::new(s_a.hc.0, s_a.hc.1, s_a.hc.2);
117                            next.control.orientation = Quaternion::rotation_x(s_a.hc.3)
118                                * Quaternion::rotation_y(s_a.hc.4)
119                                * Quaternion::rotation_z(s_a.hc.5);
120                        },
121                        Some(ToolKind::Staff) | Some(ToolKind::Sceptre) => {
122                            next.hand_r.position = Vec3::new(s_a.sthr.0, s_a.sthr.1, s_a.sthr.2);
123                            next.hand_r.orientation = Quaternion::rotation_x(s_a.sthr.3)
124                                * Quaternion::rotation_y(s_a.sthr.4);
125
126                            next.control.position = Vec3::new(s_a.stc.0, s_a.stc.1, s_a.stc.2);
127
128                            next.hand_l.position = Vec3::new(s_a.sthl.0, s_a.sthl.1, s_a.sthl.2);
129                            next.hand_l.orientation = Quaternion::rotation_x(s_a.sthl.3);
130
131                            next.control.orientation = Quaternion::rotation_x(s_a.stc.3)
132                                * Quaternion::rotation_y(s_a.stc.4)
133                                * Quaternion::rotation_z(s_a.stc.5);
134                        },
135                        Some(ToolKind::Bow) => {
136                            next.hand_l.position = Vec3::new(s_a.bhl.0, s_a.bhl.1, s_a.bhl.2);
137                            next.hand_l.orientation = Quaternion::rotation_x(s_a.bhl.3);
138                            next.hand_r.position = Vec3::new(s_a.bhr.0, s_a.bhr.1, s_a.bhr.2);
139                            next.hand_r.orientation = Quaternion::rotation_x(s_a.bhr.3);
140
141                            next.hold.position = Vec3::new(0.0, -1.0, -5.2);
142                            next.hold.orientation = Quaternion::rotation_x(-PI / 2.0);
143                            next.hold.scale = Vec3::one() * 1.0;
144
145                            next.control.position = Vec3::new(s_a.bc.0, s_a.bc.1, s_a.bc.2);
146                            next.control.orientation =
147                                Quaternion::rotation_y(s_a.bc.4) * Quaternion::rotation_z(s_a.bc.5);
148                        },
149                        Some(ToolKind::Debug) => {
150                            next.hand_l.position = Vec3::new(-7.0, 4.0, 3.0);
151                            next.hand_l.orientation = Quaternion::rotation_x(1.27);
152                            next.main.position = Vec3::new(-5.0, 5.0, 23.0);
153                            next.main.orientation = Quaternion::rotation_x(PI);
154                        },
155                        Some(ToolKind::Farming) => {
156                            next.hand_l.position = Vec3::new(9.0, 1.0, 1.0);
157                            next.hand_l.orientation = Quaternion::rotation_x(PI / 2.0);
158                            next.hand_r.position = Vec3::new(9.0, 1.0, 11.0);
159                            next.hand_r.orientation = Quaternion::rotation_x(PI / 2.0);
160                            next.main.position = Vec3::new(7.5, 7.5, 13.2);
161                            next.main.orientation = Quaternion::rotation_y(PI);
162
163                            next.control.position = Vec3::new(-11.0, 1.8, 4.0);
164                        },
165                        Some(ToolKind::Instrument) => {
166                            next.hand_l.position = Vec3::new(-7.0, 4.0, 3.0);
167                            next.hand_l.orientation = Quaternion::rotation_x(1.27);
168                            next.main.position = Vec3::new(-5.0, 5.0, 23.0);
169                            next.main.orientation = Quaternion::rotation_x(PI);
170                        },
171                        _ => {},
172                    }
173                },
174                ((_, _), _, _) => {},
175            };
176            match hands {
177                (Some(Hands::One), _) => {
178                    next.control_l.position = Vec3::new(-7.0, 8.0, 2.0);
179                    next.control_l.orientation = Quaternion::rotation_x(-0.3);
180                    next.hand_l.position = Vec3::new(0.0, -0.5, 0.0);
181                    next.hand_l.orientation = Quaternion::rotation_x(PI / 2.0)
182                },
183                (_, _) => {},
184            };
185            match hands {
186                (None | Some(Hands::One), Some(Hands::One)) => {
187                    next.control_r.position = Vec3::new(7.0, 8.0, 2.0);
188                    next.control_r.orientation = Quaternion::rotation_x(-0.3);
189                    next.hand_r.position = Vec3::new(0.0, -0.5, 0.0);
190                    next.hand_r.orientation = Quaternion::rotation_x(PI / 2.0)
191                },
192                (_, _) => {},
193            };
194            match hands {
195                (None, None) | (None, Some(Hands::One)) => {
196                    next.hand_l.position = Vec3::new(-4.5, 8.0, 5.0);
197                    next.hand_l.orientation =
198                        Quaternion::rotation_x(1.9) * Quaternion::rotation_y(-0.5)
199                },
200                (_, _) => {},
201            };
202            match hands {
203                (None, None) | (Some(Hands::One), None) => {
204                    next.hand_r.position = Vec3::new(4.5, 8.0, 5.0);
205                    next.hand_r.orientation =
206                        Quaternion::rotation_x(1.9) * Quaternion::rotation_y(0.5)
207                },
208                (_, _) => {},
209            }
210        } else if mirror > 0.0 {
211            next.hand_r.position = Vec3::new(
212                s_a.hand.0 + movement1abs * -9.0,
213                s_a.hand.1 + movement1 * 9.0,
214                s_a.hand.2 + movement1 * 5.0,
215            );
216            next.hand_r.orientation =
217                Quaternion::rotation_x(movement1 * 1.2) * Quaternion::rotation_y(movement1 * 1.5);
218            next.hand_l.position = Vec3::new(
219                -s_a.hand.0,
220                s_a.hand.1 + movement1abs * 3.0,
221                s_a.hand.2 + movement1abs * -1.0,
222            );
223            next.hand_l.orientation = Quaternion::rotation_x(movement1abs * 0.5)
224                * Quaternion::rotation_y(movement1 * 0.3);
225            next.foot_l.position =
226                Vec3::new(-s_a.foot.0, s_a.foot.1 + movement1abs * -7.0, s_a.foot.2);
227            next.foot_l.orientation = Quaternion::rotation_x(movement1abs * -1.2)
228                * Quaternion::rotation_z(movement1 * 0.8);
229
230            next.foot_r.position = Vec3::new(
231                s_a.foot.0 + movement1 * -5.0,
232                s_a.foot.1 + movement1abs * 3.0,
233                s_a.foot.2,
234            );
235            next.foot_r.orientation = Quaternion::rotation_z(movement1 * 0.6);
236        } else {
237            next.hand_l.position = Vec3::new(
238                -s_a.hand.0 + movement1abs * 9.0,
239                s_a.hand.1 + movement1abs * 9.0,
240                s_a.hand.2 + movement1abs * 5.0,
241            );
242            next.hand_l.orientation = Quaternion::rotation_x(movement1abs * 1.2)
243                * Quaternion::rotation_y(movement1 * 1.5);
244            next.hand_r.position = Vec3::new(
245                s_a.hand.0,
246                s_a.hand.1 + movement1abs * 3.0,
247                s_a.hand.2 + movement1abs * -1.0,
248            );
249            next.hand_r.orientation = Quaternion::rotation_x(movement1abs * 0.5)
250                * Quaternion::rotation_y(movement1 * 0.3);
251            next.foot_r.position =
252                Vec3::new(s_a.foot.0, s_a.foot.1 + movement1abs * -7.0, s_a.foot.2);
253            next.foot_r.orientation = Quaternion::rotation_x(movement1abs * -1.2)
254                * Quaternion::rotation_z(movement1 * 0.8);
255            next.foot_l.position = Vec3::new(
256                -s_a.foot.0 + movement1 * -5.0,
257                s_a.foot.1 + movement1abs * 3.0,
258                s_a.foot.2,
259            );
260            next.foot_l.orientation = Quaternion::rotation_z(movement1 * 0.6);
261        };
262        next.torso.position = Vec3::new(0.0, 0.0, 0.0);
263        next.torso.orientation = Quaternion::rotation_z(0.0);
264
265        if let (None, Some(Hands::Two)) = hands {
266            next.second = next.main;
267        }
268
269        next
270    }
271}