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