idle, run, jump animations

Former-commit-id: e476dc3aaf2197876c80eeba17837aee976f8df9
This commit is contained in:
jshipsey 2019-05-15 00:24:36 -04:00
parent 49cc422dfa
commit efc019f7a4
6 changed files with 178 additions and 26 deletions

BIN
assets/voxygen/voxel/pigchest.vox (Stored with Git LFS)

Binary file not shown.

View File

@ -0,0 +1,75 @@
// Standard
use std::{f32::consts::PI, ops::Mul};
// Library
use vek::*;
// Local
use super::{super::Animation, QuadrupedSkeleton, SCALE};
pub struct IdleAnimation;
impl Animation for IdleAnimation {
type Skeleton = QuadrupedSkeleton;
type Dependency = (f64);
fn update_skeleton(
skeleton: &Self::Skeleton,
global_time: Self::Dependency,
anim_time: f64,
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
let wave = (anim_time as f32 * 14.0).sin();
let wavetest = (wave.cbrt());
let waveultra_slow = (anim_time as f32 * 1.0 + PI).sin();
let waveultracos_slow = (anim_time as f32 * 1.0 + PI).cos();
let fuzzwave = (anim_time as f32 * 12.0).sin();
let wavecos = (anim_time as f32 * 14.0).cos();
let wave_slow = (anim_time as f32 * 3.5 + PI).sin();
let wavecos_slow = (anim_time as f32 * 3.5 + PI).cos();
let wave_dip = (wave_slow.abs() - 0.5).abs();
let pighead_look = Vec2::new(
((global_time + anim_time) as f32 / 8.0)
.floor()
.mul(7331.0)
.sin()
* 0.5,
((global_time + anim_time) as f32 / 8.0)
.floor()
.mul(1337.0)
.sin()
* 0.25,
);
next.pighead.offset = Vec3::new(0.0, 7.0, -1.5 + wave * 0.2) / 11.0;
next.pighead.ori = Quaternion::rotation_z(pighead_look.x) * Quaternion::rotation_x(pighead_look.y + wavecos_slow * 0.03);
next.pighead.scale = Vec3::one() / 10.5;
next.pigchest.offset = Vec3::new(wave_slow * 0.05, 0.0, 1.5 + wavecos_slow * 0.4) / 11.0;
next.pigchest.ori = Quaternion::rotation_y(wave_slow * 0.05);
next.pigchest.scale = Vec3::one() / 11.0;
next.piglf_leg.offset = Vec3::new(-4.5, 11.0, 1.5) / 11.0;
next.piglf_leg.ori = Quaternion::rotation_x(wave_slow * 0.08);
next.piglf_leg.scale = Vec3::one() / 11.0;
next.pigrf_leg.offset = Vec3::new(2.5, 11.0, 1.5) / 11.0;
next.pigrf_leg.ori = Quaternion::rotation_x(wavecos_slow * 0.08);
next.pigrf_leg.scale = Vec3::one() / 11.0;
next.piglb_leg.offset = Vec3::new(-4.5, 6.0, 1.5) / 11.0;
next.piglb_leg.ori = Quaternion::rotation_x(wavecos_slow * 0.08);
next.piglb_leg.scale = Vec3::one() / 11.0;
next.pigrb_leg.offset = Vec3::new(2.5, 6.0, 1.5) / 11.0;
next.pigrb_leg.ori = Quaternion::rotation_x(wave_slow * 0.08);
next.pigrb_leg.scale = Vec3::one() / 11.0;
next
}
}

View File

