pub mod character; // Library use vek::*; // Crate use crate::render::FigureBoneData; #[derive(Copy, Clone)] pub struct Bone { pub offset: Vec3, pub ori: Quaternion, pub scale: Vec3, } impl Bone { pub fn default() -> Self { Self { offset: Vec3::zero(), ori: Quaternion::identity(), scale: Vec3::broadcast(1.0 / 11.0), } } pub fn compute_base_matrix(&self) -> Mat4 { Mat4::::translation_3d(self.offset) * Mat4::scaling_3d(self.scale) * Mat4::from(self.ori) } /// Change the current bone to be more like `target` fn interpolate(&mut self, target: &Bone) { // TODO: Make configurable let factor = 0.3; self.offset += (target.offset - self.offset) * factor; self.ori = vek::ops::Slerp::slerp(self.ori, target.ori, factor); self.scale += (target.scale - self.scale) * factor; } } pub trait Skeleton: Send + Sync + 'static { fn compute_matrices(&self) -> [FigureBoneData; 16]; /// Change the current skeleton to be more like `target` fn interpolate(&mut self, target: &Self); } pub trait Animation { type Skeleton; type Dependency; /// Returns a new skeleton that is generated by the animation fn update_skeleton( skeleton: &Self::Skeleton, dependency: Self::Dependency, ) -> Self::Skeleton; }