mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
pub mod character;
|
|
pub mod fixture;
|
|
pub mod quadruped;
|
|
pub mod quadrupedmedium;
|
|
|
|
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 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;
|
|
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,
|
|
anim_time: f64,
|
|
) -> Self::Skeleton;
|
|
}
|