@ -0,0 +1,59 @@
// Standard
use std::f32::consts::PI;
// Library
use vek::*;
// Local
use super::{super::Animation, QuadrupedSkeleton, SCALE};
pub struct JumpAnimation;
impl Animation for JumpAnimation {
type Skeleton = QuadrupedSkeleton;
type Dependency = (f32, f64);
fn update_skeleton(
skeleton: &Self::Skeleton,
(velocity, global_time): Self::Dependency,
anim_time: f64,
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
let wave = (anim_time as f32 * 14.0).sin();
let wavetest = (wave.cbrt());
let fuzzwave = (anim_time as f32 * 12.0).sin();
let wavecos = (anim_time as f32 * 14.0).cos();
let wave_slow = (anim_time as f32 * 7.0 + PI).sin();
let wavecos_slow = (anim_time as f32 * 8.0 + PI).cos();
let wave_dip = (wave_slow.abs() - 0.5).abs();
let wave_stop = (anim_time as f32 * 4.5).min(PI / 2.0).sin();
next.pighead.offset = Vec3::new(0.0, 9.0, -1.5 ) / 11.0;
next.pighead.ori = Quaternion::rotation_x(wave_stop * 0.4);
next.pighead.scale = Vec3::one() / 10.5;
next.pigchest.offset = Vec3::new(0.0, 0.0, 1.5) / 11.0;
next.pigchest.ori = Quaternion::rotation_x(0.0);
next.pigchest.scale = Vec3::one() / 11.0;
next.piglf_leg.offset = Vec3::new(-4.5, 12.0, 1.5) / 11.0;
next.piglf_leg.ori = Quaternion::rotation_x(wave_stop * 0.6);
next.piglf_leg.scale = Vec3::one() / 11.0;
next.pigrf_leg.offset = Vec3::new(2.5, 12.0, 1.5) / 11.0;
next.pigrf_leg.ori = Quaternion::rotation_x(wave_stop * 0.6 - wave_slow * 0.3);
next.pigrf_leg.scale = Vec3::one() / 11.0;
next.piglb_leg.offset = Vec3::new(-4.5, 5.0, 2.0) / 11.0;
next.piglb_leg.ori = Quaternion::rotation_x(wave_stop * -0.6 + wave_slow * 0.3);
next.piglb_leg.scale = Vec3::one() / 11.0;
next.pigrb_leg.offset = Vec3::new(2.5, 5.0, 2.0) / 11.0;
next.pigrb_leg.ori = Quaternion::rotation_x(wave_stop * -0.6 + wave_slow * 0.3);
next.pigrb_leg.scale = Vec3::one() / 11.0;
next
}
}

View File

@ -1,8 +1,14 @@
pub mod run; pub mod run;
pub mod idle;
pub mod jump;
// Reexports // Reexports
pub use self::run::RunAnimation; pub use self::run::RunAnimation;
pub use self::idle::IdleAnimation;
pub use self::jump::JumpAnimation;
// Crate // Crate
use crate::render::FigureBoneData; use crate::render::FigureBoneData;

View File

@ -21,6 +21,8 @@ impl Animation for RunAnimation {
let mut next = (*skeleton).clone(); let mut next = (*skeleton).clone();
let wave = (anim_time as f32 * 14.0).sin(); let wave = (anim_time as f32 * 14.0).sin();
let wavequick = (anim_time as f32 * 20.0).sin();
let wavequickcos = (anim_time as f32 * 20.0).cos();
let wavetest = (wave.cbrt()); let wavetest = (wave.cbrt());
let fuzzwave = (anim_time as f32 * 12.0).sin(); let fuzzwave = (anim_time as f32 * 12.0).sin();
let wavecos = (anim_time as f32 * 14.0).cos(); let wavecos = (anim_time as f32 * 14.0).cos();
@ -28,29 +30,29 @@ impl Animation for RunAnimation {
let wavecos_slow = (anim_time as f32 * 8.0 + PI).cos(); let wavecos_slow = (anim_time as f32 * 8.0 + PI).cos();
let wave_dip = (wave_slow.abs() - 0.5).abs(); let wave_dip = (wave_slow.abs() - 0.5).abs();
next.pighead.offset = Vec3::new(5.5, 2.0, 11.0 + wavecos * 1.3); next.pighead.offset = Vec3::new(0.0, 9.0, -1.5 + wave * 1.5) / 11.0;
next.pighead.ori = Quaternion::rotation_x(0.15); next.pighead.ori = Quaternion::rotation_x(0.2 + wave * 0.05) * Quaternion::rotation_y(wavecos * 0.03);
next.pighead.scale = Vec3::one(); next.pighead.scale = Vec3::one() / 10.5;
next.pigchest.offset = Vec3::new(5.5, 0.0, 7.0 + wavecos * 1.1); next.pigchest.offset = Vec3::new(0.0, 0.0, 1.5 + wavecos * 1.2) / 11.0;
next.pigchest.ori = Quaternion::rotation_z(wave * 0.1); next.pigchest.ori = Quaternion::rotation_x(wave * 0.1);
next.pigchest.scale = Vec3::one(); next.pigchest.scale = Vec3::one() / 11.0;
next.piglf_leg.offset = Vec3::new(5.5, 0.0, 5.0 + wavecos * 1.1); next.piglf_leg.offset = Vec3::new(-4.5, 11.0 + wavequick * 0.8, 2.5 + wavequickcos * 1.5) / 11.0;
next.piglf_leg.ori = Quaternion::rotation_z(wave * 0.25); next.piglf_leg.ori = Quaternion::rotation_x(wavequick * 0.3);
next.piglf_leg.scale = Vec3::one(); next.piglf_leg.scale = Vec3::one() / 11.0;
next.pigrf_leg.offset = Vec3::new(5.5, 0.0, 2.0 + wavecos * 1.1); next.pigrf_leg.offset = Vec3::new(2.5, 11.0 - wavequickcos * 0.8, 2.5 + wavequick * 1.5) / 11.0;
next.pigrf_leg.ori = Quaternion::rotation_z(wave * 0.6); next.pigrf_leg.ori = Quaternion::rotation_x(wavequickcos * -0.3);
next.pigrf_leg.scale = Vec3::one(); next.pigrf_leg.scale = Vec3::one() / 11.0;
next.piglb_leg.offset = Vec3::new(-6.0, 0.0 + wavecos * 2.5, 11.0 - wave * 1.5); next.piglb_leg.offset = Vec3::new(-4.5, 6.0 - wavequickcos * 0.8, 2.5 + wavequick * 1.5) / 11.0;
next.piglb_leg.ori = Quaternion::rotation_x(wavecos * 0.9); next.piglb_leg.ori = Quaternion::rotation_x(wavequickcos * -0.3);
next.piglb_leg.scale = Vec3::one(); next.piglb_leg.scale = Vec3::one() / 11.0;
next.pigrb_leg.offset = Vec3::new(9.0, 0.0 - wavecos * 2.5, 11.0 + wave * 1.5); next.pigrb_leg.offset = Vec3::new(2.5, 6.0 + wavequick * 0.8, 2.5 + wavequickcos * 1.5) / 11.0;
next.pigrb_leg.ori = Quaternion::rotation_x(wavecos * -0.9); next.pigrb_leg.ori = Quaternion::rotation_x(wavequick * 0.3);
next.pigrb_leg.scale = Vec3::one(); next.pigrb_leg.scale = Vec3::one() / 11.0;
next next
} }

