veloren_voxygen_anim/biped_small/
wield.rs1use super::{
2 super::{Animation, vek::*},
3 BipedSmallSkeleton, SkeletonAttr, biped_small_wield_bow, biped_small_wield_spear,
4 biped_small_wield_sword,
5};
6use common::comp::item::tool::{AbilitySpec, ToolKind};
7use std::f32::consts::PI;
8
9pub struct WieldAnimation;
10
11type WieldAnimationDependency<'a> = (
12 (Option<ToolKind>, Option<&'a AbilitySpec>),
13 Option<ToolKind>,
14 Vec3<f32>,
15 Vec3<f32>,
16 Vec3<f32>,
17 f32,
18 Vec3<f32>,
19 f32,
20);
21
22impl Animation for WieldAnimation {
23 type Dependency<'a> = WieldAnimationDependency<'a>;
24 type Skeleton = BipedSmallSkeleton;
25
26 #[cfg(feature = "use-dyn-lib")]
27 const UPDATE_FN: &'static [u8] = b"biped_small_wield\0";
28
29 #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "biped_small_wield"))]
30 fn update_skeleton_inner(
31 skeleton: &Self::Skeleton,
32 (
33 (active_tool_kind, active_tool_spec),
34 second_tool_kind,
35 velocity,
36 _orientation,
37 _last_ori,
38 _global_time,
39 _avg_vel,
40 acc_vel,
41 ): Self::Dependency<'_>,
42 anim_time: f32,
43 _rate: &mut f32,
44 s_a: &SkeletonAttr,
45 ) -> Self::Skeleton {
46 let mut next = (*skeleton).clone();
47 let speed = Vec2::<f32>::from(velocity).magnitude();
48
49 let fastacc = (acc_vel * 2.0).sin();
50 let fast = (anim_time * 10.0).sin();
51 let fastalt = (anim_time * 10.0 + PI / 2.0).sin();
52 let slow = (anim_time * 2.0).sin();
53
54 let speednorm = speed / 9.4;
55 let speednormcancel = 1.0 - speednorm;
56
57 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + fast * -0.1 * speednormcancel);
58 next.head.orientation = Quaternion::rotation_x(0.45 * speednorm)
59 * Quaternion::rotation_y(fast * 0.07 * speednormcancel);
60 next.chest.position = Vec3::new(
61 0.0,
62 s_a.chest.0,
63 s_a.chest.1 + fastalt * 0.4 * speednormcancel + speednormcancel * -0.5,
64 );
65
66 next.pants.position = Vec3::new(0.0, s_a.pants.0, s_a.pants.1);
67
68 next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
69 next.tail.orientation = Quaternion::rotation_x(0.05 * fastalt * speednormcancel)
70 * Quaternion::rotation_z(fast * 0.15 * speednormcancel);
71
72 next.main.position = Vec3::new(0.0, 0.0, 0.0);
73 next.main.orientation = Quaternion::rotation_z(0.0);
74 next.second.position = Vec3::new(0.0, 0.0, 0.0);
75 next.second.orientation = Quaternion::rotation_z(0.0);
76
77 next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
78 next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
79
80 next.hand_l.orientation = Quaternion::rotation_x(0.0);
81 next.hand_r.orientation = Quaternion::rotation_x(0.0);
82
83 match active_tool_kind {
88 Some(ToolKind::Spear) => {
89 biped_small_wield_spear(&mut next, s_a, anim_time, speed, fastacc);
90 },
91 Some(ToolKind::Blowgun) => {
92 next.control_l.position = Vec3::new(1.0 - s_a.grip.0 * 2.0, 0.0, 3.0);
93 next.control_r.position = Vec3::new(-1.0 + s_a.grip.0 * 2.0, 0.0, 4.0);
94
95 next.control.position = Vec3::new(
96 0.0,
97 s_a.grip.2,
98 4.0 - s_a.grip.2 / 2.5
99 + s_a.grip.0 * -2.0
100 + fastacc * 0.5
101 + fastalt * 0.1 * speednormcancel
102 + speednorm * 4.0,
103 );
104
105 next.control_l.orientation =
106 Quaternion::rotation_x(3.8 + slow * 0.1) * Quaternion::rotation_y(-0.3);
107 next.control_r.orientation =
108 Quaternion::rotation_x(3.5 + slow * 0.1 + s_a.grip.0 * 0.2)
109 * Quaternion::rotation_y(0.5 + slow * 0.0 + s_a.grip.0 * 0.2);
110
111 next.control.orientation = Quaternion::rotation_x(-2.2 + 0.5 * speednorm);
112 },
113 Some(ToolKind::Bow) => {
114 biped_small_wield_bow(&mut next, s_a, anim_time, speed, fastacc);
115 },
116 Some(ToolKind::Staff) => {
117 next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
118 next.control_r.position =
119 Vec3::new(7.0 + s_a.grip.0 * 2.0, -4.0, 3.0 + speednorm * -3.0);
120
121 next.control.position = Vec3::new(
122 -5.0,
123 -1.0 + s_a.grip.2,
124 -2.0 + -s_a.grip.2 / 2.5
125 + s_a.grip.0 * -2.0
126 + fastacc * 1.5
127 + fastalt * 0.5 * speednormcancel
128 + speednorm * 2.0,
129 );
130
131 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + slow * 0.1)
132 * Quaternion::rotation_y(-0.3)
133 * Quaternion::rotation_z(-0.3);
134 next.control_r.orientation =
135 Quaternion::rotation_x(PI / 2.0 + slow * 0.1 + s_a.grip.0 * 0.2)
136 * Quaternion::rotation_y(-0.4 + slow * 0.0 + s_a.grip.0 * 0.2)
137 * Quaternion::rotation_z(-0.0);
138
139 next.control.orientation = Quaternion::rotation_x(-0.3 + 0.2 * speednorm)
140 * Quaternion::rotation_y(-0.2 * speednorm)
141 * Quaternion::rotation_z(0.5);
142 },
143 Some(ToolKind::Axe | ToolKind::Hammer | ToolKind::Pick) => {
144 next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
145 next.control_r.position =
146 Vec3::new(9.0 + s_a.grip.0 * 2.0, -1.0, -2.0 + speednorm * -3.0);
147
148 next.control.position = Vec3::new(
149 -5.0,
150 -1.0 + s_a.grip.2,
151 -1.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + speednorm * 2.0,
152 );
153
154 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + slow * 0.1)
155 * Quaternion::rotation_y(-0.0)
156 * Quaternion::rotation_z(-0.0);
157 next.control_r.orientation =
158 Quaternion::rotation_x(0.5 + slow * 0.1 + s_a.grip.0 * 0.2)
159 * Quaternion::rotation_y(0.2 + slow * 0.0 + s_a.grip.0 * 0.2)
160 * Quaternion::rotation_z(-0.0);
161
162 next.control.orientation = Quaternion::rotation_x(-0.3 + 0.2 * speednorm)
163 * Quaternion::rotation_y(-0.2 * speednorm)
164 * Quaternion::rotation_z(-0.3);
165
166 if let Some(AbilitySpec::Custom(spec)) = active_tool_spec
167 && spec.as_str() == "Ashen Axe"
168 {
169 next.main.position += Vec3::new(-4.0, -2.5, 0.0);
170 }
171 },
172 Some(ToolKind::Dagger | ToolKind::Sword) => {
173 biped_small_wield_sword(&mut next, s_a, speednorm, slow);
174 },
175 Some(ToolKind::Natural) => {
176 if let Some(AbilitySpec::Custom(spec)) = active_tool_spec {
177 match spec.as_str() {
178 "ShamanicSpirit" => {
179 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
180 next.hand_l.orientation = Quaternion::rotation_x(1.2);
181 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
182 next.hand_r.orientation = Quaternion::rotation_x(1.2);
183 next.main.position = Vec3::new(0.0, 12.0, 5.0);
184 },
185 _ => {
186 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
187 next.hand_l.orientation = Quaternion::rotation_x(1.2);
188 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
189 next.hand_r.orientation = Quaternion::rotation_x(1.2);
190 },
191 }
192 }
193 },
194 _ => {
195 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
196 next.hand_l.orientation = Quaternion::rotation_x(1.2);
197 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
198 next.hand_r.orientation = Quaternion::rotation_x(1.2);
199 },
200 }
201
202 match second_tool_kind {
203 Some(ToolKind::Axe) => {
204 next.control.position += Vec3::new(1.0, 0.0, 0.0);
205 next.control.orientation = Quaternion::rotation_x(0.0)
206 * Quaternion::rotation_y(0.0)
207 * Quaternion::rotation_z(0.0);
208
209 next.control_r.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
210 next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 - slow * 0.1)
211 * Quaternion::rotation_y(0.0)
212 * Quaternion::rotation_z(0.0);
213
214 next.second.position += Vec3::new(8.0, -2.5, 4.0);
215 next.second.orientation = Quaternion::rotation_x(-PI / 2.0)
216 * Quaternion::rotation_y(0.0)
217 * Quaternion::rotation_z(0.0);
218 },
219 _ => {},
220 }
221
222 next
223 }
224}