1pub mod basic;
2pub mod idle;
3pub mod jump;
4pub mod multi;
5pub mod run;
6pub mod stunned;
7
8pub use self::{
10 basic::{BasicAction, BasicActionDependency},
11 idle::IdleAnimation,
12 jump::JumpAnimation,
13 multi::{MultiAction, MultiActionDependency},
14 run::RunAnimation,
15 stunned::StunnedAnimation,
16};
17
18use super::{FigureBoneData, Skeleton, vek::*};
19use common::comp::{self};
20use core::convert::TryFrom;
21
22pub type Body = comp::arthropod::Body;
23
24skeleton_impls!(struct ArthropodSkeleton ComputedArthropodSkeleton {
25 + head
26 + chest
27 + mandible_l
28 + mandible_r
29 + wing_fl
30 + wing_fr
31 + wing_bl
32 + wing_br
33 + leg_fl
34 + leg_fr
35 + leg_fcl
36 + leg_fcr
37 + leg_bcl
38 + leg_bcr
39 + leg_bl
40 + leg_br
41});
42
43impl Skeleton for ArthropodSkeleton {
44 type Attr = SkeletonAttr;
45 type Body = Body;
46 type ComputedSkeleton = ComputedArthropodSkeleton;
47
48 const BONE_COUNT: usize = ComputedArthropodSkeleton::BONE_COUNT;
49 #[cfg(feature = "use-dyn-lib")]
50 const COMPUTE_FN: &'static [u8] = b"arthropod_compute_s\0";
51
52 #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "arthropod_compute_s"))]
53
54 fn compute_matrices_inner(
55 &self,
56 base_mat: Mat4<f32>,
57 buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
58 body: Self::Body,
59 ) -> Self::ComputedSkeleton {
60 let base_mat = base_mat * Mat4::scaling_3d(SkeletonAttr::from(&body).scaler / 6.0);
61
62 let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
63 let head_mat = chest_mat * Mat4::<f32>::from(self.head);
64 let mandible_l_mat = head_mat * Mat4::<f32>::from(self.mandible_l);
65 let mandible_r_mat = head_mat * Mat4::<f32>::from(self.mandible_r);
66 let wing_fl_mat = chest_mat * Mat4::<f32>::from(self.wing_fl);
67 let wing_fr_mat = chest_mat * Mat4::<f32>::from(self.wing_fr);
68 let wing_bl_mat = chest_mat * Mat4::<f32>::from(self.wing_bl);
69 let wing_br_mat = chest_mat * Mat4::<f32>::from(self.wing_br);
70 let leg_fl_mat = chest_mat * Mat4::<f32>::from(self.leg_fl);
71 let leg_fr_mat = chest_mat * Mat4::<f32>::from(self.leg_fr);
72 let leg_fcl_mat = chest_mat * Mat4::<f32>::from(self.leg_fcl);
73 let leg_fcr_mat = chest_mat * Mat4::<f32>::from(self.leg_fcr);
74 let leg_bcl_mat = chest_mat * Mat4::<f32>::from(self.leg_bcl);
75 let leg_bcr_mat = chest_mat * Mat4::<f32>::from(self.leg_bcr);
76 let leg_bl_mat = chest_mat * Mat4::<f32>::from(self.leg_bl);
77 let leg_br_mat = chest_mat * Mat4::<f32>::from(self.leg_br);
78
79 let computed_skeleton = ComputedArthropodSkeleton {
80 head: head_mat,
81 chest: chest_mat,
82 mandible_l: mandible_l_mat,
83 mandible_r: mandible_r_mat,
84 wing_fl: wing_fl_mat,
85 wing_fr: wing_fr_mat,
86 wing_bl: wing_bl_mat,
87 wing_br: wing_br_mat,
88 leg_fl: leg_fl_mat,
89 leg_fr: leg_fr_mat,
90 leg_fcl: leg_fcl_mat,
91 leg_fcr: leg_fcr_mat,
92 leg_bcl: leg_bcl_mat,
93 leg_bcr: leg_bcr_mat,
94 leg_bl: leg_bl_mat,
95 leg_br: leg_br_mat,
96 };
97
98 computed_skeleton.set_figure_bone_data(buf);
99 computed_skeleton
100 }
101}
102
103pub struct SkeletonAttr {
104 head: (f32, f32),
105 chest: (f32, f32),
106 mandible: (f32, f32, f32),
107 wing_f: (f32, f32, f32),
108 wing_b: (f32, f32, f32),
109 leg_f: (f32, f32, f32),
110 leg_fc: (f32, f32, f32),
111 leg_bc: (f32, f32, f32),
112 leg_b: (f32, f32, f32),
113 scaler: f32,
114 leg_ori: (f32, f32, f32, f32),
115 snapper: bool,
116}
117
118impl<'a> TryFrom<&'a comp::Body> for SkeletonAttr {
119 type Error = ();
120
121 fn try_from(body: &'a comp::Body) -> Result<Self, Self::Error> {
122 match body {
123 comp::Body::Arthropod(body) => Ok(SkeletonAttr::from(body)),
124 _ => Err(()),
125 }
126 }
127}
128
129impl Default for SkeletonAttr {
130 fn default() -> Self {
131 Self {
132 head: (0.0, 0.0),
133 chest: (0.0, 0.0),
134 mandible: (0.0, 0.0, 0.0),
135 wing_f: (0.0, 0.0, 0.0),
136 wing_b: (0.0, 0.0, 0.0),
137 leg_f: (0.0, 0.0, 0.0),
138 leg_fc: (0.0, 0.0, 0.0),
139 leg_bc: (0.0, 0.0, 0.0),
140 leg_b: (0.0, 0.0, 0.0),
141 scaler: 0.0,
142 leg_ori: (0.0, 0.0, 0.0, 0.0),
143 snapper: false,
144 }
145 }
146}
147
148impl<'a> From<&'a Body> for SkeletonAttr {
149 fn from(body: &'a Body) -> Self {
150 use comp::arthropod::Species::*;
151 Self {
152 head: match (body.species, body.body_type) {
153 (Tarantula, _) => (6.0, 0.5),
154 (Blackwidow, _) => (5.5, -3.0),
155 (Antlion, _) => (4.5, 0.0),
156 (Hornbeetle, _) => (5.0, 3.0),
157 (Leafbeetle, _) => (4.0, 0.0),
158 (Stagbeetle, _) => (5.0, -1.0),
159 (Weevil, _) => (4.0, 0.0),
160 (Cavespider, _) => (6.0, 0.5),
161 (Moltencrawler, _) => (4.0, -1.0),
162 (Mosscrawler, _) => (4.0, -1.5),
163 (Sandcrawler, _) => (4.0, -1.0),
164 (Dagonite, _) => (4.0, -1.0),
165 (Emberfly, _) => (-1.5, 0.5),
166 },
167 chest: match (body.species, body.body_type) {
168 (Tarantula, _) => (-5.0, 6.0),
169 (Blackwidow, _) => (-5.0, 10.0),
170 (Antlion, _) => (-5.0, 8.5),
171 (Hornbeetle, _) => (-5.0, 7.5),
172 (Leafbeetle, _) => (-5.0, 6.0),
173 (Stagbeetle, _) => (-5.0, 6.5),
174 (Weevil, _) => (-5.0, 6.0),
175 (Cavespider, _) => (-5.0, 7.0),
176 (Moltencrawler, _) => (-7.0, 6.0),
177 (Mosscrawler, _) => (-7.0, 6.5),
178 (Sandcrawler, _) => (-7.0, 6.0),
179 (Dagonite, _) => (-6.0, 8.0),
180 (Emberfly, _) => (-5.0, 2.5),
181 },
182 mandible: match (body.species, body.body_type) {
183 (Tarantula, _) => (1.5, 7.0, -0.5),
184 (Blackwidow, _) => (2.5, 8.0, 0.0),
185 (Antlion, _) => (8.5, 9.0, -3.5),
186 (Hornbeetle, _) => (1.5, 7.0, -0.5),
187 (Leafbeetle, _) => (1.5, 7.0, -0.5),
188 (Stagbeetle, _) => (1.5, 10.0, 1.0),
189 (Weevil, _) => (1.5, 7.0, -0.5),
190 (Cavespider, _) => (2.5, 8.0, -0.5),
191 (Moltencrawler, _) => (2.5, 8.0, 0.0),
192 (Mosscrawler, _) => (2.5, 8.0, 0.0),
193 (Sandcrawler, _) => (2.5, 8.0, 0.0),
194 (Dagonite, _) => (2.5, 8.0, 0.0),
195 (Emberfly, _) => (1.5, 7.0, -0.5),
196 },
197 wing_f: match (body.species, body.body_type) {
198 (Tarantula, _) => (3.0, 0.0, -4.0),
199 (Blackwidow, _) => (3.0, 0.0, -4.0),
200 (Antlion, _) => (3.0, 0.0, -4.0),
201 (Hornbeetle, _) => (5.5, 5.0, 3.0),
202 (Leafbeetle, _) => (0.5, 5.0, 3.0),
203 (Stagbeetle, _) => (0.5, 6.0, 4.5),
204 (Weevil, _) => (0.5, 5.0, 3.0),
205 (Cavespider, _) => (3.0, 0.0, -4.0),
206 (Moltencrawler, _) => (3.0, 0.0, -4.0),
207 (Mosscrawler, _) => (3.0, 0.0, -4.0),
208 (Sandcrawler, _) => (3.0, 0.0, -4.0),
209 (Dagonite, _) => (3.0, 0.0, -4.0),
210 (Emberfly, _) => (5.5, 6.0, 3.0),
211 },
212 wing_b: match (body.species, body.body_type) {
213 (Tarantula, _) => (3.0, 0.0, -4.0),
214 (Blackwidow, _) => (3.0, 0.0, -4.0),
215 (Antlion, _) => (3.0, 0.0, -4.0),
216 (Hornbeetle, _) => (4.0, 6.0, 2.0),
217 (Leafbeetle, _) => (0.5, 4.0, 2.0),
218 (Stagbeetle, _) => (0.5, 6.0, 3.0),
219 (Weevil, _) => (0.5, 4.0, 1.5),
220 (Cavespider, _) => (3.0, 0.0, -4.0),
221 (Moltencrawler, _) => (3.0, 0.0, -4.0),
222 (Mosscrawler, _) => (3.0, 0.0, -4.0),
223 (Sandcrawler, _) => (3.0, 0.0, -4.0),
224 (Dagonite, _) => (3.0, 0.0, -4.0),
225 (Emberfly, _) => (4.0, 6.0, 2.0),
226 },
227 leg_f: match (body.species, body.body_type) {
228 (Tarantula, _) => (4.0, 11.0, -1.5),
229 (Blackwidow, _) => (4.0, 13.5, -6.0),
230 (Antlion, _) => (4.0, 11.5, -4.0),
231 (Hornbeetle, _) => (5.0, 6.0, -3.0),
232 (Leafbeetle, _) => (5.0, 6.0, -1.0),
233 (Stagbeetle, _) => (4.5, 6.0, -2.0),
234 (Weevil, _) => (5.0, 9.0, -2.0),
235 (Cavespider, _) => (4.0, 13.0, -3.0),
236 (Moltencrawler, _) => (2.5, 14.0, -3.0),
237 (Mosscrawler, _) => (1.5, 14.0, -3.5),
238 (Sandcrawler, _) => (1.5, 14.0, -3.0),
239 (Dagonite, _) => (1.5, 14.0, -3.0),
240 (Emberfly, _) => (2.5, 6.0, -2.5),
241 },
242 leg_fc: match (body.species, body.body_type) {
243 (Tarantula, _) => (1.5, 13.5, -1.5),
244 (Blackwidow, _) => (2.5, 13.0, -5.5),
245 (Antlion, _) => (1.5, 6.0, -4.0),
246 (Hornbeetle, _) => (1.5, 7.5, -3.0),
247 (Leafbeetle, _) => (1.5, 6.5, -1.5),
248 (Stagbeetle, _) => (1.5, 7.5, -2.0),
249 (Weevil, _) => (1.5, 8.5, -2.0),
250 (Cavespider, _) => (2.5, 12.5, -2.5),
251 (Moltencrawler, _) => (3.5, 11.0, -3.0),
252 (Mosscrawler, _) => (2.5, 11.0, -3.5),
253 (Sandcrawler, _) => (2.5, 11.0, -3.0),
254 (Dagonite, _) => (2.5, 11.0, -3.0),
255 (Emberfly, _) => (1.5, 7.5, -2.5),
256 },
257 leg_bc: match (body.species, body.body_type) {
258 (Tarantula, _) => (1.5, 10.5, -1.5),
259 (Blackwidow, _) => (2.5, 10.0, -5.5),
260 (Antlion, _) => (6.0, 7.5, -4.0),
261 (Hornbeetle, _) => (5.0, 6.0, -3.0),
262 (Leafbeetle, _) => (4.5, 5.0, -2.5),
263 (Stagbeetle, _) => (5.0, 6.0, -2.0),
264 (Weevil, _) => (6.0, 5.0, -2.5),
265 (Cavespider, _) => (2.5, 9.5, -2.5),
266 (Moltencrawler, _) => (2.5, 8.0, -3.0),
267 (Mosscrawler, _) => (1.5, 8.0, -3.5),
268 (Sandcrawler, _) => (1.5, 8.0, -3.0),
269 (Dagonite, _) => (1.5, 8.0, -3.0),
270 (Emberfly, _) => (2.5, 3.5, -2.5),
271 },
272 leg_b: match (body.species, body.body_type) {
273 (Tarantula, _) => (1.5, 7.5, -1.5),
274 (Blackwidow, _) => (2.5, 7.0, -5.5),
275 (Antlion, _) => (1.5, 7.5, -1.5),
276 (Hornbeetle, _) => (1.5, 7.5, -1.5),
277 (Leafbeetle, _) => (1.5, 7.5, -1.5),
278 (Stagbeetle, _) => (1.5, 7.5, -1.5),
279 (Weevil, _) => (1.5, 7.5, -1.5),
280 (Cavespider, _) => (2.5, 6.5, -2.5),
281 (Moltencrawler, _) => (2.5, 7.0, -5.5),
282 (Mosscrawler, _) => (2.5, 7.0, -5.5),
283 (Sandcrawler, _) => (2.5, 7.0, -5.5),
284 (Dagonite, _) => (2.5, 7.0, -5.5),
285 (Emberfly, _) => (1.5, 7.5, -1.0),
286 },
287 scaler: match (body.species, body.body_type) {
288 (Tarantula, _) => 1.0,
289 (Blackwidow, _) => 1.0,
290 (Antlion, _) => 1.0,
291 (Hornbeetle, _) => 1.0,
292 (Leafbeetle, _) => 0.8,
293 (Stagbeetle, _) => 1.0,
294 (Weevil, _) => 0.75,
295 (Cavespider, _) => 1.0,
296 (Moltencrawler, _) => 1.0,
297 (Mosscrawler, _) => 1.0,
298 (Sandcrawler, _) => 1.0,
299 (Dagonite, _) => 1.0,
300 (Emberfly, _) => 0.5,
301 },
302 leg_ori: match (body.species, body.body_type) {
304 (Antlion, _) => (0.7, -0.3, -0.4, 0.4),
305 (_, _) => (0.1, -0.3, 0.0, 0.4),
306 },
307 snapper: match (body.species, body.body_type) {
309 (Stagbeetle, _) => true,
310 (Antlion, _) => true,
311 (_, _) => false,
312 },
313 }
314 }
315}
316
317pub fn mount_mat(
318 body: &Body,
319 computed_skeleton: &ComputedArthropodSkeleton,
320 skeleton: &ArthropodSkeleton,
321) -> (Mat4<f32>, Quaternion<f32>) {
322 use comp::arthropod::Species::*;
323
324 match (body.species, body.body_type) {
325 (
326 Hornbeetle | Leafbeetle | Stagbeetle | Weevil | Moltencrawler | Mosscrawler
327 | Sandcrawler | Dagonite,
328 _,
329 ) => (computed_skeleton.head, skeleton.head.orientation),
330 _ => (computed_skeleton.chest, skeleton.chest.orientation),
331 }
332}
333
334pub fn mount_transform(
335 body: &Body,
336 computed_skeleton: &ComputedArthropodSkeleton,
337 skeleton: &ArthropodSkeleton,
338) -> Transform<f32, f32, f32> {
339 use comp::arthropod::Species::*;
340
341 let mount_point = match (body.species, body.body_type) {
342 (Tarantula, _) => (0.0, 1.0, 4.0),
343 (Blackwidow, _) => (0.0, 0.0, 5.0),
344 (Antlion, _) => (0.0, 2.0, 3.5),
345 (Hornbeetle, _) => (0.0, 1.5, 1.5),
346 (Leafbeetle, _) => (0.0, 1.5, 3.0),
347 (Stagbeetle, _) => (0.0, 3.5, 3.5),
348 (Weevil, _) => (0.0, 1.5, 3.0),
349 (Cavespider, _) => (0.0, 1.0, 4.0),
350 (Moltencrawler, _) => (0.0, 5.5, 6.0),
351 (Mosscrawler, _) => (0.0, 6.5, 6.0),
352 (Sandcrawler, _) => (0.0, 6.5, 6.0),
353 (Dagonite, _) => (0.0, 8.5, 6.0),
354 (Emberfly, _) => (0.0, 3.0, 4.0),
355 }
356 .into();
357
358 let (mount_mat, orientation) = mount_mat(body, computed_skeleton, skeleton);
359 Transform {
360 position: mount_mat.mul_point(mount_point),
361 orientation,
362 scale: Vec3::one(),
363 }
364}