veloren_voxygen_anim/biped_small/
shockwave.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 ShockwaveAnimation;
9
10type ShockwaveAnimationDependency = (
11    Option<ToolKind>,
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 ShockwaveAnimation {
24    type Dependency<'a> = ShockwaveAnimationDependency;
25    type Skeleton = BipedSmallSkeleton;
26
27    #[cfg(feature = "use-dyn-lib")]
28    const UPDATE_FN: &'static [u8] = b"biped_small_shockwave\0";
29
30    #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "biped_small_shockwave"))]
31    fn update_skeleton_inner(
32        skeleton: &Self::Skeleton,
33        (
34            active_tool_kind,
35            second_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, move2base, move3) = match stage_section {
53            Some(StageSection::Buildup) => (anim_time.sqrt(), (anim_time * 13.0).sin(), 0.0, 0.0),
54            Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(4), 0.0),
55            Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time),
56            _ => (0.0, 0.0, 0.0, 0.0),
57        };
58        let pullback = 1.0 - move3;
59        let twitch = twitch * pullback;
60        let subtract = global_time - timer;
61        let check = subtract - subtract.trunc();
62        let mirror = (check - 0.5).signum();
63        let move1 = move1base * pullback * mirror;
64        let move2 = move2base * pullback * mirror;
65        let move1abs = move1base * pullback;
66        let move2abs = move2base * pullback;
67        next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
68        next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
69        next.main.position = Vec3::new(0.0, 0.0, 0.0);
70        next.main.orientation = Quaternion::rotation_x(0.0);
71        next.second.position = Vec3::new(0.0, 0.0, 0.0);
72        next.second.orientation = Quaternion::rotation_x(0.0);
73        next.hand_l.orientation = Quaternion::rotation_x(0.0);
74        next.hand_r.orientation = Quaternion::rotation_x(0.0);
75        match (active_tool_kind, second_tool_kind) {
76            (Some(ToolKind::Staff), None) => {
77                next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
78                next.control_r.position = Vec3::new(
79                    7.0 + s_a.grip.0 * 2.0 + move1abs * -8.0,
80                    -4.0 + move1abs * 5.0,
81                    3.0,
82                );
83
84                next.control.position = Vec3::new(
85                    -5.0 + move1abs * 5.0,
86                    -1.0 + s_a.grip.2 + move1abs * 3.0 + move2abs * 5.0,
87                    -2.0 + -s_a.grip.2 / 2.5
88                        + s_a.grip.0 * -2.0
89                        + move1abs * 12.0
90                        + move2abs * -13.0,
91                );
92
93                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
94                    * Quaternion::rotation_y(-0.3)
95                    * Quaternion::rotation_z(-0.3);
96                next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
97                    * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2)
98                    * Quaternion::rotation_z(-0.0);
99
100                next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * 0.2)
101                    * Quaternion::rotation_y(0.0)
102                    * Quaternion::rotation_z(0.5);
103                next.chest.orientation = Quaternion::rotation_x(move1abs * 0.5 + move2abs * -1.0);
104                next.head.orientation =
105                    Quaternion::rotation_x(move1abs * 0.5) * Quaternion::rotation_y(twitch * 0.5);
106                next.main.orientation = Quaternion::rotation_z(move1abs * 0.5 + move2abs * 0.9);
107            },
108            (Some(ToolKind::Sword), None) => {
109                let rotate = move1 * 2.0 * PI + move2 * 2.0 * PI;
110                let jump = move1 + 3.0 + move2 * -3.0;
111                next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
112                next.control_r.position = Vec3::new(
113                    7.0 + s_a.grip.0 * 2.0 + move1abs * -8.0,
114                    -4.0 + move1abs * 5.0,
115                    3.0,
116                );
117
118                next.control.position = Vec3::new(
119                    -5.0 + move1abs * 5.0,
120                    -1.0 + s_a.grip.2 + move1abs * 3.0 + move2abs * 5.0,
121                    -2.0 + -s_a.grip.2 / 2.5
122                        + s_a.grip.0 * -2.0
123                        + move1abs * 12.0
124                        + move2abs * -13.0,
125                );
126
127                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
128                    * Quaternion::rotation_y(-0.3)
129                    * Quaternion::rotation_z(-0.3);
130                next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
131                    * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2)
132                    * Quaternion::rotation_z(-0.0);
133
134                next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * 0.2)
135                    * Quaternion::rotation_y(0.0)
136                    * Quaternion::rotation_z(0.5);
137                next.chest.orientation = Quaternion::rotation_x(move1abs * 0.5 + move2abs * -1.0);
138                next.head.orientation =
139                    Quaternion::rotation_x(move1abs * 0.5) * Quaternion::rotation_y(twitch * 0.5);
140                next.main.orientation = Quaternion::rotation_z(move1abs * 0.5 + move2abs * 0.9);
141                next.chest.orientation = Quaternion::rotation_z(rotate + (1.0 - move3));
142
143                next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + jump);
144            },
145            (Some(ToolKind::Axe), Some(ToolKind::Axe)) => {
146                next.main.position =
147                    Vec3::new(-s_a.hand.0 - 4.0, s_a.hand.1 + 2.0, s_a.hand.2 - 4.0);
148                next.main.orientation = Quaternion::rotation_x(-0.2);
149                next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
150                next.hand_l.orientation = Quaternion::rotation_x(1.2);
151                next.second.position =
152                    Vec3::new(s_a.hand.0 + 4.0, s_a.hand.1 + 2.0, s_a.hand.2 - 4.0);
153                next.second.orientation = Quaternion::rotation_x(-0.2);
154                next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
155                next.hand_r.orientation = Quaternion::rotation_x(1.2);
156
157                next.chest.orientation = Quaternion::rotation_x(move2abs * -1.0)
158                    * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
159
160                if mirror > 0.0 {
161                    next.control_r.position += Vec3::new(-5.0, 0.0, 5.0) * move1abs;
162                    next.control_r.orientation.rotate_x(PI / 10.0 * move1abs);
163                    next.control_l.position += Vec3::new(3.0, 0.0, 10.0) * move1abs;
164                    next.main.position += Vec3::new(3.0, 0.0, 10.0) * move1abs;
165                    next.control_l.orientation.rotate_x(PI / 4.0 * move1abs);
166                    next.main.orientation.rotate_x(PI / 4.0 * move1abs);
167
168                    next.control_r.position += Vec3::new(0.0, 0.0, -5.0) * move2abs;
169                    next.control_r.orientation.rotate_x(-PI / 4.0 * move2abs);
170                    next.control_l.position += Vec3::new(0.0, 0.0, -10.0) * move2abs;
171                    next.main.position += Vec3::new(0.0, 0.0, -10.0) * move2abs;
172                    next.control_l.orientation.rotate_x(-PI / 4.0 * move2abs);
173                    next.main.orientation.rotate_x(-PI / 4.0 * move2abs);
174                } else {
175                    next.control_l.position += Vec3::new(5.0, 0.0, 5.0) * move1abs;
176                    next.main.position += Vec3::new(3.0, 0.0, 5.0) * move1abs;
177                    next.control_l.orientation.rotate_x(PI / 10.0 * move1abs);
178                    next.main.orientation.rotate_x(PI / 10.0 * move1abs);
179                    next.control_r.position += Vec3::new(-3.0, 0.0, 10.0) * move1abs;
180                    next.control_r.orientation.rotate_x(PI / 4.0 * move1abs);
181
182                    next.control_l.position += Vec3::new(0.0, 0.0, -5.0) * move2abs;
183                    next.main.position += Vec3::new(0.0, 0.0, -5.0) * move2abs;
184                    next.control_l.orientation.rotate_x(-PI / 4.0 * move2abs);
185                    next.main.orientation.rotate_x(-PI / 4.0 * move2abs);
186                    next.control_r.position += Vec3::new(0.0, 0.0, -10.0) * move2abs;
187                    next.control_r.orientation.rotate_x(-PI / 4.0 * move2abs);
188                }
189            },
190            _ => {
191                next.chest.orientation = Quaternion::rotation_x(move2abs * -1.0)
192                    * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
193                next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
194                next.hand_l.orientation = Quaternion::rotation_x(1.2);
195                next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
196                next.hand_r.orientation = Quaternion::rotation_x(1.2);
197            },
198        }
199        next
200    }
201}