2019-01-23 20:01:58 +00:00
|
|
|
// Standard
|
|
|
|
use std::f32::consts::PI;
|
|
|
|
|
2019-01-14 14:40:22 +00:00
|
|
|
// Library
|
|
|
|
use vek::*;
|
|
|
|
|
|
|
|
// Local
|
|
|
|
use super::{
|
|
|
|
CharacterSkeleton,
|
|
|
|
super::Animation,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub struct RunAnimation;
|
|
|
|
|
|
|
|
impl Animation for RunAnimation {
|
|
|
|
type Skeleton = CharacterSkeleton;
|
|
|
|
type Dependency = f64;
|
|
|
|
|
|
|
|
fn update_skeleton(
|
|
|
|
skeleton: &mut Self::Skeleton,
|
|
|
|
time: f64,
|
|
|
|
) {
|
2019-01-14 23:13:58 +00:00
|
|
|
let wave = (time as f32 * 12.0).sin();
|
2019-01-23 20:01:58 +00:00
|
|
|
let wave_slow = (time as f32 * 6.0 + PI).sin();
|
|
|
|
let wave_dip = (wave_slow.abs() - 0.5).abs();
|
2019-01-14 14:40:22 +00:00
|
|
|
|
2019-04-12 22:19:19 +00:00
|
|
|
skeleton.head.offset = Vec3::unit_z() * 13.0 / 11.0;
|
2019-03-05 00:00:11 +00:00
|
|
|
skeleton.head.ori = Quaternion::rotation_z(wave * 0.3);
|
2019-01-14 14:40:22 +00:00
|
|
|
|
2019-04-12 22:19:19 +00:00
|
|
|
skeleton.chest.offset = Vec3::unit_z() * 9.0 / 11.0;
|
2019-03-05 00:00:11 +00:00
|
|
|
skeleton.chest.ori = Quaternion::rotation_z(wave * 0.3);
|
2019-01-14 14:40:22 +00:00
|
|
|
|
2019-04-12 22:19:19 +00:00
|
|
|
skeleton.belt.offset = Vec3::unit_z() * 7.0 / 11.0;
|
2019-03-05 00:00:11 +00:00
|
|
|
skeleton.belt.ori = Quaternion::rotation_z(wave * 0.2);
|
2019-01-14 14:40:22 +00:00
|
|
|
|
2019-04-12 22:19:19 +00:00
|
|
|
skeleton.shorts.offset = Vec3::unit_z() * 4.0 / 11.0;
|
2019-03-05 00:00:11 +00:00
|
|
|
skeleton.shorts.ori = Quaternion::rotation_z(wave * 0.1);
|
2019-01-14 14:40:22 +00:00
|
|
|
|
2019-04-12 22:19:19 +00:00
|
|
|
skeleton.l_hand.offset = Vec3::new(-6.0 - wave_dip * 6.0, wave * 5.0, 11.0 - wave_dip * 6.0) / 11.0;
|
|
|
|
skeleton.r_hand.offset = Vec3::new(6.0 + wave_dip * 6.0, -wave * 5.0, 11.0 - wave_dip * 6.0) / 11.0;
|
2019-01-14 14:40:22 +00:00
|
|
|
|
2019-04-12 22:19:19 +00:00
|
|
|
skeleton.l_foot.offset = Vec3::new(-3.5, 1.0 - wave * 8.0, 3.5 - wave_dip * 4.0) / 11.0;
|
2019-03-05 00:00:11 +00:00
|
|
|
skeleton.l_foot.ori = Quaternion::rotation_x(-wave + 1.0);
|
2019-04-12 22:19:19 +00:00
|
|
|
skeleton.r_foot.offset = Vec3::new(3.5, 1.0 + wave * 8.0, 3.5 - wave_dip * 4.0) / 11.0;
|
2019-03-05 00:00:11 +00:00
|
|
|
skeleton.r_foot.ori = Quaternion::rotation_x(wave + 1.0);
|
2019-01-14 14:40:22 +00:00
|
|
|
|
2019-03-05 00:00:11 +00:00
|
|
|
skeleton.back.offset = Vec3::new(-9.0, 5.0, 18.0);
|
|
|
|
skeleton.back.ori = Quaternion::rotation_y(2.5);
|
2019-04-12 22:19:19 +00:00
|
|
|
skeleton.back.scale = Vec3::one();
|
2019-01-14 14:40:22 +00:00
|
|
|
}
|
|
|
|
}
|