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
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 tail_f_mat = chest_mat * Mat4::<f32>::from(self.tail_f);
64        let tail_b_mat = chest_mat * Mat4::<f32>::from(self.tail_b);
65        let arm_l_mat = chest_mat * Mat4::<f32>::from(self.arm_l);
66        let pincer_l0_mat = arm_l_mat * Mat4::<f32>::from(self.pincer_l0);
67        let pincer_l1_mat = pincer_l0_mat * Mat4::<f32>::from(self.pincer_l1);
68        let arm_r_mat = chest_mat * Mat4::<f32>::from(self.arm_r);
69        let pincer_r0_mat = arm_r_mat * Mat4::<f32>::from(self.pincer_r0);
70        let pincer_r1_mat = pincer_r0_mat * Mat4::<f32>::from(self.pincer_r1);
71        let leg_fl_mat = chest_mat * Mat4::<f32>::from(self.leg_fl);
72        let leg_cl_mat = chest_mat * Mat4::<f32>::from(self.leg_cl);
73        let leg_bl_mat = chest_mat * Mat4::<f32>::from(self.leg_bl);
74        let leg_fr_mat = chest_mat * Mat4::<f32>::from(self.leg_fr);
75        let leg_cr_mat = chest_mat * Mat4::<f32>::from(self.leg_cr);
76        let leg_br_mat = chest_mat * Mat4::<f32>::from(self.leg_br);
77
78        let computed_skeleton = ComputedCrustaceanSkeleton {
79            chest: chest_mat,
80            tail_f: tail_f_mat,
81            tail_b: tail_b_mat,
82            arm_l: arm_l_mat,
83            pincer_l0: pincer_l0_mat,
84            pincer_l1: pincer_l1_mat,
85            arm_r: arm_r_mat,
86            pincer_r0: pincer_r0_mat,
87            pincer_r1: pincer_r1_mat,
88            leg_fl: leg_fl_mat,
89            leg_cl: leg_cl_mat,
90            leg_bl: leg_bl_mat,
91            leg_fr: leg_fr_mat,
92            leg_cr: leg_cr_mat,
93            leg_br: leg_br_mat,
94        };
95
96        computed_skeleton.set_figure_bone_data(buf);
97        computed_skeleton
98    }
99}
100
101pub struct SkeletonAttr {
102    chest: (f32, f32),
103    arm: (f32, f32, f32),
104    leg_f: (f32, f32, f32),
105    leg_c: (f32, f32, f32),
106    leg_b: (f32, f32, f32),
107    leg_ori: (f32, f32, f32),
108    move_sideways: bool,
109    scaler: f32,
110}
111
112impl<'a> From<&'a Body> for SkeletonAttr {
113    fn from(body: &'a Body) -> Self {
114        use comp::crustacean::Species::*;
115        Self {
116            chest: match (body.species, body.body_type) {
117                (Crab, _) => (0.0, 0.0),
118                (SoldierCrab, _) => (0.0, 0.0),
119                (Karkatha, _) => (0.0, 0.0),
120            },
121            arm: match (body.species, body.body_type) {
122                (Crab, _) => (0.0, 5.0, 0.0),
123                (SoldierCrab, _) => (0.0, 5.0, 0.0),
124                (Karkatha, _) => (0.0, 0.0, 0.0),
125            },
126            leg_f: match (body.species, body.body_type) {
127                (Crab, _) => (0.0, 0.0, 0.0),
128                (SoldierCrab, _) => (0.0, 0.0, 0.0),
129                (Karkatha, _) => (3.0, 0.0, 0.0),
130            },
131            leg_c: match (body.species, body.body_type) {
132                (Crab, _) => (0.0, 0.0, 0.0),
133                (SoldierCrab, _) => (0.0, 0.0, 0.0),
134                (Karkatha, _) => (0.0, 0.0, 0.0),
135            },
136            leg_b: match (body.species, body.body_type) {
137                (Crab, _) => (0.0, 0.0, 0.0),
138                (SoldierCrab, _) => (0.0, 0.0, 0.0),
139                (Karkatha, _) => (0.0, 0.0, 0.0),
140            },
141            leg_ori: match (body.species, body.body_type) {
142                (Crab, _) => (-0.4, 0.0, 0.4),
143                (SoldierCrab, _) => (-0.4, 0.0, 0.4),
144                (Karkatha, _) => (-0.4, 0.0, 0.4),
145            },
146            move_sideways: match (body.species, body.body_type) {
147                (Crab, _) => true,
148                (SoldierCrab, _) => true,
149                (Karkatha, _) => false,
150            },
151            scaler: match (body.species, body.body_type) {
152                (Crab, _) => 0.62,
153                (SoldierCrab, _) => 0.62,
154                (Karkatha, _) => 1.2,
155            },
156        }
157    }
158}
159
160pub fn mount_mat(
161    computed_skeleton: &ComputedCrustaceanSkeleton,
162    skeleton: &CrustaceanSkeleton,
163) -> (Mat4<f32>, Quaternion<f32>) {
164    (computed_skeleton.chest, skeleton.chest.orientation)
165}
166
167pub fn mount_transform(
168    body: &Body,
169    computed_skeleton: &ComputedCrustaceanSkeleton,
170    skeleton: &CrustaceanSkeleton,
171) -> Transform<f32, f32, f32> {
172    use comp::crustacean::Species::*;
173
174    let mount_point = match (body.species, body.body_type) {
175        (Crab, _) => (0.0, -3.5, 6.0),
176        (SoldierCrab, _) => (0.0, -2.5, 8.0),
177        (Karkatha, _) => (0.0, -1.0, 32.0),
178    }
179    .into();
180
181    let (mount_mat, orientation) = mount_mat(computed_skeleton, skeleton);
182    Transform {
183        position: mount_mat.mul_point(mount_point),
184        orientation,
185        scale: Vec3::one(),
186    }
187}