veloren_voxygen_anim/biped_small/
alpha.rs1use 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", unsafe(export_name = "biped_small_alpha"))]
33 fn update_skeleton_inner(
34 skeleton: &Self::Skeleton,
35 (
36 ability_id,
37 active_tool_kind,
38 velocity,
39 _orientation,
40 _last_ori,
41 global_time,
42 _avg_vel,
43 acc_vel,
44 stage_section,
45 timer,
46 ): Self::Dependency<'_>,
47 anim_time: f32,
48 _rate: &mut f32,
49 s_a: &SkeletonAttr,
50 ) -> Self::Skeleton {
51 let mut next = (*skeleton).clone();
52 let speed = Vec2::<f32>::from(velocity).magnitude();
53 let speednorm = speed / 9.4;
54 let speednormcancel = 1.0 - speednorm;
55
56 let anim_time = anim_time.min(1.0);
57 let (move1base, move2base, move3) = match stage_section {
58 Some(StageSection::Buildup) => (anim_time.sqrt(), 0.0, 0.0),
59 Some(StageSection::Action) => (1.0, anim_time.powi(4), 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 subtract = global_time - timer;
65 let check = subtract - subtract.trunc();
66 let mirror = (check - 0.5).signum();
67 let move1 = move1base * pullback * mirror;
68 let move2 = move2base * pullback * mirror;
69 let move1abs = move1base * pullback;
70 let move2abs = move2base * pullback;
71
72 init_biped_small_alpha(&mut next, s_a);
73
74 match active_tool_kind {
75 Some(ToolKind::Spear) => {
76 biped_small_alpha_spear(
77 &mut next,
78 s_a,
79 move1abs,
80 move2abs,
81 anim_time,
82 speednormcancel,
83 );
84 },
85 Some(ToolKind::Axe | ToolKind::Hammer | ToolKind::Pick | ToolKind::Shovel) => {
86 biped_small_alpha_axe(&mut next, s_a, move1abs, move2abs);
87 },
88 Some(ToolKind::Dagger) => {
89 biped_small_alpha_dagger(&mut next, s_a, move1abs, move2abs);
90 },
91 Some(ToolKind::Sword) => {
92 let slow = (anim_time * 2.0).sin();
93 biped_small_wield_sword(&mut next, s_a, speednorm, slow);
94
95 next.chest.orientation.rotate_z(1.2 * move1abs);
96 next.head.orientation.rotate_z(-0.6 * move1abs);
97 next.pants.orientation.rotate_z(-0.6 * move1abs);
98 next.control.orientation.rotate_x(0.8 * move1abs);
99 next.control.orientation.rotate_y(-0.4 * move1abs);
100
101 next.chest.orientation.rotate_z(-3.0 * move2abs);
102 next.head.orientation.rotate_z(1.5 * move2abs);
103 next.pants.orientation.rotate_z(2.0 * move2abs);
104 next.control.orientation.rotate_x(-3.0 * move2abs);
105 },
106 Some(ToolKind::Staff) => match ability_id {
107 Some("common.abilities.custom.dwarves.flamekeeper.flamecrush") => {
108 next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
109 next.control_r.position = Vec3::new(12.0 + s_a.grip.0 * 2.0, -4.0, 3.0);
110
111 next.control.position = Vec3::new(
112 -9.0 + move1 * 5.0 + move2 * -5.0,
113 2.0 + s_a.grip.2,
114 -2.0 + -s_a.grip.2 / 2.5
115 + s_a.grip.0 * -2.0
116 + move1abs * 6.0
117 + move2abs * -3.0,
118 );
119
120 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
121 * Quaternion::rotation_y(-0.3)
122 * Quaternion::rotation_z(-0.3);
123 next.control_r.orientation =
124 Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
125 * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2)
126 * Quaternion::rotation_z(-0.0);
127
128 next.control.orientation =
129 Quaternion::rotation_x(-0.3 + move1abs * 1.0 + move2abs * -2.0)
130 * Quaternion::rotation_y(0.0)
131 * Quaternion::rotation_z(0.5);
132 next.chest.orientation =
133 Quaternion::rotation_x(move1abs * 0.5 + move2abs * -1.0)
134 * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
135 next.head.orientation = Quaternion::rotation_z(move1 * -0.8 + move2 * 0.8);
136 },
137 _ => {
138 next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
139 next.control_r.position = Vec3::new(7.0 + s_a.grip.0 * 2.0, -4.0, 3.0);
140
141 next.control.position = Vec3::new(
142 -5.0 + move1 * 5.0 + move2 * -5.0,
143 -1.0 + s_a.grip.2,
144 -2.0 + -s_a.grip.2 / 2.5
145 + s_a.grip.0 * -2.0
146 + move1abs * 6.0
147 + move2abs * -3.0,
148 );
149
150 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
151 * Quaternion::rotation_y(-0.3)
152 * Quaternion::rotation_z(-0.3);
153 next.control_r.orientation =
154 Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
155 * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2)
156 * Quaternion::rotation_z(-0.0);
157
158 next.control.orientation =
159 Quaternion::rotation_x(-0.3 + move1abs * 1.0 + move2abs * -2.0)
160 * Quaternion::rotation_y(0.0)
161 * Quaternion::rotation_z(0.5);
162 next.chest.orientation =
163 Quaternion::rotation_x(move1abs * 0.5 + move2abs * -1.0)
164 * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
165 next.head.orientation = Quaternion::rotation_z(move1 * -0.8 + move2 * 0.8);
166 },
167 },
168 Some(ToolKind::Bow) => match ability_id {
169 Some("common.abilities.haniwa.archer.kick") => {
170 let fastacc = (acc_vel * 2.0).sin();
171 biped_small_wield_bow(&mut next, s_a, anim_time, speed, fastacc);
172
173 next.chest.orientation.rotate_z(move1abs * 1.1);
174 next.control.orientation.rotate_z(move1abs * -0.9);
175 next.control.position += Vec3::new(7.0, 1.0, 0.0) * move1abs;
176 next.head.orientation.rotate_z(move1abs * -0.8);
177 next.foot_l.orientation.rotate_z(move1abs * 1.1);
178
179 next.chest.orientation.rotate_z(move2abs * -2.3);
180 next.control.orientation.rotate_z(move2abs * 1.9);
181 next.control.position += Vec3::new(-7.0, -1.0, 0.0) * move2abs;
182 next.head.orientation.rotate_z(move2abs * 0.9);
183 next.foot_l.orientation.rotate_y(move2abs * 1.3);
184 next.foot_l.orientation.rotate_z(move2abs * -2.9);
185 next.foot_l.position += Vec3::new(3.0, 8.0, 4.0) * move2abs;
186 },
187 _ => {},
188 },
189 Some(ToolKind::Natural) => {
190 let tension = match stage_section {
191 Some(StageSection::Buildup) => (anim_time * 10.0).sin(),
192 Some(StageSection::Action) => 1.0,
193 Some(StageSection::Recover) => 1.0,
194 _ => 0.0,
195 };
196 next.chest.orientation =
197 Quaternion::rotation_x(move1abs * 1.0 + move2abs * -1.5 + tension * 0.2);
198 next.pants.orientation = Quaternion::rotation_x(move1abs * -0.5 + move2abs * 0.5);
199 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
200 next.hand_l.orientation =
201 Quaternion::rotation_x(1.2 + move1abs * 1.5 + move2abs * -1.0)
202 * Quaternion::rotation_y(tension * 0.5);
203 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
204 next.hand_r.orientation =
205 Quaternion::rotation_x(1.2 + move1abs * 1.5 + move2abs * -1.0)
206 * Quaternion::rotation_y(tension * -0.5);
207 },
208 _ => {
209 next.chest.orientation = Quaternion::rotation_x(move2abs * -1.0)
210 * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
211 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
212 next.hand_l.orientation = Quaternion::rotation_x(1.2);
213 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
214 next.hand_r.orientation = Quaternion::rotation_x(1.2);
215 },
216 }
217 next
218 }
219}