2019-01-14 14:40:22 +00:00
|
|
|
pub mod character;
|
2019-05-13 23:43:10 +00:00
|
|
|
pub mod quadruped;
|
2019-01-13 20:53:55 +00:00
|
|
|
// Library
|
|
|
|
use vek::*;
|
|
|
|
|
|
|
|
// Crate
|
|
|
|
use crate::render::FigureBoneData;
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub struct Bone {
|
|
|
|
pub offset: Vec3<f32>,
|
|
|
|
pub ori: Quaternion<f32>,
|
2019-04-12 22:19:19 +00:00
|
|
|
pub scale: Vec3<f32>,
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Bone {
|
|
|
|
pub fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
offset: Vec3::zero(),
|
|
|
|
ori: Quaternion::identity(),
|
2019-04-12 22:19:19 +00:00
|
|
|
scale: Vec3::broadcast(1.0 / 11.0),
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn compute_base_matrix(&self) -> Mat4<f32> {
|
2019-04-29 20:37:19 +00:00
|
|
|
Mat4::<f32>::translation_3d(self.offset)
|
|
|
|
* Mat4::scaling_3d(self.scale)
|
|
|
|
* Mat4::from(self.ori)
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
2019-04-16 18:15:49 +00:00
|
|
|
|
|
|
|
/// 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;
|
2019-04-16 18:43:13 +00:00
|
|
|
self.ori = vek::ops::Slerp::slerp(self.ori, target.ori, factor);
|
|
|
|
self.scale += (target.scale - self.scale) * factor;
|
2019-04-16 18:15:49 +00:00
|
|
|
}
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 21:51:14 +00:00
|
|
|
pub trait Skeleton: Send + Sync + 'static {
|
2019-01-14 14:18:58 +00:00
|
|
|
fn compute_matrices(&self) -> [FigureBoneData; 16];
|
2019-04-16 18:15:49 +00:00
|
|
|
|
|
|
|
/// Change the current skeleton to be more like `target`
|
|
|
|
fn interpolate(&mut self, target: &Self);
|
2019-01-13 20:53:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 14:18:58 +00:00
|
|
|
pub trait Animation {
|
|
|
|
type Skeleton;
|
|
|
|
type Dependency;
|
|
|
|
|
2019-04-16 18:15:49 +00:00
|
|
|
/// Returns a new skeleton that is generated by the animation
|
2019-05-09 17:58:16 +00:00
|
|
|
fn update_skeleton(
|
|
|
|
skeleton: &Self::Skeleton,
|
|
|
|
dependency: Self::Dependency,
|
|
|
|
anim_time: f64,
|
|
|
|
) -> Self::Skeleton;
|
2019-01-14 14:18:58 +00:00
|
|
|
}
|