veloren/voxygen/src/anim/mod.rs
2020-03-05 14:02:11 +00:00

73 lines
1.8 KiB
Rust

pub mod biped_large;
pub mod bird_medium;
pub mod bird_small;
pub mod character;
pub mod critter;
pub mod dragon;
pub mod fish_medium;
pub mod fish_small;
pub mod fixture;
pub mod object;
pub mod quadruped_medium;
pub mod quadruped_small;
use crate::render::FigureBoneData;
use vek::*;
#[derive(Copy, Clone)]
pub struct Bone {
pub offset: Vec3<f32>,
pub ori: Quaternion<f32>,
pub scale: Vec3<f32>,
}
impl Default for Bone {
fn default() -> Self {
Self {
offset: Vec3::zero(),
ori: Quaternion::identity(),
scale: Vec3::broadcast(1.0 / 11.0),
}
}
}
impl Bone {
pub fn compute_base_matrix(&self) -> Mat4<f32> {
Mat4::<f32>::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, dt: f32) {
// TODO: Make configurable.
let factor = (15.0 * dt).min(1.0);
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 {
type Attr;
fn compute_matrices(&self) -> [FigureBoneData; 18];
/// Change the current skeleton to be more like `target`.
fn interpolate(&mut self, target: &Self, dt: f32);
}
pub trait Animation {
type Skeleton: Skeleton;
type Dependency;
/// Returns a new skeleton that is generated by the animation.
fn update_skeleton(
skeleton: &Self::Skeleton,
dependency: Self::Dependency,
anim_time: f64,
rate: &mut f32,
skeleton_attr: &<<Self as Animation>::Skeleton as Skeleton>::Attr,
) -> Self::Skeleton;
}