View File

@ -243,7 +243,7 @@ impl FigureModelCache {
match pighead { match pighead {
Pighead::Default => "pighead.vox", Pighead::Default => "pighead.vox",
}, },
Vec3::new(0.0, 5.0, 0.0), Vec3::new(-6.0, 4.5, 3.0),
) )
} }
@ -252,7 +252,7 @@ impl FigureModelCache {
match pigchest { match pigchest {
Pigchest::Default => "pigchest.vox", Pigchest::Default => "pigchest.vox",
}, },
Vec3::new(0.0, 0.0, 0.0), Vec3::new(-5.0, 4.5, 0.0),
) )
} }
@ -261,7 +261,7 @@ impl FigureModelCache {
match pigleg_l { match pigleg_l {
Pigleg_l::Default => "pigleg_l.vox", Pigleg_l::Default => "pigleg_l.vox",
}, },
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, -1.0, -1.5),
) )
} }
@ -270,7 +270,7 @@ impl FigureModelCache {
match pigleg_r { match pigleg_r {
Pigleg_r::Default => "pigleg_r.vox", Pigleg_r::Default => "pigleg_r.vox",
}, },
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, -1.0, -1.5),
) )
} }
@ -279,7 +279,7 @@ impl FigureModelCache {
match pigleg_l { match pigleg_l {
Pigleg_l::Default => "pigleg_l.vox", Pigleg_l::Default => "pigleg_l.vox",
}, },
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, -1.0, -1.5),
) )
} }
@ -288,7 +288,7 @@ impl FigureModelCache {
match pigleg_r { match pigleg_r {
Pigleg_r::Default => "pigleg_r.vox", Pigleg_r::Default => "pigleg_r.vox",
}, },
Vec3::new(0.0, 0.0, 0.0), Vec3::new(0.0, -1.0, -1.5),
) )
} }
} }
@ -366,6 +366,16 @@ impl FigureMgr {
(vel.0.magnitude(), time), (vel.0.magnitude(), time),
animation_history.time, animation_history.time,
), ),
comp::Animation::Idle => quadruped::IdleAnimation::update_skeleton(
state.skeleton_mut(),
time,
animation_history.time,
),
comp::Animation::Jump => quadruped::JumpAnimation::update_skeleton(
state.skeleton_mut(),
(vel.0.magnitude(), time),
animation_history.time,
),
// TODO! // TODO!
_ => state.skeleton_mut().clone(), _ => state.skeleton_mut().clone(),
}; };