veloren/voxygen/src/anim/mod.rs

54 lines
1.2 KiB
Rust
Raw Normal View History

2019-01-14 14:40:22 +00:00
pub mod character;
// Library
use vek::*;
// Crate
use crate::render::FigureBoneData;
#[derive(Copy, Clone)]
pub struct Bone {
pub offset: Vec3<f32>,
pub ori: Quaternion<f32>,
pub scale: Vec3<f32>,
}
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<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) {
// TODO: Make configurable
let factor = 0.3;
self.offset += (target.offset - self.offset) * factor;
}
}
pub trait Skeleton: Send + Sync + 'static {
2019-01-14 14:18:58 +00:00
fn compute_matrices(&self) -> [FigureBoneData; 16];
/// Change the current skeleton to be more like `target`
fn interpolate(&mut self, target: &Self);
}
2019-01-14 14:18:58 +00:00
pub trait Animation {
type Skeleton;
type Dependency;
/// Returns a new skeleton that is generated by the animation
2019-01-14 14:18:58 +00:00
fn update_skeleton(
skeleton: &Self::Skeleton,
2019-01-14 14:18:58 +00:00
dependency: Self::Dependency,
) -> Self::Skeleton;
2019-01-14 14:18:58 +00:00
}