1pub mod alpha;
2pub mod breathe;
3pub mod dash;
4pub mod feed;
5pub mod fly;
6pub mod idle;
7pub mod run;
8pub mod shockwave;
9pub mod shoot;
10pub mod stunned;
11pub mod summon;
12pub mod swim;
13
14pub use self::{
16 alpha::AlphaAnimation, breathe::BreatheAnimation, dash::DashAnimation, feed::FeedAnimation,
17 fly::FlyAnimation, idle::IdleAnimation, run::RunAnimation, shockwave::ShockwaveAnimation,
18 shoot::ShootAnimation, stunned::StunnedAnimation, summon::SummonAnimation, swim::SwimAnimation,
19};
20
21use super::{FigureBoneData, Offsets, Skeleton, make_bone, vek::*};
22use common::comp::{self};
23use core::convert::TryFrom;
24
25pub type Body = comp::bird_medium::Body;
26
27skeleton_impls!(struct BirdMediumSkeleton {
28 + head,
29 + chest,
30 + tail,
31 + wing_in_l,
32 + wing_in_r,
33 + wing_out_l,
34 + wing_out_r,
35 + leg_l,
36 + leg_r,
37});
38
39impl Skeleton for BirdMediumSkeleton {
40 type Attr = SkeletonAttr;
41 type Body = Body;
42
43 const BONE_COUNT: usize = 9;
44 #[cfg(feature = "use-dyn-lib")]
45 const COMPUTE_FN: &'static [u8] = b"bird_medium_compute_mats\0";
46
47 #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_medium_compute_mats")]
48
49 fn compute_matrices_inner(
50 &self,
51 base_mat: Mat4<f32>,
52 buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
53 body: Self::Body,
54 ) -> Offsets {
55 let base_mat = base_mat * Mat4::scaling_3d(SkeletonAttr::from(&body).scaler / 8.0);
56
57 let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
58 let head_mat = chest_mat * Mat4::<f32>::from(self.head);
59 let tail_mat = chest_mat * Mat4::<f32>::from(self.tail);
60 let wing_in_l_mat = chest_mat * Mat4::<f32>::from(self.wing_in_l);
61 let wing_in_r_mat = chest_mat * Mat4::<f32>::from(self.wing_in_r);
62 let wing_out_l_mat = wing_in_l_mat * Mat4::<f32>::from(self.wing_out_l);
63 let wing_out_r_mat = wing_in_r_mat * Mat4::<f32>::from(self.wing_out_r);
64 let leg_l_mat = base_mat * Mat4::<f32>::from(self.leg_l);
65 let leg_r_mat = base_mat * Mat4::<f32>::from(self.leg_r);
66
67 *(<&mut [_; Self::BONE_COUNT]>::try_from(&mut buf[0..Self::BONE_COUNT]).unwrap()) = [
68 make_bone(head_mat),
69 make_bone(chest_mat),
70 make_bone(tail_mat),
71 make_bone(wing_in_l_mat),
72 make_bone(wing_in_r_mat),
73 make_bone(wing_out_l_mat),
74 make_bone(wing_out_r_mat),
75 make_bone(leg_l_mat),
76 make_bone(leg_r_mat),
77 ];
78 use common::comp::body::bird_medium::Species::*;
79
80 let (mount_bone_mat, mount_bone_ori) = (chest_mat, self.chest.orientation);
81 let mount_position = mount_bone_mat.mul_point(mount_point(&body));
82 let mount_orientation = mount_bone_ori;
83
84 Offsets {
85 viewpoint: match body.species {
86 Bat | BloodmoonBat | VampireBat => {
87 Some((head_mat * Vec4::new(0.0, 5.0, -4.0, 1.0)).xyz())
88 },
89 _ => Some((head_mat * Vec4::new(0.0, 3.0, 2.0, 1.0)).xyz()),
90 },
91 mount_bone: Transform {
92 position: mount_position,
93 orientation: mount_orientation,
94 scale: Vec3::one(),
95 },
96 ..Default::default()
97 }
98 }
99}
100
101pub struct SkeletonAttr {
102 head: (f32, f32),
103 chest: (f32, f32),
104 tail: (f32, f32),
105 wing_in: (f32, f32, f32),
106 wing_out: (f32, f32, f32),
107 leg: (f32, f32, f32),
108 scaler: f32,
109 feed: f32,
110}
111
112impl<'a> TryFrom<&'a comp::Body> for SkeletonAttr {
113 type Error = ();
114
115 fn try_from(body: &'a comp::Body) -> Result<Self, Self::Error> {
116 match body {
117 comp::Body::BirdMedium(body) => Ok(SkeletonAttr::from(body)),
118 _ => Err(()),
119 }
120 }
121}
122
123impl Default for SkeletonAttr {
124 fn default() -> Self {
125 Self {
126 chest: (0.0, 0.0),
127 head: (0.0, 0.0),
128 tail: (0.0, 0.0),
129 wing_in: (0.0, 0.0, 0.0),
130 wing_out: (0.0, 0.0, 0.0),
131 leg: (0.0, 0.0, 0.0),
132 scaler: 0.0,
133 feed: 0.0,
134 }
135 }
136}
137
138impl<'a> From<&'a Body> for SkeletonAttr {
139 fn from(body: &'a Body) -> Self {
140 use comp::bird_medium::{BodyType::*, Species::*};
141 Self {
142 chest: match (body.species, body.body_type) {
143 (SnowyOwl, _) => (0.0, 4.5),
144 (HornedOwl, _) => (0.0, 4.5),
145 (Duck, _) => (0.0, 4.0),
146 (Cockatiel, _) => (0.0, 4.0),
147 (Chicken, Male) => (0.0, 5.5),
148 (Chicken, Female) => (0.0, 5.5),
149 (Bat, _) => (0.0, 7.0),
150 (Penguin, _) => (0.0, 7.0),
151 (Goose, _) => (0.0, 6.5),
152 (Peacock, _) => (0.0, 7.5),
153 (Eagle, _) => (0.0, 6.0),
154 (Parrot, _) => (0.0, 5.0),
155 (Crow, _) => (0.0, 4.0),
156 (Dodo, _) => (0.0, 6.0),
157 (Parakeet, _) => (0.0, 3.5),
158 (Puffin, _) => (0.0, 6.0),
159 (Toucan, _) => (0.0, 5.0),
160 (BloodmoonBat, _) => (0.0, 7.0),
161 (VampireBat, _) => (0.0, 7.5),
162 },
163 head: match (body.species, body.body_type) {
164 (SnowyOwl, _) => (3.5, 5.0),
165 (HornedOwl, _) => (3.5, 5.0),
166 (Duck, _) => (2.0, 5.5),
167 (Cockatiel, _) => (3.0, 5.5),
168 (Chicken, Male) => (3.0, 4.5),
169 (Chicken, Female) => (3.0, 6.0),
170 (Bat, _) => (2.5, 5.0),
171 (Penguin, _) => (1.5, 6.0),
172 (Goose, _) => (5.0, 4.0),
173 (Peacock, _) => (3.0, 5.0),
174 (Eagle, _) => (4.5, 5.0),
175 (Parrot, _) => (1.5, 4.5),
176 (Crow, _) => (4.5, 4.0),
177 (Dodo, _) => (3.5, 4.5),
178 (Parakeet, _) => (2.0, 4.0),
179 (Puffin, _) => (3.5, 5.5),
180 (Toucan, _) => (2.5, 4.5),
181 (BloodmoonBat, _) => (4.0, 5.0),
182 (VampireBat, _) => (2.5, 5.0),
183 },
184 tail: match (body.species, body.body_type) {
185 (SnowyOwl, _) => (-6.0, -2.0),
186 (HornedOwl, _) => (-6.0, -2.0),
187 (Duck, _) => (-5.0, 1.0),
188 (Cockatiel, _) => (-3.0, -0.5),
189 (Chicken, Male) => (-7.5, 3.5),
190 (Chicken, Female) => (-4.5, 3.0),
191 (Bat, _) => (-8.0, -4.0),
192 (Penguin, _) => (-3.0, -4.0),
193 (Goose, _) => (-4.0, 3.0),
194 (Peacock, _) => (-5.5, 1.0),
195 (Eagle, _) => (-6.0, -2.0),
196 (Parrot, _) => (-6.0, 0.0),
197 (Crow, _) => (-5.0, -1.5),
198 (Dodo, _) => (-7.5, -0.5),
199 (Parakeet, _) => (-5.0, -1.0),
200 (Puffin, _) => (-7.0, -2.0),
201 (Toucan, _) => (-6.0, 0.0),
202 (BloodmoonBat, _) => (-6.0, 1.0),
203 (VampireBat, _) => (-5.0, -4.0),
204 },
205 wing_in: match (body.species, body.body_type) {
206 (SnowyOwl, _) => (2.5, 1.0, 1.5),
207 (HornedOwl, _) => (2.5, 1.0, 1.5),
208 (Duck, _) => (2.5, 0.5, 1.0),
209 (Cockatiel, _) => (1.5, 0.5, 1.0),
210 (Chicken, Male) => (2.0, 1.0, 1.0),
211 (Chicken, Female) => (2.0, 1.5, 1.0),
212 (Bat, _) => (2.0, 2.0, -2.0),
213 (Penguin, _) => (3.0, 0.5, 1.0),
214 (Goose, _) => (2.5, 1.0, 2.0),
215 (Peacock, _) => (2.0, 1.0, 1.0),
216 (Eagle, _) => (3.0, 1.5, 1.0),
217 (Parrot, _) => (2.0, 0.5, 0.0),
218 (Crow, _) => (2.0, 0.5, 1.0),
219 (Dodo, _) => (3.0, -1.0, 1.0),
220 (Parakeet, _) => (1.0, 0.5, 0.0),
221 (Puffin, _) => (2.0, 0.0, 1.0),
222 (Toucan, _) => (2.0, 0.5, 0.0),
223 (BloodmoonBat, _) => (4.0, 3.0, 1.5),
224 (VampireBat, _) => (2.0, 2.0, -2.0),
225 },
226 wing_out: match (body.species, body.body_type) {
227 (SnowyOwl, _) => (4.5, 3.5, 1.0),
228 (HornedOwl, _) => (4.5, 3.5, 1.0),
229 (Duck, _) => (3.0, 2.0, 0.5),
230 (Cockatiel, _) => (3.0, 2.0, 0.5),
231 (Chicken, Male) => (3.0, 2.0, 0.5),
232 (Chicken, Female) => (3.0, 2.0, 0.5),
233 (Bat, _) => (5.0, 3.0, 0.0),
234 (Penguin, _) => (3.0, 2.5, 0.5),
235 (Goose, _) => (4.0, 3.0, 0.5),
236 (Peacock, _) => (5.0, 3.0, 0.5),
237 (Eagle, _) => (8.0, 4.5, 0.5),
238 (Parrot, _) => (5.0, 3.0, 0.5),
239 (Crow, _) => (5.0, 3.0, 0.5),
240 (Dodo, _) => (3.0, 3.0, 0.5),
241 (Parakeet, _) => (3.0, 0.0, 0.5),
242 (Puffin, _) => (5.0, 3.0, 0.5),
243 (Toucan, _) => (5.0, 3.0, 0.5),
244 (BloodmoonBat, _) => (11.0, 6.0, 0.0),
245 (VampireBat, _) => (5.0, 5.0, 0.0),
246 },
247 leg: match (body.species, body.body_type) {
248 (SnowyOwl, _) => (1.5, -2.5, 4.8),
249 (HornedOwl, _) => (1.5, -2.5, 4.8),
250 (Duck, _) => (1.5, 0.0, 3.0),
251 (Cockatiel, _) => (1.0, -1.0, 3.0),
252 (Chicken, Male) => (1.0, 0.0, 4.4),
253 (Chicken, Female) => (1.0, 0.0, 4.4),
254 (Bat, _) => (2.5, -1.0, 6.0),
255 (Penguin, _) => (1.5, -1.5, 4.5),
256 (Goose, _) => (2.0, -2.5, 4.4),
257 (Peacock, _) => (2.0, -2.0, 7.0),
258 (Eagle, _) => (1.5, -4.0, 4.4),
259 (Parrot, _) => (1.5, -1.0, 2.2),
260 (Crow, _) => (1.5, -2.5, 2.1),
261 (Dodo, _) => (1.5, -3.0, 3.0),
262 (Parakeet, _) => (1.0, -2.0, 1.3),
263 (Puffin, _) => (1.5, -2.2, 2.5),
264 (Toucan, _) => (1.5, -3.0, 2.3),
265 (BloodmoonBat, _) => (1.5, -3.5, 6.0),
266 (VampireBat, _) => (2.5, -1.0, 6.0),
267 },
268 scaler: match (body.species, body.body_type) {
269 (SnowyOwl, _) => 0.75,
270 (HornedOwl, _) => 0.75,
271 (Duck, _) => 0.75,
272 (Cockatiel, _) => 0.75,
273 (Chicken, _) => 0.75,
274 (Bat, _) => 0.75,
275 (Penguin, _) => 0.75,
276 (Goose, _) => 0.75,
277 (Peacock, _) => 0.75,
278 (Eagle, _) => 0.75,
279 (Parrot, _) => 0.75,
280 (Crow, _) => 0.75,
281 (Dodo, _) => 0.75,
282 (Parakeet, _) => 0.75,
283 (Puffin, _) => 0.75,
284 (Toucan, _) => 0.75,
285 (BloodmoonBat, _) => 1.05,
286 (VampireBat, _) => 0.75,
287 },
288 feed: match (body.species, body.body_type) {
289 (SnowyOwl, _) => -0.65,
290 (HornedOwl, _) => -0.65,
291 (Duck, _) => -0.55,
292 (Cockatiel, _) => -0.60,
293 (Chicken, _) => -0.65,
294 (Bat, _) => -0.55,
295 (Penguin, _) => -0.75,
296 (Goose, _) => -0.65,
297 (Peacock, _) => -1.2,
298 (Eagle, _) => -0.75,
299 (Parrot, _) => -0.60,
300 (Crow, _) => -0.65,
301 (Dodo, _) => -0.65,
302 (Parakeet, _) => -0.60,
303 (Puffin, _) => -0.75,
304 (Toucan, _) => -0.50,
305 (BloodmoonBat, _) => -0.55,
306 (VampireBat, _) => -0.55,
307 },
308 }
309 }
310}
311
312fn mount_point(body: &Body) -> Vec3<f32> {
313 use comp::bird_medium::{BodyType::*, Species::*};
314 match (body.species, body.body_type) {
315 (SnowyOwl, _) => (0.0, -4.0, 2.0),
316 (HornedOwl, _) => (0.0, -4.0, 1.0),
317 (Duck, _) => (0.0, -3.0, 2.0),
318 (Cockatiel, _) => (0.0, -1.5, 1.5),
319 (Chicken, Female) => (0.0, -2.5, 2.5),
320 (Chicken, Male) => (0.0, -2.0, 2.5),
321 (Bat, _) => (0.0, 0.0, -1.5),
322 (Penguin, _) => (0.0, -2.5, 4.5),
323 (Goose, _) => (0.0, -1.0, 3.0),
324 (Peacock, _) => (0.0, -3.0, 2.5),
325 (Eagle, _) => (0.0, -4.0, 2.0),
326 (Parrot, _) => (0.0, -3.0, 1.5),
327 (Crow, _) => (0.0, -1.5, 2.0),
328 (Dodo, _) => (0.0, -4.0, 3.0),
329 (Parakeet, _) => (0.0, -1.5, 1.5),
330 (Puffin, _) => (0.0, -3.5, 1.0),
331 (Toucan, _) => (0.0, -2.0, 1.5),
332 (BloodmoonBat, _) => (0.0, 0.5, 3.5),
333 (VampireBat, _) => (0.0, 0.0, -1.5),
334 }
335 .into()
336}