mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added anim_time to animations
Former-commit-id: 44ec8108c41a3cad74b6f3c0a2df02e5166a5487
This commit is contained in:
parent
2e3288cc29
commit
3705f9a871
@ -113,6 +113,7 @@ impl Character {
|
||||
pub struct AnimationHistory {
|
||||
pub last: Option<Animation>,
|
||||
pub current: Animation,
|
||||
pub time: f64,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
|
@ -10,6 +10,7 @@ use crate::{
|
||||
},
|
||||
terrain::TerrainMap,
|
||||
vol::{ReadVol, Vox},
|
||||
state::DeltaTime,
|
||||
};
|
||||
|
||||
// Basic ECS AI agent system
|
||||
@ -18,6 +19,7 @@ pub struct Sys;
|
||||
impl<'a> System<'a> for Sys {
|
||||
type SystemData = (
|
||||
ReadExpect<'a, TerrainMap>,
|
||||
Read<'a, DeltaTime>,
|
||||
Entities<'a>,
|
||||
ReadStorage<'a, Pos>,
|
||||
WriteStorage<'a, Vel>,
|
||||
@ -26,7 +28,7 @@ impl<'a> System<'a> for Sys {
|
||||
ReadStorage<'a, Control>,
|
||||
);
|
||||
|
||||
fn run(&mut self, (terrain, entities, pos, mut vels, mut dirs, mut anims, controls): Self::SystemData) {
|
||||
fn run(&mut self, (terrain, dt, entities, pos, mut vels, mut dirs, mut anims, controls): Self::SystemData) {
|
||||
for (entity, pos, mut vel, mut dir, control) in
|
||||
(&entities, &pos, &mut vels, &mut dirs, &controls).join()
|
||||
{
|
||||
@ -60,13 +62,22 @@ impl<'a> System<'a> for Sys {
|
||||
Animation::Jump
|
||||
};
|
||||
|
||||
let last_animation = anims.get_mut(entity).map(|h| h.current);
|
||||
let last_history = anims.get_mut(entity).cloned();
|
||||
|
||||
let time = if let Some((true, time)) = last_history
|
||||
.map(|last| (last.current == animation, last.time))
|
||||
{
|
||||
time + dt.0 as f64
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
anims.insert(
|
||||
entity,
|
||||
AnimationHistory {
|
||||
last: last_animation,
|
||||
last: last_history.map(|last| last.current),
|
||||
current: animation,
|
||||
time,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -137,6 +137,7 @@ impl Server {
|
||||
comp::AnimationHistory {
|
||||
last: None,
|
||||
current: Animation::Idle,
|
||||
time: 0.0,
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -13,15 +13,15 @@ impl Animation for IdleAnimation {
|
||||
type Skeleton = CharacterSkeleton;
|
||||
type Dependency = f64;
|
||||
|
||||
fn update_skeleton(skeleton: &Self::Skeleton, time: f64) -> Self::Skeleton {
|
||||
fn update_skeleton(skeleton: &Self::Skeleton, global_time: f64, anim_time: f64) -> Self::Skeleton {
|
||||
let mut next = (*skeleton).clone();
|
||||
|
||||
let wave = (time as f32 * 12.0).sin();
|
||||
let wavecos = (time as f32 * 12.0).cos();
|
||||
let wave_slow = (time as f32 * 6.0 + PI).sin();
|
||||
let wavecos_slow = (time as f32 * 6.0 + PI).cos();
|
||||
let waveultra_slow = (time as f32 * 1.0 + PI).sin();
|
||||
let waveultracos_slow = (time as f32 * 1.0 + PI).cos();
|
||||
let wave = (anim_time as f32 * 12.0).sin();
|
||||
let wavecos = (anim_time as f32 * 12.0).cos();
|
||||
let wave_slow = (anim_time as f32 * 6.0 + PI).sin();
|
||||
let wavecos_slow = (anim_time as f32 * 6.0 + PI).cos();
|
||||
let waveultra_slow = (anim_time as f32 * 1.0 + PI).sin();
|
||||
let waveultracos_slow = (anim_time as f32 * 1.0 + PI).cos();
|
||||
let wave_dip = (wave_slow.abs() - 0.5).abs();
|
||||
|
||||
next.head.offset = Vec3::new(5.5, 0.0, 12.0 + waveultra_slow * 0.4);
|
||||
|
@ -13,15 +13,15 @@ impl Animation for RunAnimation {
|
||||
type Skeleton = CharacterSkeleton;
|
||||
type Dependency = f64;
|
||||
|
||||
fn update_skeleton(skeleton: &Self::Skeleton, time: f64) -> Self::Skeleton {
|
||||
fn update_skeleton(skeleton: &Self::Skeleton, global_time: f64, anim_time: f64) -> Self::Skeleton {
|
||||
let mut next = (*skeleton).clone();
|
||||
|
||||
let wave = (time as f32 * 14.0).sin();
|
||||
let wave = (anim_time as f32 * 14.0).sin();
|
||||
let wavetest = (wave.cbrt());
|
||||
let fuzzwave = (time as f32 * 12.0).sin();
|
||||
let wavecos = (time as f32 * 14.0).cos();
|
||||
let wave_slow = (time as f32 * 7.0 + PI).sin();
|
||||
let wavecos_slow = (time as f32 * 8.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 * 7.0 + PI).sin();
|
||||
let wavecos_slow = (anim_time as f32 * 8.0 + PI).cos();
|
||||
let wave_dip = (wave_slow.abs() - 0.5).abs();
|
||||
|
||||
next.head.offset = Vec3::new(6.0, 0.0, 12.0 + wavecos * 1.3);
|
||||
|
@ -50,5 +50,5 @@ pub trait Animation {
|
||||
type Dependency;
|
||||
|
||||
/// Returns a new skeleton that is generated by the animation
|
||||
fn update_skeleton(skeleton: &Self::Skeleton, dependency: Self::Dependency) -> Self::Skeleton;
|
||||
fn update_skeleton(skeleton: &Self::Skeleton, dependency: Self::Dependency, anim_time: f64) -> Self::Skeleton;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use vek::*;
|
||||
const NEAR_PLANE: f32 = 0.1;
|
||||
const FAR_PLANE: f32 = 10000.0;
|
||||
|
||||
const INTERP_TIME: f32 = 0.2;
|
||||
const INTERP_TIME: f32 = 0.1;
|
||||
|
||||
pub struct Camera {
|
||||
tgt_focus: Vec3<f32>,
|
||||
|
@ -207,10 +207,10 @@ impl FigureCache {
|
||||
|
||||
let target_skeleton = match animation_history.current {
|
||||
comp::character::Animation::Idle => {
|
||||
IdleAnimation::update_skeleton(&mut state.skeleton, time)
|
||||
IdleAnimation::update_skeleton(&mut state.skeleton, time, animation_history.time)
|
||||
},
|
||||
comp::character::Animation::Run => {
|
||||
RunAnimation::update_skeleton(&mut state.skeleton, time)
|
||||
RunAnimation::update_skeleton(&mut state.skeleton, time, animation_history.time)
|
||||
},
|
||||
comp::character::Animation::Jump => {
|
||||
// TODO
|
||||
|
@ -115,7 +115,7 @@ impl Scene {
|
||||
.unwrap_or(Vec3::zero());
|
||||
|
||||
// Alter camera position to match player
|
||||
self.camera.set_focus_pos(player_pos + Vec3::unit_z() * 3.5);
|
||||
self.camera.set_focus_pos(player_pos + Vec3::unit_z() * 2.1);
|
||||
|
||||
// Tick camera for interpolation
|
||||
self.camera.update(client.state().get_time());
|
||||
|
Loading…
Reference in New Issue
Block a user