veloren/voxygen/src/anim/quadruped_small/mod.rs

181 lines
6.2 KiB
Rust
Raw Normal View History

pub mod idle;
pub mod jump;
pub mod run;
// Reexports
pub use self::{idle::IdleAnimation, jump::JumpAnimation, run::RunAnimation};
use super::{Bone, Skeleton};
use crate::render::FigureBoneData;
2020-01-26 00:22:48 +00:00
use common::comp::{self};
use vek::Vec3;
2020-01-26 00:22:48 +00:00
#[derive(Clone, Default)]
pub struct QuadrupedSmallSkeleton {
2019-10-26 02:20:38 +00:00
head: Bone,
chest: Bone,
leg_lf: Bone,
leg_rf: Bone,
leg_lb: Bone,
leg_rb: Bone,
2020-06-01 00:33:24 +00:00
tail: Bone,
}
impl QuadrupedSmallSkeleton {
pub fn new() -> Self { Self::default() }
}
impl Skeleton for QuadrupedSmallSkeleton {
2020-01-26 00:22:48 +00:00
type Attr = SkeletonAttr;
2020-06-01 00:33:24 +00:00
fn bone_count(&self) -> usize { 7 }
fn compute_matrices(&self) -> ([FigureBoneData; 16], Vec3<f32>) {
2020-06-01 00:33:24 +00:00
let chest_mat = self.chest.compute_base_matrix();
(
[
FigureBoneData::new(self.head.compute_base_matrix()),
2020-06-01 00:33:24 +00:00
FigureBoneData::new(chest_mat),
FigureBoneData::new(self.leg_lf.compute_base_matrix()),
FigureBoneData::new(self.leg_rf.compute_base_matrix()),
FigureBoneData::new(self.leg_lb.compute_base_matrix()),
FigureBoneData::new(self.leg_rb.compute_base_matrix()),
2020-06-01 00:33:24 +00:00
FigureBoneData::new(chest_mat * self.tail.compute_base_matrix()),
FigureBoneData::default(),
FigureBoneData::default(),
FigureBoneData::default(),
FigureBoneData::default(),
FigureBoneData::default(),
FigureBoneData::default(),
FigureBoneData::default(),
FigureBoneData::default(),
FigureBoneData::default(),
],
Vec3::default(),
)
}
fn interpolate(&mut self, target: &Self, dt: f32) {
2019-10-26 02:20:38 +00:00
self.head.interpolate(&target.head, dt);
self.chest.interpolate(&target.chest, dt);
self.leg_lf.interpolate(&target.leg_lf, dt);
self.leg_rf.interpolate(&target.leg_rf, dt);
self.leg_lb.interpolate(&target.leg_lb, dt);
self.leg_rb.interpolate(&target.leg_rb, dt);
2020-06-01 00:33:24 +00:00
self.tail.interpolate(&target.tail, dt);
}
}
2020-01-26 00:22:48 +00:00
pub struct SkeletonAttr {
head: (f32, f32),
chest: (f32, f32),
feet_f: (f32, f32, f32),
feet_b: (f32, f32, f32),
2020-06-01 00:33:24 +00:00
tail: (f32, f32),
2020-01-26 00:22:48 +00:00
}
impl<'a> std::convert::TryFrom<&'a comp::Body> for SkeletonAttr {
type Error = ();
fn try_from(body: &'a comp::Body) -> Result<Self, Self::Error> {
match body {
comp::Body::QuadrupedSmall(body) => Ok(SkeletonAttr::from(body)),
_ => Err(()),
}
}
}
impl Default for SkeletonAttr {
fn default() -> Self {
Self {
head: (0.0, 0.0),
chest: (0.0, 0.0),
feet_f: (0.0, 0.0, 0.0),
feet_b: (0.0, 0.0, 0.0),
2020-06-01 00:33:24 +00:00
tail: (0.0, 0.0),
2020-01-26 00:22:48 +00:00
}
}
}
impl<'a> From<&'a comp::quadruped_small::Body> for SkeletonAttr {
fn from(body: &'a comp::quadruped_small::Body) -> Self {
use comp::quadruped_small::Species::*;
Self {
head: match (body.species, body.body_type) {
(Pig, _) => (6.0, 7.0),
(Fox, _) => (8.0, 8.0),
(Sheep, _) => (8.0, 8.0),
(Boar, _) => (13.0, 8.0),
(Jackalope, _) => (6.0, 9.0),
(Skunk, _) => (7.0, 9.0),
(Cat, _) => (7.0, 8.0),
(Batfox, _) => (8.0, 9.0),
(Raccoon, _) => (9.0, 7.0),
(Quokka, _) => (10.0, 10.0),
(Dodarock, _) => (8.0, 9.0),
(Holladon, _) => (8.0, 8.0),
2020-04-28 03:13:23 +00:00
(Hyena, _) => (7.5, 13.0),
2020-01-26 00:22:48 +00:00
},
chest: match (body.species, body.body_type) {
(Pig, _) => (0.0, 8.0),
2020-06-01 00:33:24 +00:00
(Fox, _) => (1.0, 5.0),
(Sheep, _) => (-1.0, 6.0),
(Boar, _) => (0.0, 7.0),
2020-01-26 00:22:48 +00:00
(Jackalope, _) => (-2.0, 6.0),
2020-06-01 00:33:24 +00:00
(Skunk, _) => (0.0, 6.0),
(Cat, _) => (0.0, 6.0),
2020-01-26 00:22:48 +00:00
(Batfox, _) => (-2.0, 6.0),
2020-06-01 00:33:24 +00:00
(Raccoon, _) => (0.0, 6.0),
2020-01-26 00:22:48 +00:00
(Quokka, _) => (2.0, 8.0),
(Dodarock, _) => (-2.0, 8.0),
(Holladon, _) => (-2.0, 6.0),
2020-04-28 03:13:23 +00:00
(Hyena, _) => (-2.0, 9.0),
2020-01-26 00:22:48 +00:00
},
feet_f: match (body.species, body.body_type) {
(Pig, _) => (3.0, 5.0, 2.0),
(Fox, _) => (3.0, 5.0, 3.0),
(Sheep, _) => (3.0, 3.0, 3.0),
(Boar, _) => (3.0, 5.0, 3.0),
(Jackalope, _) => (3.0, 5.0, 4.0),
(Skunk, _) => (3.0, 3.0, 4.0),
(Cat, _) => (3.0, 5.0, 3.0),
(Batfox, _) => (2.5, 5.0, 3.0),
(Raccoon, _) => (3.0, 5.0, 3.0),
(Quokka, _) => (3.0, 5.0, 3.0),
(Dodarock, _) => (3.5, 5.0, 4.0),
(Holladon, _) => (3.0, 5.0, 4.0),
2020-04-28 03:13:23 +00:00
(Hyena, _) => (2.5, 5.0, 6.0),
2020-01-26 00:22:48 +00:00
},
feet_b: match (body.species, body.body_type) {
(Pig, _) => (3.0, -2.0, 2.0),
(Fox, _) => (2.5, -2.0, 3.0),
(Sheep, _) => (3.0, -4.0, 3.0),
(Boar, _) => (3.0, -3.0, 5.0),
(Jackalope, _) => (3.0, -2.0, 4.0),
(Skunk, _) => (3.0, -4.0, 4.0),
(Cat, _) => (2.0, -2.0, 3.0),
(Batfox, _) => (2.5, -2.0, 3.0),
(Raccoon, _) => (3.0, -2.0, 3.0),
(Quokka, _) => (3.0, -4.0, 3.0),
(Dodarock, _) => (4.5, -3.0, 4.0),
2020-01-29 06:38:08 +00:00
(Holladon, _) => (4.0, -4.0, 3.0),
2020-04-28 03:13:23 +00:00
(Hyena, _) => (2.5, -7.0, 6.0),
2020-01-26 00:22:48 +00:00
},
2020-06-01 00:33:24 +00:00
tail: match (body.species, body.body_type) {
(Pig, _) => (-4.0, 3.0),
(Fox, _) => (-3.5, 1.0),
(Sheep, _) => (-5.0, 0.0),
(Boar, _) => (-8.5, 2.0),
(Jackalope, _) => (0.0, 5.0),
(Skunk, _) => (-3.0, 1.5),
(Cat, _) => (-3.0, 2.0),
(Batfox, _) => (0.0, 5.0),
(Raccoon, _) => (-4.0, 1.0),
(Quokka, _) => (0.0, 6.0),
(Dodarock, _) => (0.0, 5.0),
(Holladon, _) => (0.0, 4.0),
(Hyena, _) => (-8.0, 1.0),
},
2020-01-26 00:22:48 +00:00
}
}
}