veloren_voxygen_anim/crustacean/
mod.rs

1mod alpha;
2mod combomelee;
3mod idle;
4mod jump;
5mod leapmelee;
6mod ripostemelee;
7mod run;
8mod stunned;
9mod summon;
10mod swim;
11
12// Reexports
13pub use self::{
14    alpha::AlphaAnimation, combomelee::ComboAnimation, idle::IdleAnimation, jump::JumpAnimation,
15    leapmelee::LeapMeleeAnimation, ripostemelee::RiposteMeleeAnimation, run::RunAnimation,
16    stunned::StunnedAnimation, summon::SummonAnimation, swim::SwimAnimation,
17};
18
19use common::comp::{self};
20
21use super::{FigureBoneData, Skeleton, vek::*};
22
23pub type Body = comp::crustacean::Body;
24
25skeleton_impls!(struct CrustaceanSkeleton ComputedCrustaceanSkeleton {
26    + chest
27    + tail_f
28    + tail_b
29    + arm_l
30    + pincer_l0
31    + pincer_l1
32    + arm_r
33    + pincer_r0
34    + pincer_r1
35    + leg_fl
36    + leg_cl
37    + leg_bl
38    + leg_fr
39    + leg_cr
40    + leg_br
41});
42
43impl Skeleton for CrustaceanSkeleton {
44    type Attr = SkeletonAttr;
45    type Body = Body;
46    type ComputedSkeleton = ComputedCrustaceanSkeleton;
47
48    const BONE_COUNT: usize = ComputedCrustaceanSkeleton::BONE_COUNT;
49    #[cfg(feature = "use-dyn-lib")]
50    const COMPUTE_FN: &'static [u8] = b"crustacean_compute_s\0";
51
52    #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "crustacean_compute_s"))]
53    fn compute_matrices_inner(
54        &self,
55        base_mat: Mat4<f32>,
56        buf: &mut [FigureBoneData; super::MAX_BONE_COUNT],
57        body: Self::Body,
58    ) -> Self::ComputedSkeleton {
59        let base_mat = base_mat * Mat4::scaling_3d(SkeletonAttr::from(&body).scaler / 6.0);
60
61        let chest_mat = base_mat * Mat4::<f32>::from(self.chest);
62        let tail_f_mat = chest_mat * Mat4::<f32>::from(self.tail_f);
63        let tail_b_mat = chest_mat * Mat4::<f32>::from(self.tail_b);
64        let arm_l_mat = chest_mat * Mat4::<f32>::from(self.arm_l);
65        let pincer_l0_mat = arm_l_mat * Mat4::<f32>::from(self.pincer_l0);
66        let pincer_l1_mat = pincer_l0_mat * Mat4::<f32>::from(self.pincer_l1);
67        let arm_r_mat = chest_mat * Mat4::<f32>::from(self.arm_r);
68        let pincer_r0_mat = arm_r_mat * Mat4::<f32>::from(self.pincer_r0);
69        let pincer_r1_mat = pincer_r0_mat * Mat4::<f32>::from(self.pincer_r1);
70        let leg_fl_mat = chest_mat * Mat4::<f32>::from(self.leg_fl);
71        let leg_cl_mat = chest_mat * Mat4::<f32>::from(self.leg_cl);
72        let leg_bl_mat = chest_mat * Mat4::<f32>::from(self.leg_bl);
73        let leg_fr_mat = chest_mat * Mat4::<f32>::from(self.leg_fr);
74        let leg_cr_mat = chest_mat * Mat4::<f32>::from(self.leg_cr);
75        let leg_br_mat = chest_mat * Mat4::<f32>::from(self.leg_br);
76
77        let computed_skeleton = ComputedCrustaceanSkeleton {
78            chest: chest_mat,
79            tail_f: tail_f_mat,
80            tail_b: tail_b_mat,
81            arm_l: arm_l_mat,
82            pincer_l0: pincer_l0_mat,
83            pincer_l1: pincer_l1_mat,
84            arm_r: arm_r_mat,
85            pincer_r0: pincer_r0_mat,
86            pincer_r1: pincer_r1_mat,
87            leg_fl: leg_fl_mat,
88            leg_cl: leg_cl_mat,
89            leg_bl: leg_bl_mat,
90            leg_fr: leg_fr_mat,
91            leg_cr: leg_cr_mat,
92            leg_br: leg_br_mat,
93        };
94
95        computed_skeleton.set_figure_bone_data(buf);
96        computed_skeleton
97    }
98}
99
100pub struct SkeletonAttr {
101    chest: (f32, f32),
102    arm: (f32, f32, f32),
103    leg_f: (f32, f32, f32),
104    leg_c: (f32, f32, f32),
105    leg_b: (f32, f32, f32),
106    leg_ori: (f32, f32, f32),
107    move_sideways: bool,
108    scaler: f32,
109}
110
111impl<'a> From<&'a Body> for SkeletonAttr {
112    fn from(body: &'a Body) -> Self {
113        use comp::crustacean::Species::*;
114        Self {
115            chest: match (body.species, body.body_type) {
116                (Crab, _) => (0.0, 0.0),
117                (SoldierCrab, _) => (0.0, 0.0),
118                (Karkatha, _) => (0.0, 0.0),
119            },
120            arm: match (body.species, body.body_type) {
121                (Crab, _) => (0.0, 5.0, 0.0),
122                (SoldierCrab, _) => (0.0, 5.0, 0.0),
123                (Karkatha, _) => (0.0, 0.0, 0.0),
124            },
125            leg_f: match (body.species, body.body_type) {
126                (Crab, _) => (0.0, 0.0, 0.0),
127                (SoldierCrab, _) => (0.0, 0.0, 0.0),
128                (Karkatha, _) => (3.0, 0.0, 0.0),
129            },
130            leg_c: match (body.species, body.body_type) {
131                (Crab, _) => (0.0, 0.0, 0.0),
132                (SoldierCrab, _) => (0.0, 0.0, 0.0),
133                (Karkatha, _) => (0.0, 0.0, 0.0),
134            },
135            leg_b: match (body.species, body.body_type) {
136                (Crab, _) => (0.0, 0.0, 0.0),
137                (SoldierCrab, _) => (0.0, 0.0, 0.0),
138                (Karkatha, _) => (0.0, 0.0, 0.0),
139            },
140            leg_ori: match (body.species, body.body_type) {
141                (Crab, _) => (-0.4, 0.0, 0.4),
142                (SoldierCrab, _) => (-0.4, 0.0, 0.4),
143                (Karkatha, _) => (-0.4, 0.0, 0.4),
144            },
145            move_sideways: match (body.species, body.body_type) {
146                (Crab, _) => true,
147                (SoldierCrab, _) => true,
148                (Karkatha, _) => false,
149            },
150            scaler: match (body.species, body.body_type) {
151                (Crab, _) => 0.62,
152                (SoldierCrab, _) => 0.62,
153                (Karkatha, _) => 1.2,
154            },
155        }
156    }
157}
158
159pub fn mount_mat(
160    computed_skeleton: &ComputedCrustaceanSkeleton,
161    skeleton: &CrustaceanSkeleton,
162) -> (Mat4<f32>, Quaternion<f32>) {
163    (computed_skeleton.chest, skeleton.chest.orientation)
164}
165
166pub fn mount_transform(
167    body: &Body,
168    computed_skeleton: &ComputedCrustaceanSkeleton,
169    skeleton: &CrustaceanSkeleton,
170) -> Transform<f32, f32, f32> {
171    use comp::crustacean::Species::*;
172
173    let mount_point = match (body.species, body.body_type) {
174        (Crab, _) => (0.0, -3.5, 6.0),
175        (SoldierCrab, _) => (0.0, -2.5, 8.0),
176        (Karkatha, _) => (0.0, -1.0, 32.0),
177    }
178    .into();
179
180    let (mount_mat, orientation) = mount_mat(computed_skeleton, skeleton);
181    Transform {
182        position: mount_mat.mul_point(mount_point),
183        orientation,
184        scale: Vec3::one(),
185    }
186}