From e674424974b246d2ec9640fb92abece0edd26ca8 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Fri, 23 Aug 2019 22:50:35 +0200 Subject: [PATCH 01/16] Allow non player entites to be removed again --- server/src/lib.rs | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/server/src/lib.rs b/server/src/lib.rs index 0be77d38d9..52c7fc7cd4 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -243,6 +243,8 @@ impl Server { let state = &mut self.state; let clients = &mut self.clients; + let mut todo_remove = None; + match event { ServerEvent::Explosion { pos, radius } => { const RAYS: usize = 500; @@ -306,23 +308,21 @@ impl Server { clients.notify_registered(ServerMsg::kill(msg)); } - { - // Give EXP to the client - let mut stats = ecs.write_storage::(); + // Give EXP to the client + let mut stats = ecs.write_storage::(); - if let Some(entity_stats) = stats.get(entity).cloned() { - if let comp::HealthSource::Attack { by } = cause { - ecs.entity_from_uid(by.into()).map(|attacker| { - if let Some(attacker_stats) = stats.get_mut(attacker) { - // TODO: Discuss whether we should give EXP by Player Killing or not. - attacker_stats.exp.change_by( - (entity_stats.health.maximum() as f64 / 10.0 - + entity_stats.level.level() as f64 * 10.0) - as i64, - ); - } - }); - } + if let Some(entity_stats) = stats.get(entity).cloned() { + if let comp::HealthSource::Attack { by } = cause { + ecs.entity_from_uid(by.into()).map(|attacker| { + if let Some(attacker_stats) = stats.get_mut(attacker) { + // TODO: Discuss whether we should give EXP by Player Killing or not. + attacker_stats.exp.change_by( + (entity_stats.health.maximum() as f64 / 10.0 + + entity_stats.level.level() as f64 * 10.0) + as i64, + ); + } + }); } } @@ -331,7 +331,7 @@ impl Server { let _ = ecs.write_storage().insert(entity, comp::ForceUpdate); client.force_state(ClientState::Dead); } else { - let _ = state.ecs_mut().delete_entity_synced(entity); + todo_remove = Some(entity.clone()); } } @@ -356,6 +356,10 @@ impl Server { } } } + + if let Some(entity) = todo_remove { + let _ = state.ecs_mut().delete_entity_synced(entity); + } } } From 637b4642d8cf3466132c85b39ad6bb2ea506b0b6 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Mon, 26 Aug 2019 00:22:43 +0200 Subject: [PATCH 02/16] Split animations --- client/src/lib.rs | 22 ++- voxygen/src/scene/figure.rs | 311 +++++++++++++++++++----------------- 2 files changed, 182 insertions(+), 151 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 285017027f..6c2bbf8f3e 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -282,7 +282,26 @@ impl Client { // Handle new messages from the server. frontend_events.append(&mut self.handle_new_messages()?); - // 3) + // 3) Update client local data + { + let ecs = self.state.ecs_mut(); + for (entity, _) in (&ecs.entities(), &ecs.read_storage::()).join() { + let mut last_character_state = + ecs.write_storage::>(); + if let Some(client_character_state) = + ecs.read_storage::().get(entity) + { + if last_character_state + .get(entity) + .map(|&l| l != *client_character_state) + .unwrap_or(true) + { + let _ = last_character_state + .insert(entity, comp::Last(*client_character_state)); + } + } + } + } // 4) Tick the client's LocalState self.state.tick(dt); @@ -395,7 +414,6 @@ impl Client { } // 7) Finish the tick, pass control back to the frontend. - self.tick += 1; Ok(frontend_events) } diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 4c457d93a6..f6551a04df 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -1,7 +1,7 @@ use crate::{ anim::{ self, character::CharacterSkeleton, object::ObjectSkeleton, quadruped::QuadrupedSkeleton, - quadrupedmedium::QuadrupedMediumSkeleton, Animation, Skeleton, SkeletonAttr, + quadrupedmedium::QuadrupedMediumSkeleton, Animation as _, Skeleton, SkeletonAttr, }, mesh::Meshable, render::{ @@ -13,7 +13,9 @@ use client::Client; use common::{ assets, comp::{ - self, humanoid, item::Tool, object, quadruped, quadruped_medium, Body, Equipment, Item, + + self, humanoid, item::Tool, object, quadruped, quadruped_medium, Body, Equipment, Item, ActionState::*, Animation, Body, + CharacterState, Last, MovementState::*, Ori, Pos, Scale, Stats, Vel, }, figure::Segment, terrain::TerrainChunkSize, @@ -23,7 +25,7 @@ use dot_vox::DotVoxData; use hashbrown::HashMap; use log::debug; use specs::{Entity as EcsEntity, Join}; -use std::f32; +use std::{f32, time::Instant}; use vek::*; const DAMAGE_FADE_COEFFICIENT: f64 = 5.0; @@ -618,19 +620,20 @@ impl FigureMgr { let dt = client.state().get_delta_time(); // Get player position. let player_pos = ecs - .read_storage::() + .read_storage::() .get(client.entity()) .map_or(Vec3::zero(), |pos| pos.0); - for (entity, pos, vel, ori, scale, body, animation_info, stats) in ( + for (entity, pos, vel, ori, scale, body, character, last_character, stats) in ( &ecs.entities(), - &ecs.read_storage::(), - &ecs.read_storage::(), - &ecs.read_storage::(), - ecs.read_storage::().maybe(), - &ecs.read_storage::(), - ecs.read_storage::().maybe(), - ecs.read_storage::().maybe(), + &ecs.read_storage::(), + &ecs.read_storage::(), + &ecs.read_storage::(), + ecs.read_storage::().maybe(), + &ecs.read_storage::(), + ecs.read_storage::().maybe(), + ecs.read_storage::>().maybe(), + ecs.read_storage::().maybe(), ) .join() { @@ -683,80 +686,84 @@ impl FigureMgr { .character_states .entry(entity) .or_insert_with(|| FigureState::new(renderer, CharacterSkeleton::new())); - - let animation_info = match animation_info { - Some(a_i) => a_i, - None => continue, + let (character, last_character) = match (character, last_character) { + (Some(c), Some(l)) => (c, l), + _ => continue, }; - let target_skeleton = match animation_info.animation { - comp::Animation::Idle => anim::character::IdleAnimation::update_skeleton( - state.skeleton_mut(), - time, - animation_info.time, - skeleton_attr, - ), - comp::Animation::Run => anim::character::RunAnimation::update_skeleton( - state.skeleton_mut(), - (vel.0.magnitude(), time), - animation_info.time, - skeleton_attr, - ), - comp::Animation::Jump => anim::character::JumpAnimation::update_skeleton( - state.skeleton_mut(), - time, - animation_info.time, - skeleton_attr, - ), - comp::Animation::Attack => { - anim::character::AttackAnimation::update_skeleton( - state.skeleton_mut(), - time, - animation_info.time, - skeleton_attr, - ) - } - comp::Animation::Block => anim::character::BlockAnimation::update_skeleton( - state.skeleton_mut(), - time, - animation_info.time, - skeleton_attr, - ), - comp::Animation::Cjump => anim::character::CjumpAnimation::update_skeleton( - state.skeleton_mut(), - time, - animation_info.time, - skeleton_attr, - ), - comp::Animation::Roll => anim::character::RollAnimation::update_skeleton( - state.skeleton_mut(), - time, - animation_info.time, - skeleton_attr, - ), - comp::Animation::Crun => anim::character::CrunAnimation::update_skeleton( - state.skeleton_mut(), - (vel.0.magnitude(), time), - animation_info.time, - skeleton_attr, - ), - comp::Animation::Cidle => anim::character::CidleAnimation::update_skeleton( - state.skeleton_mut(), - time, - animation_info.time, - skeleton_attr, - ), - comp::Animation::Gliding => { - anim::character::GlidingAnimation::update_skeleton( - state.skeleton_mut(), - (vel.0.magnitude(), time), - animation_info.time, - skeleton_attr, - ) - } - }; + if last_character.0.movement != character.movement { + state.last_movement_change = Instant::now(); + } + if last_character.0.action != character.action { + state.last_action_change = Instant::now(); + } + + let time_since_movement_change = + state.last_movement_change.elapsed().as_secs_f64(); + let time_since_action_change = state.last_action_change.elapsed().as_secs_f64(); + + let target_movement = match &character.movement { + Stand => anim::character::IdleAnimation::update_skeleton( + state.skeleton_mut(), + time, + time_since_movement_change, + skeleton_attr, + ), + Run => anim::character::RunAnimation::update_skeleton( + state.skeleton_mut(), + (vel.0.magnitude(), time), + time_since_movement_change, + skeleton_attr, + ), + Jump => anim::character::JumpAnimation::update_skeleton( + state.skeleton_mut(), + time, + time_since_movement_change, + skeleton_attr, + ), + Roll { .. } => anim::character::RollAnimation::update_skeleton( + state.skeleton_mut(), + time, + time_since_movement_change, + skeleton_attr, + ), + Glide => anim::character::GlidingAnimation::update_skeleton( + state.skeleton_mut(), + (vel.0.magnitude(), time), + time_since_movement_change, + skeleton_attr, + ), + }; + state.skeleton.interpolate(&target_movement, dt); + + let target_action = match &character.action { + Idle => anim::character::IdleAnimation::update_skeleton( + state.skeleton_mut(), + time, + time_since_action_change, + skeleton_attr, + ), + Wield { .. } => anim::character::CidleAnimation::update_skeleton( + state.skeleton_mut(), + time, + time_since_action_change, + skeleton_attr, + ), + Attack { .. } => anim::character::AttackAnimation::update_skeleton( + state.skeleton_mut(), + time, + time_since_action_change, + skeleton_attr, + ), + Block { .. } => anim::character::BlockAnimation::update_skeleton( + state.skeleton_mut(), + time, + time_since_action_change, + skeleton_attr, + ), + }; + state.skeleton.interpolate(&target_action, dt); - state.skeleton.interpolate(&target_skeleton, dt); state.update(renderer, pos.0, ori.0, scale, col, dt); } Body::Quadruped(_) => { @@ -765,42 +772,43 @@ impl FigureMgr { .entry(entity) .or_insert_with(|| FigureState::new(renderer, QuadrupedSkeleton::new())); - let animation_info = match animation_info { - Some(a_i) => a_i, - None => continue, + let (character, last_character) = match (character, last_character) { + (Some(c), Some(l)) => (c, l), + _ => continue, }; - let target_skeleton = match animation_info.animation { - comp::Animation::Run | comp::Animation::Crun => { - anim::quadruped::RunAnimation::update_skeleton( - state.skeleton_mut(), - (vel.0.magnitude(), time), - animation_info.time, - skeleton_attr, - ) - } - comp::Animation::Idle | comp::Animation::Cidle => { - anim::quadruped::IdleAnimation::update_skeleton( - state.skeleton_mut(), - time, - animation_info.time, - skeleton_attr, - ) - } - comp::Animation::Jump | comp::Animation::Cjump => { - anim::quadruped::JumpAnimation::update_skeleton( - state.skeleton_mut(), - (vel.0.magnitude(), time), - animation_info.time, - skeleton_attr, - ) - } + if last_character.0.movement != character.movement { + state.last_movement_change = Instant::now(); + } + + let time_since_movement_change = + state.last_movement_change.elapsed().as_secs_f64(); + + let target_movement = match character.movement { + Stand => anim::quadruped::IdleAnimation::update_skeleton( + state.skeleton_mut(), + time, + time_since_movement_change, + skeleton_attr, + ), + Run => anim::quadruped::RunAnimation::update_skeleton( + state.skeleton_mut(), + (vel.0.magnitude(), time), + time_since_movement_change, + skeleton_attr, + ), + Jump => anim::quadruped::JumpAnimation::update_skeleton( + state.skeleton_mut(), + (vel.0.magnitude(), time), + time_since_movement_change, + skeleton_attr, + ), // TODO! _ => state.skeleton_mut().clone(), }; - state.skeleton.interpolate(&target_skeleton, dt); + state.skeleton.interpolate(&target_movement, dt); state.update(renderer, pos.0, ori.0, scale, col, dt); } Body::QuadrupedMedium(_) => { @@ -811,42 +819,43 @@ impl FigureMgr { FigureState::new(renderer, QuadrupedMediumSkeleton::new()) }); - let animation_info = match animation_info { - Some(a_i) => a_i, - None => continue, + let (character, last_character) = match (character, last_character) { + (Some(c), Some(l)) => (c, l), + _ => continue, }; - let target_skeleton = match animation_info.animation { - comp::Animation::Run | comp::Animation::Crun => { - anim::quadrupedmedium::RunAnimation::update_skeleton( - state.skeleton_mut(), - (vel.0.magnitude(), time), - animation_info.time, - skeleton_attr, - ) - } - comp::Animation::Idle | comp::Animation::Cidle => { - anim::quadrupedmedium::IdleAnimation::update_skeleton( - state.skeleton_mut(), - time, - animation_info.time, - skeleton_attr, - ) - } - comp::Animation::Jump | comp::Animation::Cjump => { - anim::quadrupedmedium::JumpAnimation::update_skeleton( - state.skeleton_mut(), - (vel.0.magnitude(), time), - animation_info.time, - skeleton_attr, - ) - } + if last_character.0.movement != character.movement { + state.last_movement_change = Instant::now(); + } + + let time_since_movement_change = + state.last_movement_change.elapsed().as_secs_f64(); + + let target_movement = match character.movement { + Stand => anim::quadrupedmedium::IdleAnimation::update_skeleton( + state.skeleton_mut(), + time, + time_since_movement_change, + skeleton_attr, + ), + Run => anim::quadrupedmedium::RunAnimation::update_skeleton( + state.skeleton_mut(), + (vel.0.magnitude(), time), + time_since_movement_change, + skeleton_attr, + ), + Jump => anim::quadrupedmedium::JumpAnimation::update_skeleton( + state.skeleton_mut(), + (vel.0.magnitude(), time), + time_since_movement_change, + skeleton_attr, + ), // TODO! _ => state.skeleton_mut().clone(), }; - state.skeleton.interpolate(&target_skeleton, dt); + state.skeleton.interpolate(&target_movement, dt); state.update(renderer, pos.0, ori.0, scale, col, dt); } Body::Object(_) => { @@ -887,12 +896,12 @@ impl FigureMgr { for (entity, _, _, _, body, stats, _) in ( &ecs.entities(), - &ecs.read_storage::(), - &ecs.read_storage::(), - &ecs.read_storage::(), - &ecs.read_storage::(), - ecs.read_storage::().maybe(), - ecs.read_storage::().maybe(), + &ecs.read_storage::(), + &ecs.read_storage::(), + &ecs.read_storage::(), + &ecs.read_storage::(), + ecs.read_storage::().maybe(), + ecs.read_storage::().maybe(), ) .join() // Don't render figures outside of frustum (camera viewport, max draw distance is farplane) @@ -901,7 +910,7 @@ impl FigureMgr { &pos.0.x, &pos.0.y, &pos.0.z, - &(scale.unwrap_or(&comp::Scale(1.0)).0 * 2.0), + &(scale.unwrap_or(&Scale(1.0)).0 * 2.0), ) }) // Don't render dead entities @@ -934,7 +943,7 @@ impl FigureMgr { if camera.get_mode() == CameraMode::FirstPerson && client .state() - .read_storage::() + .read_storage::() .get(client.entity()) .is_some() && entity == client.entity() @@ -953,6 +962,8 @@ impl FigureMgr { pub struct FigureState { bone_consts: Consts, locals: Consts, + last_movement_change: Instant, + last_action_change: Instant, skeleton: S, pos: Vec3, ori: Vec3, @@ -965,6 +976,8 @@ impl FigureState { .create_consts(&skeleton.compute_matrices()) .unwrap(), locals: renderer.create_consts(&[FigureLocals::default()]).unwrap(), + last_movement_change: Instant::now(), + last_action_change: Instant::now(), skeleton, pos: Vec3::zero(), ori: Vec3::zero(), From e6197d4c10ec67b8f3fe05aaebd5a50f5db3a910 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Mon, 26 Aug 2019 01:18:19 -0400 Subject: [PATCH 03/16] separate static anims for feet (run/static) --- common/src/comp/animation.rs | 2 + common/src/sys/animation.rs | 6 +- voxygen/src/anim/character/idle.rs | 8 --- voxygen/src/anim/character/lean.rs | 107 ++++++++++++++++++++++++++++ voxygen/src/anim/character/mod.rs | 4 ++ voxygen/src/anim/character/run.rs | 78 +------------------- voxygen/src/anim/character/stand.rs | 36 ++++++++++ voxygen/src/scene/figure.rs | 7 +- 8 files changed, 158 insertions(+), 90 deletions(-) create mode 100644 voxygen/src/anim/character/lean.rs create mode 100644 voxygen/src/anim/character/stand.rs diff --git a/common/src/comp/animation.rs b/common/src/comp/animation.rs index ee4fc69da4..001d292059 100644 --- a/common/src/comp/animation.rs +++ b/common/src/comp/animation.rs @@ -4,7 +4,9 @@ use specs_idvs::IDVStorage; #[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum Animation { Idle, + Stand, Run, + Lean, Jump, Gliding, Attack, diff --git a/common/src/sys/animation.rs b/common/src/sys/animation.rs index fde92932c3..3bc916fc5c 100644 --- a/common/src/sys/animation.rs +++ b/common/src/sys/animation.rs @@ -33,8 +33,10 @@ impl<'a> System<'a> for Sys { let animation = match (physics.on_ground, &character.movement, &character.action) { (_, Roll { .. }, Idle) => Animation::Roll, - (true, Stand, Idle) => Animation::Idle, - (true, Run, Idle) => Animation::Run, + (true, Stand, _) => Animation::Stand, //if standing still, legs still + (true, Stand, Idle) => Animation::Idle, //if standing still and not acting, idle the body + (true, Run, _) => Animation::Run, //if running, legs run + (true, Run, Idle) => Animation::Lean, //if running and not acting, lean the body (false, Jump, Idle) => Animation::Jump, (true, Stand, Wield { .. }) => Animation::Cidle, (true, Run, Wield { .. }) => Animation::Crun, diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index f5ab828a78..dae68319fb 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -75,14 +75,6 @@ impl Animation for IdleAnimation { next.r_hand.ori = Quaternion::rotation_x(0.0 + wave_ultra_slow * -0.06); next.r_hand.scale = Vec3::one(); - next.l_foot.offset = Vec3::new(-3.4, -0.1, 8.0); - next.l_foot.ori = Quaternion::identity(); - next.l_foot.scale = Vec3::one(); - - next.r_foot.offset = Vec3::new(3.4, -0.1, 8.0); - next.r_foot.ori = Quaternion::identity(); - next.r_foot.scale = Vec3::one(); - next.weapon.offset = Vec3::new( -7.0 + skeleton_attr.weapon_x, -5.0 + skeleton_attr.weapon_y, diff --git a/voxygen/src/anim/character/lean.rs b/voxygen/src/anim/character/lean.rs new file mode 100644 index 0000000000..1d60609225 --- /dev/null +++ b/voxygen/src/anim/character/lean.rs @@ -0,0 +1,107 @@ +use super::{ + super::{Animation, SkeletonAttr}, + CharacterSkeleton, +}; +use std::f32::consts::PI; +use std::ops::Mul; +use vek::*; + +pub struct LeanAnimation; + +impl Animation for LeanAnimation { + type Skeleton = CharacterSkeleton; + type Dependency = (f32, f64); + + fn update_skeleton( + skeleton: &Self::Skeleton, + (velocity, global_time): Self::Dependency, + anim_time: f64, + skeleton_attr: &SkeletonAttr, + ) -> Self::Skeleton { + let mut next = (*skeleton).clone(); + + let wave = (anim_time as f32 * 12.0).sin(); + let wave_cos = (anim_time as f32 * 12.0).cos(); + let wave_diff = (anim_time as f32 * 12.0 + PI / 2.0).sin(); + let wave_cos_dub = (anim_time as f32 * 24.0).cos(); + let wave_stop = (anim_time as f32 * 2.6).min(PI / 2.0).sin(); + + let head_look = Vec2::new( + ((global_time + anim_time) as f32 / 2.0) + .floor() + .mul(7331.0) + .sin() + * 0.2, + ((global_time + anim_time) as f32 / 2.0) + .floor() + .mul(1337.0) + .sin() + * 0.1, + ); + + next.head.offset = Vec3::new( + 0.0, + -1.0 + skeleton_attr.neck_forward, + skeleton_attr.neck_height + 15.0 + wave_cos * 1.3, + ); + next.head.ori = Quaternion::rotation_z(head_look.x + wave * 0.1) + * Quaternion::rotation_x(head_look.y + 0.35); + next.head.scale = Vec3::one() * skeleton_attr.head_scale; + + next.chest.offset = Vec3::new(0.0, 0.0, 7.0 + wave_cos * 1.1); + next.chest.ori = Quaternion::rotation_z(wave * 0.2); + next.chest.scale = Vec3::one(); + + next.belt.offset = Vec3::new(0.0, 0.0, 5.0 + wave_cos * 1.1); + next.belt.ori = Quaternion::rotation_z(wave * 0.35); + next.belt.scale = Vec3::one(); + + next.shorts.offset = Vec3::new(0.0, 0.0, 2.0 + wave_cos * 1.1); + next.shorts.ori = Quaternion::rotation_z(wave * 0.6); + next.shorts.scale = Vec3::one(); + + next.l_hand.offset = Vec3::new( + -7.5 + wave_cos_dub * 1.0, + 2.0 + wave_cos * 5.0, + 0.0 - wave * 1.5, + ); + next.l_hand.ori = Quaternion::rotation_x(wave_cos * 0.8); + next.l_hand.scale = Vec3::one(); + + next.r_hand.offset = Vec3::new( + 7.5 - wave_cos_dub * 1.0, + 2.0 - wave_cos * 5.0, + 0.0 + wave * 1.5, + ); + next.r_hand.ori = Quaternion::rotation_x(wave_cos * -0.8); + next.r_hand.scale = Vec3::one(); + + next.weapon.offset = Vec3::new( + -7.0 + skeleton_attr.weapon_x, + -5.0 + skeleton_attr.weapon_y, + 15.0, + ); + next.weapon.ori = + Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57 + wave_cos * 0.25); + next.weapon.scale = Vec3::one(); + + next.l_shoulder.offset = Vec3::new(-5.0, 0.0, 4.7); + next.l_shoulder.ori = Quaternion::rotation_x(wave_cos * 0.15); + next.l_shoulder.scale = Vec3::one() * 1.1; + + next.r_shoulder.offset = Vec3::new(5.0, 0.0, 4.7); + next.r_shoulder.ori = Quaternion::rotation_x(wave * 0.15); + next.r_shoulder.scale = Vec3::one() * 1.1; + + next.draw.offset = Vec3::new(0.0, 5.0, 0.0); + next.draw.ori = Quaternion::rotation_y(0.0); + next.draw.scale = Vec3::one() * 0.0; + + next.torso.offset = Vec3::new(0.0, -0.2 + wave * -0.08, 0.4) * skeleton_attr.scaler; + next.torso.ori = + Quaternion::rotation_x(wave_stop * velocity * -0.06 + wave_diff * velocity * -0.005); + next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; + + next + } +} diff --git a/voxygen/src/anim/character/mod.rs b/voxygen/src/anim/character/mod.rs index 138ca93a2b..0837dcb881 100644 --- a/voxygen/src/anim/character/mod.rs +++ b/voxygen/src/anim/character/mod.rs @@ -5,9 +5,11 @@ pub mod cjump; pub mod crun; pub mod gliding; pub mod idle; +pub mod stand; pub mod jump; pub mod roll; pub mod run; +pub mod lean; // Reexports pub use self::attack::AttackAnimation; @@ -17,9 +19,11 @@ pub use self::cjump::CjumpAnimation; pub use self::crun::CrunAnimation; pub use self::gliding::GlidingAnimation; pub use self::idle::IdleAnimation; +pub use self::stand::StandAnimation; pub use self::jump::JumpAnimation; pub use self::roll::RollAnimation; pub use self::run::RunAnimation; +pub use self::lean::LeanAnimation; use super::{Bone, Skeleton}; use crate::render::FigureBoneData; diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index be4d9c802a..2a646a8c98 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -26,56 +26,6 @@ impl Animation for RunAnimation { let wave_cos_dub = (anim_time as f32 * 24.0).cos(); let wave_stop = (anim_time as f32 * 2.6).min(PI / 2.0).sin(); - let head_look = Vec2::new( - ((global_time + anim_time) as f32 / 2.0) - .floor() - .mul(7331.0) - .sin() - * 0.2, - ((global_time + anim_time) as f32 / 2.0) - .floor() - .mul(1337.0) - .sin() - * 0.1, - ); - - next.head.offset = Vec3::new( - 0.0, - -1.0 + skeleton_attr.neck_forward, - skeleton_attr.neck_height + 15.0 + wave_cos * 1.3, - ); - next.head.ori = Quaternion::rotation_z(head_look.x + wave * 0.1) - * Quaternion::rotation_x(head_look.y + 0.35); - next.head.scale = Vec3::one() * skeleton_attr.head_scale; - - next.chest.offset = Vec3::new(0.0, 0.0, 7.0 + wave_cos * 1.1); - next.chest.ori = Quaternion::rotation_z(wave * 0.2); - next.chest.scale = Vec3::one(); - - next.belt.offset = Vec3::new(0.0, 0.0, 5.0 + wave_cos * 1.1); - next.belt.ori = Quaternion::rotation_z(wave * 0.35); - next.belt.scale = Vec3::one(); - - next.shorts.offset = Vec3::new(0.0, 0.0, 2.0 + wave_cos * 1.1); - next.shorts.ori = Quaternion::rotation_z(wave * 0.6); - next.shorts.scale = Vec3::one(); - - next.l_hand.offset = Vec3::new( - -7.5 + wave_cos_dub * 1.0, - 2.0 + wave_cos * 5.0, - 0.0 - wave * 1.5, - ); - next.l_hand.ori = Quaternion::rotation_x(wave_cos * 0.8); - next.l_hand.scale = Vec3::one(); - - next.r_hand.offset = Vec3::new( - 7.5 - wave_cos_dub * 1.0, - 2.0 - wave_cos * 5.0, - 0.0 + wave * 1.5, - ); - next.r_hand.ori = Quaternion::rotation_x(wave_cos * -0.8); - next.r_hand.scale = Vec3::one(); - next.l_foot.offset = Vec3::new(-3.4, 0.0 + wave_cos * 1.0, 6.0 - wave_cos_dub * 0.7); next.l_foot.ori = Quaternion::rotation_x(-0.0 - wave_cos * 1.5); next.l_foot.scale = Vec3::one(); @@ -83,33 +33,7 @@ impl Animation for RunAnimation { next.r_foot.offset = Vec3::new(3.4, 0.0 - wave_cos * 1.0, 6.0 - wave_cos_dub * 0.7); next.r_foot.ori = Quaternion::rotation_x(-0.0 + wave_cos * 1.5); next.r_foot.scale = Vec3::one(); - - next.weapon.offset = Vec3::new( - -7.0 + skeleton_attr.weapon_x, - -5.0 + skeleton_attr.weapon_y, - 15.0, - ); - next.weapon.ori = - Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57 + wave_cos * 0.25); - next.weapon.scale = Vec3::one(); - - next.l_shoulder.offset = Vec3::new(-5.0, 0.0, 4.7); - next.l_shoulder.ori = Quaternion::rotation_x(wave_cos * 0.15); - next.l_shoulder.scale = Vec3::one() * 1.1; - - next.r_shoulder.offset = Vec3::new(5.0, 0.0, 4.7); - next.r_shoulder.ori = Quaternion::rotation_x(wave * 0.15); - next.r_shoulder.scale = Vec3::one() * 1.1; - - next.draw.offset = Vec3::new(0.0, 5.0, 0.0); - next.draw.ori = Quaternion::rotation_y(0.0); - next.draw.scale = Vec3::one() * 0.0; - - next.torso.offset = Vec3::new(0.0, -0.2 + wave * -0.08, 0.4) * skeleton_attr.scaler; - next.torso.ori = - Quaternion::rotation_x(wave_stop * velocity * -0.06 + wave_diff * velocity * -0.005); - next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; - + next } } diff --git a/voxygen/src/anim/character/stand.rs b/voxygen/src/anim/character/stand.rs new file mode 100644 index 0000000000..a542690c0f --- /dev/null +++ b/voxygen/src/anim/character/stand.rs @@ -0,0 +1,36 @@ +use super::{ + super::{Animation, SkeletonAttr}, + CharacterSkeleton, +}; +use std::{f32::consts::PI, ops::Mul}; +use vek::*; + +pub struct Input { + pub attack: bool, +} +pub struct StandAnimation; + +impl Animation for StandAnimation { + type Skeleton = CharacterSkeleton; + type Dependency = f64; + + fn update_skeleton( + skeleton: &Self::Skeleton, + global_time: f64, + anim_time: f64, + skeleton_attr: &SkeletonAttr, + ) -> Self::Skeleton { + let mut next = (*skeleton).clone(); + + + next.l_foot.offset = Vec3::new(-3.4, -0.1, 8.0); + next.l_foot.ori = Quaternion::identity(); + next.l_foot.scale = Vec3::one(); + + next.r_foot.offset = Vec3::new(3.4, -0.1, 8.0); + next.r_foot.ori = Quaternion::identity(); + next.r_foot.scale = Vec3::one(); + + next + } +} diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index f6551a04df..87e97a8c23 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -703,7 +703,7 @@ impl FigureMgr { let time_since_action_change = state.last_action_change.elapsed().as_secs_f64(); let target_movement = match &character.movement { - Stand => anim::character::IdleAnimation::update_skeleton( + Stand => anim::character::StandAnimation::update_skeleton( state.skeleton_mut(), time, time_since_movement_change, @@ -739,10 +739,11 @@ impl FigureMgr { let target_action = match &character.action { Idle => anim::character::IdleAnimation::update_skeleton( state.skeleton_mut(), - time, - time_since_action_change, + (vel.0.magnitude(), time), + time_since_movement_change, skeleton_attr, ), + Wield { .. } => anim::character::CidleAnimation::update_skeleton( state.skeleton_mut(), time, From cd3e34064792a4ce749fe1f8074a70c51a17fe05 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Mon, 26 Aug 2019 14:25:49 +0200 Subject: [PATCH 04/16] Use movement anim as base and action anim as overwrite --- voxygen/src/scene/figure.rs | 57 ++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 87e97a8c23..00cd28aef6 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -702,68 +702,61 @@ impl FigureMgr { state.last_movement_change.elapsed().as_secs_f64(); let time_since_action_change = state.last_action_change.elapsed().as_secs_f64(); - let target_movement = match &character.movement { + let target_base = match &character.movement { Stand => anim::character::StandAnimation::update_skeleton( - state.skeleton_mut(), + &CharacterSkeleton::new(), time, time_since_movement_change, skeleton_attr, ), Run => anim::character::RunAnimation::update_skeleton( - state.skeleton_mut(), + &CharacterSkeleton::new(), (vel.0.magnitude(), time), time_since_movement_change, skeleton_attr, ), Jump => anim::character::JumpAnimation::update_skeleton( - state.skeleton_mut(), + &CharacterSkeleton::new(), time, time_since_movement_change, skeleton_attr, ), Roll { .. } => anim::character::RollAnimation::update_skeleton( - state.skeleton_mut(), + &CharacterSkeleton::new(), time, time_since_movement_change, skeleton_attr, ), Glide => anim::character::GlidingAnimation::update_skeleton( - state.skeleton_mut(), + &CharacterSkeleton::new(), (vel.0.magnitude(), time), time_since_movement_change, skeleton_attr, ), }; - state.skeleton.interpolate(&target_movement, dt); - let target_action = match &character.action { - Idle => anim::character::IdleAnimation::update_skeleton( - state.skeleton_mut(), - (vel.0.magnitude(), time), - time_since_movement_change, - skeleton_attr, - ), - - Wield { .. } => anim::character::CidleAnimation::update_skeleton( - state.skeleton_mut(), + let target_bones = match (&character.movement, &character.action) { + (_, Wield { .. }) => anim::character::CidleAnimation::update_skeleton( + &target_base, time, time_since_action_change, skeleton_attr, ), - Attack { .. } => anim::character::AttackAnimation::update_skeleton( - state.skeleton_mut(), + (_, Attack { .. }) => anim::character::AttackAnimation::update_skeleton( + &target_base, time, time_since_action_change, skeleton_attr, ), - Block { .. } => anim::character::BlockAnimation::update_skeleton( - state.skeleton_mut(), + (_, Block { .. }) => anim::character::BlockAnimation::update_skeleton( + &target_base, time, time_since_action_change, skeleton_attr, ), + _ => target_base, }; - state.skeleton.interpolate(&target_action, dt); + state.skeleton.interpolate(&target_bones, dt); state.update(renderer, pos.0, ori.0, scale, col, dt); } @@ -785,21 +778,21 @@ impl FigureMgr { let time_since_movement_change = state.last_movement_change.elapsed().as_secs_f64(); - let target_movement = match character.movement { + let target_base = match character.movement { Stand => anim::quadruped::IdleAnimation::update_skeleton( - state.skeleton_mut(), + &QuadrupedSkeleton::new(), time, time_since_movement_change, skeleton_attr, ), Run => anim::quadruped::RunAnimation::update_skeleton( - state.skeleton_mut(), + &QuadrupedSkeleton::new(), (vel.0.magnitude(), time), time_since_movement_change, skeleton_attr, ), Jump => anim::quadruped::JumpAnimation::update_skeleton( - state.skeleton_mut(), + &QuadrupedSkeleton::new(), (vel.0.magnitude(), time), time_since_movement_change, skeleton_attr, @@ -809,7 +802,7 @@ impl FigureMgr { _ => state.skeleton_mut().clone(), }; - state.skeleton.interpolate(&target_movement, dt); + state.skeleton.interpolate(&target_base, dt); state.update(renderer, pos.0, ori.0, scale, col, dt); } Body::QuadrupedMedium(_) => { @@ -832,21 +825,21 @@ impl FigureMgr { let time_since_movement_change = state.last_movement_change.elapsed().as_secs_f64(); - let target_movement = match character.movement { + let target_base = match character.movement { Stand => anim::quadrupedmedium::IdleAnimation::update_skeleton( - state.skeleton_mut(), + &QuadrupedMediumSkeleton::new(), time, time_since_movement_change, skeleton_attr, ), Run => anim::quadrupedmedium::RunAnimation::update_skeleton( - state.skeleton_mut(), + &QuadrupedMediumSkeleton::new(), (vel.0.magnitude(), time), time_since_movement_change, skeleton_attr, ), Jump => anim::quadrupedmedium::JumpAnimation::update_skeleton( - state.skeleton_mut(), + &QuadrupedMediumSkeleton::new(), (vel.0.magnitude(), time), time_since_movement_change, skeleton_attr, @@ -856,7 +849,7 @@ impl FigureMgr { _ => state.skeleton_mut().clone(), }; - state.skeleton.interpolate(&target_movement, dt); + state.skeleton.interpolate(&target_base, dt); state.update(renderer, pos.0, ori.0, scale, col, dt); } Body::Object(_) => { From bec942753ec6ae569bbf8e1c8a63d8790dde62aa Mon Sep 17 00:00:00 2001 From: jshipsey Date: Mon, 26 Aug 2019 23:04:54 -0400 Subject: [PATCH 05/16] some stuff fixed, other stuff still broken --- common/src/sys/animation.rs | 18 +++---- voxygen/src/anim/character/block.rs | 12 ++--- voxygen/src/anim/character/crun.rs | 44 ---------------- voxygen/src/anim/character/run.rs | 75 +++++++++++++++++++++++++++ voxygen/src/anim/character/stand.rs | 78 +++++++++++++++++++++++++++++ voxygen/src/scene/figure.rs | 7 +-- 6 files changed, 172 insertions(+), 62 deletions(-) diff --git a/common/src/sys/animation.rs b/common/src/sys/animation.rs index 3bc916fc5c..eb3ce92551 100644 --- a/common/src/sys/animation.rs +++ b/common/src/sys/animation.rs @@ -32,15 +32,15 @@ impl<'a> System<'a> for Sys { } let animation = match (physics.on_ground, &character.movement, &character.action) { - (_, Roll { .. }, Idle) => Animation::Roll, - (true, Stand, _) => Animation::Stand, //if standing still, legs still - (true, Stand, Idle) => Animation::Idle, //if standing still and not acting, idle the body - (true, Run, _) => Animation::Run, //if running, legs run - (true, Run, Idle) => Animation::Lean, //if running and not acting, lean the body - (false, Jump, Idle) => Animation::Jump, - (true, Stand, Wield { .. }) => Animation::Cidle, - (true, Run, Wield { .. }) => Animation::Crun, - (false, Jump, Wield { .. }) => Animation::Cjump, + //(_, Roll { .. }, _) => Animation::Roll, + //(true, Stand, _) => Animation::Stand, //if standing still, legs still + //(true, Stand, Idle) => Animation::Idle, //if standing still and not acting, idle the body + //(true, Run, _) => Animation::Run, //if running, legs run + //(true, Run, Idle) => Animation::Lean, //if running and not acting, lean the body + //(false, Jump, Idle) => Animation::Jump, + //(true, Stand, Wield { .. }) => Animation::Cidle, + //(true, Run, Wield { .. }) => Animation::Crun, + //(false, Jump, Wield { .. }) => Animation::Cjump, (_, Glide, Idle) => Animation::Gliding, (_, _, Attack { .. }) => Animation::Attack, (_, _, Block { .. }) => Animation::Block, diff --git a/voxygen/src/anim/character/block.rs b/voxygen/src/anim/character/block.rs index e62654ec0e..594cec571b 100644 --- a/voxygen/src/anim/character/block.rs +++ b/voxygen/src/anim/character/block.rs @@ -224,13 +224,13 @@ impl Animation for BlockAnimation { next.weapon.scale = Vec3::one(); } } - next.l_foot.offset = Vec3::new(-3.4, 0.3, 8.0 + wave_ultra_slow_cos * 0.1); - next.l_foot.ori = Quaternion::rotation_x(-0.3); - next.l_foot.scale = Vec3::one(); + //next.l_foot.offset = Vec3::new(-3.4, 0.3, 8.0 + wave_ultra_slow_cos * 0.1); + //next.l_foot.ori = Quaternion::rotation_x(-0.3); + //next.l_foot.scale = Vec3::one(); - next.r_foot.offset = Vec3::new(3.4, 1.2, 8.0 + wave_ultra_slow * 0.1); - next.r_foot.ori = Quaternion::rotation_x(0.3); - next.r_foot.scale = Vec3::one(); + //next.r_foot.offset = Vec3::new(3.4, 1.2, 8.0 + wave_ultra_slow * 0.1); + //next.r_foot.ori = Quaternion::rotation_x(0.3); + //next.r_foot.scale = Vec3::one(); next.l_shoulder.offset = Vec3::new(-5.0, 0.0, 4.7); next.l_shoulder.ori = Quaternion::rotation_x(0.0); diff --git a/voxygen/src/anim/character/crun.rs b/voxygen/src/anim/character/crun.rs index 26cbe654fb..b5bd6f2057 100644 --- a/voxygen/src/anim/character/crun.rs +++ b/voxygen/src/anim/character/crun.rs @@ -40,26 +40,6 @@ impl Animation for CrunAnimation { * 0.1, ); - next.head.offset = Vec3::new( - 0.0, - 0.0 + skeleton_attr.neck_forward, - skeleton_attr.neck_height + 15.0 + wave_cos * 1.3, - ); - next.head.ori = Quaternion::rotation_z(head_look.x + wave * 0.1) - * Quaternion::rotation_x(head_look.y + 0.35); - next.head.scale = Vec3::one() * skeleton_attr.head_scale; - - next.chest.offset = Vec3::new(0.0, 0.0, 7.0 + wave_cos * 1.1); - next.chest.ori = Quaternion::rotation_z(wave * 0.15); - next.chest.scale = Vec3::one(); - - next.belt.offset = Vec3::new(0.0, 0.0, 5.0 + wave_cos * 1.1); - next.belt.ori = Quaternion::rotation_z(wave * 0.25); - next.belt.scale = Vec3::one(); - - next.shorts.offset = Vec3::new(0.0, 0.0, 2.0 + wave_cos * 1.1); - next.shorts.ori = Quaternion::rotation_z(wave * 0.4); - next.shorts.scale = Vec3::one(); match Tool::Hammer { //TODO: Inventory @@ -187,30 +167,6 @@ impl Animation for CrunAnimation { next.weapon.scale = Vec3::one(); } } - next.l_foot.offset = Vec3::new(-3.4, 0.0 + wave_cos * 1.0, 6.0 - wave_cos_dub * 0.7); - next.l_foot.ori = Quaternion::rotation_x(-0.0 - wave_cos * 1.5); - next.l_foot.scale = Vec3::one(); - - next.r_foot.offset = Vec3::new(3.4, 0.0 - wave_cos * 1.0, 6.0 - wave_cos_dub * 0.7); - next.r_foot.ori = Quaternion::rotation_x(-0.0 + wave_cos * 1.5); - next.r_foot.scale = Vec3::one(); - - next.l_shoulder.offset = Vec3::new(-5.0, 0.0, 4.7); - next.l_shoulder.ori = Quaternion::rotation_x(wave_cos * 0.15); - next.l_shoulder.scale = Vec3::one() * 1.1; - - next.r_shoulder.offset = Vec3::new(5.0, 0.0, 4.7); - next.r_shoulder.ori = Quaternion::rotation_x(wave * 0.15); - next.r_shoulder.scale = Vec3::one() * 1.1; - - next.draw.offset = Vec3::new(0.0, 5.0, 0.0); - next.draw.ori = Quaternion::rotation_y(0.0); - next.draw.scale = Vec3::one() * 0.0; - - next.torso.offset = Vec3::new(0.0, -0.2 + wave * -0.08, 0.2) * skeleton_attr.scaler; - next.torso.ori = - Quaternion::rotation_x(wave_stop * velocity * -0.04 + wave_diff * velocity * -0.005); - next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; next } diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index 2a646a8c98..58013fe0ba 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -25,6 +25,54 @@ impl Animation for RunAnimation { let wave_diff = (anim_time as f32 * 12.0 + PI / 2.0).sin(); let wave_cos_dub = (anim_time as f32 * 24.0).cos(); let wave_stop = (anim_time as f32 * 2.6).min(PI / 2.0).sin(); + let head_look = Vec2::new( + ((global_time + anim_time) as f32 / 2.0) + .floor() + .mul(7331.0) + .sin() + * 0.2, + ((global_time + anim_time) as f32 / 2.0) + .floor() + .mul(1337.0) + .sin() + * 0.1, + ); + next.head.offset = Vec3::new( + 0.0, + -1.0 + skeleton_attr.neck_forward, + skeleton_attr.neck_height + 15.0 + wave_cos * 1.3, + ); + next.head.ori = Quaternion::rotation_z(head_look.x + wave * 0.1) + * Quaternion::rotation_x(head_look.y + 0.35); + next.head.scale = Vec3::one() * skeleton_attr.head_scale; + + next.chest.offset = Vec3::new(0.0, 0.0, 7.0 + wave_cos * 1.1); + next.chest.ori = Quaternion::rotation_z(wave * 0.2); + next.chest.scale = Vec3::one(); + + next.belt.offset = Vec3::new(0.0, 0.0, 5.0 + wave_cos * 1.1); + next.belt.ori = Quaternion::rotation_z(wave * 0.35); + next.belt.scale = Vec3::one(); + + next.shorts.offset = Vec3::new(0.0, 0.0, 2.0 + wave_cos * 1.1); + next.shorts.ori = Quaternion::rotation_z(wave * 0.6); + next.shorts.scale = Vec3::one(); + + next.l_hand.offset = Vec3::new( + -7.5 + wave_cos_dub * 1.0, + 2.0 + wave_cos * 5.0, + 0.0 - wave * 1.5, + ); + next.l_hand.ori = Quaternion::rotation_x(wave_cos * 0.8); + next.l_hand.scale = Vec3::one(); + + next.r_hand.offset = Vec3::new( + 7.5 - wave_cos_dub * 1.0, + 2.0 - wave_cos * 5.0, + 0.0 + wave * 1.5, + ); + next.r_hand.ori = Quaternion::rotation_x(wave_cos * -0.8); + next.r_hand.scale = Vec3::one(); next.l_foot.offset = Vec3::new(-3.4, 0.0 + wave_cos * 1.0, 6.0 - wave_cos_dub * 0.7); next.l_foot.ori = Quaternion::rotation_x(-0.0 - wave_cos * 1.5); @@ -34,6 +82,33 @@ impl Animation for RunAnimation { next.r_foot.ori = Quaternion::rotation_x(-0.0 + wave_cos * 1.5); next.r_foot.scale = Vec3::one(); + next.weapon.offset = Vec3::new( + -7.0 + skeleton_attr.weapon_x, + -5.0 + skeleton_attr.weapon_y, + 15.0, + ); + next.weapon.ori = + Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57 + wave_cos * 0.25); + next.weapon.scale = Vec3::one(); + + next.l_shoulder.offset = Vec3::new(-5.0, 0.0, 4.7); + next.l_shoulder.ori = Quaternion::rotation_x(wave_cos * 0.15); + next.l_shoulder.scale = Vec3::one() * 1.1; + + next.r_shoulder.offset = Vec3::new(5.0, 0.0, 4.7); + next.r_shoulder.ori = Quaternion::rotation_x(wave * 0.15); + next.r_shoulder.scale = Vec3::one() * 1.1; + + next.draw.offset = Vec3::new(0.0, 5.0, 0.0); + next.draw.ori = Quaternion::rotation_y(0.0); + next.draw.scale = Vec3::one() * 0.0; + + next.torso.offset = Vec3::new(0.0, -0.2 + wave * -0.08, 0.4) * skeleton_attr.scaler; + next.torso.ori = + Quaternion::rotation_x(wave_stop * velocity * -0.06 + wave_diff * velocity * -0.005); + next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; + + next } } diff --git a/voxygen/src/anim/character/stand.rs b/voxygen/src/anim/character/stand.rs index a542690c0f..00d0ec0b8f 100644 --- a/voxygen/src/anim/character/stand.rs +++ b/voxygen/src/anim/character/stand.rs @@ -22,6 +22,59 @@ impl Animation for StandAnimation { ) -> Self::Skeleton { let mut next = (*skeleton).clone(); + let wave_ultra_slow = (anim_time as f32 * 1.0 + PI).sin(); + let wave_ultra_slow_cos = (anim_time as f32 * 1.0 + PI).cos(); + + let head_look = Vec2::new( + ((global_time + anim_time) as f32 / 12.0) + .floor() + .mul(7331.0) + .sin() + * 0.5, + ((global_time + anim_time) as f32 / 12.0) + .floor() + .mul(1337.0) + .sin() + * 0.25, + ); + next.head.offset = Vec3::new( + 0.0 + skeleton_attr.neck_right, + 0.0 + skeleton_attr.neck_forward, + skeleton_attr.neck_height + 15.0 + wave_ultra_slow * 0.3, + ); + next.head.ori = + Quaternion::rotation_z(head_look.x) * Quaternion::rotation_x(head_look.y.abs()); + next.head.scale = Vec3::one() * skeleton_attr.head_scale; + + next.chest.offset = Vec3::new(0.0, 0.0, 7.0 + wave_ultra_slow * 0.3); + next.chest.ori = Quaternion::rotation_x(0.0); + next.chest.scale = Vec3::one(); + + next.belt.offset = Vec3::new(0.0, 0.0, 5.0 + wave_ultra_slow * 0.3); + next.belt.ori = Quaternion::rotation_x(0.0); + next.belt.scale = Vec3::one(); + + next.shorts.offset = Vec3::new(0.0, 0.0, 2.0 + wave_ultra_slow * 0.3); + next.shorts.ori = Quaternion::rotation_x(0.0); + next.shorts.scale = Vec3::one(); + + next.l_hand.offset = Vec3::new( + -7.5, + 0.0 + wave_ultra_slow_cos * 0.15, + 0.0 + wave_ultra_slow * 0.5, + ); + + next.l_hand.ori = Quaternion::rotation_x(0.0 + wave_ultra_slow * -0.06); + next.l_hand.scale = Vec3::one(); + + next.r_hand.offset = Vec3::new( + 7.5, + 0.0 + wave_ultra_slow_cos * 0.15, + 0.0 + wave_ultra_slow * 0.5, + ); + next.r_hand.ori = Quaternion::rotation_x(0.0 + wave_ultra_slow * -0.06); + next.r_hand.scale = Vec3::one(); + next.l_foot.offset = Vec3::new(-3.4, -0.1, 8.0); next.l_foot.ori = Quaternion::identity(); @@ -31,6 +84,31 @@ impl Animation for StandAnimation { next.r_foot.ori = Quaternion::identity(); next.r_foot.scale = Vec3::one(); + next.weapon.offset = Vec3::new( + -7.0 + skeleton_attr.weapon_x, + -5.0 + skeleton_attr.weapon_y, + 15.0, + ); + next.weapon.ori = Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57); + next.weapon.scale = Vec3::one(); + + next.l_shoulder.offset = Vec3::new(-5.0, 0.0, 4.7); + next.l_shoulder.ori = Quaternion::rotation_x(0.0); + next.l_shoulder.scale = Vec3::one() * 1.1; + + next.r_shoulder.offset = Vec3::new(5.0, 0.0, 4.7); + next.r_shoulder.ori = Quaternion::rotation_x(0.0); + next.r_shoulder.scale = Vec3::one() * 1.1; + + next.draw.offset = Vec3::new(0.0, 5.0, 0.0); + next.draw.ori = Quaternion::rotation_y(0.0); + next.draw.scale = Vec3::one() * 0.0; + + next.torso.offset = Vec3::new(0.0, -0.2, 0.1) * skeleton_attr.scaler; + next.torso.ori = Quaternion::rotation_x(0.0); + next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; + + next } } diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 00cd28aef6..c45a065df9 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -701,7 +701,7 @@ impl FigureMgr { let time_since_movement_change = state.last_movement_change.elapsed().as_secs_f64(); let time_since_action_change = state.last_action_change.elapsed().as_secs_f64(); - + let target_base = match &character.movement { Stand => anim::character::StandAnimation::update_skeleton( &CharacterSkeleton::new(), @@ -736,9 +736,10 @@ impl FigureMgr { }; let target_bones = match (&character.movement, &character.action) { - (_, Wield { .. }) => anim::character::CidleAnimation::update_skeleton( + + (_, Wield { .. }) => anim::character::CrunAnimation::update_skeleton( &target_base, - time, + (vel.0.magnitude(), time), time_since_action_change, skeleton_attr, ), From f8d0b1040ac536b3db387581b0d96ee5a559e929 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Wed, 28 Aug 2019 00:44:23 -0400 Subject: [PATCH 06/16] readded cidle --- common/src/sys/animation.rs | 6 +++--- voxygen/src/anim/character/run.rs | 2 +- voxygen/src/scene/figure.rs | 13 +++++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/common/src/sys/animation.rs b/common/src/sys/animation.rs index eb3ce92551..d9ec094db9 100644 --- a/common/src/sys/animation.rs +++ b/common/src/sys/animation.rs @@ -41,9 +41,9 @@ impl<'a> System<'a> for Sys { //(true, Stand, Wield { .. }) => Animation::Cidle, //(true, Run, Wield { .. }) => Animation::Crun, //(false, Jump, Wield { .. }) => Animation::Cjump, - (_, Glide, Idle) => Animation::Gliding, - (_, _, Attack { .. }) => Animation::Attack, - (_, _, Block { .. }) => Animation::Block, + //(_, Glide, Idle) => Animation::Gliding, + //(_, _, Attack { .. }) => Animation::Attack, + //(_, _, Block { .. }) => Animation::Block, // Impossible animation (Caused by missing animations or syncing delays) _ => Animation::Gliding, }; diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index 58013fe0ba..274f6174ce 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -81,7 +81,7 @@ impl Animation for RunAnimation { next.r_foot.offset = Vec3::new(3.4, 0.0 - wave_cos * 1.0, 6.0 - wave_cos_dub * 0.7); next.r_foot.ori = Quaternion::rotation_x(-0.0 + wave_cos * 1.5); next.r_foot.scale = Vec3::one(); - + next.weapon.offset = Vec3::new( -7.0 + skeleton_attr.weapon_x, -5.0 + skeleton_attr.weapon_y, diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index c45a065df9..39989b65b5 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -701,7 +701,7 @@ impl FigureMgr { let time_since_movement_change = state.last_movement_change.elapsed().as_secs_f64(); let time_since_action_change = state.last_action_change.elapsed().as_secs_f64(); - + let target_base = match &character.movement { Stand => anim::character::StandAnimation::update_skeleton( &CharacterSkeleton::new(), @@ -736,10 +736,9 @@ impl FigureMgr { }; let target_bones = match (&character.movement, &character.action) { - - (_, Wield { .. }) => anim::character::CrunAnimation::update_skeleton( + (Stand, Wield { .. }) => anim::character::CidleAnimation::update_skeleton( &target_base, - (vel.0.magnitude(), time), + time, time_since_action_change, skeleton_attr, ), @@ -749,6 +748,12 @@ impl FigureMgr { time_since_action_change, skeleton_attr, ), + (_, Wield { .. }) => anim::character::CrunAnimation::update_skeleton( + &target_base, + (vel.0.magnitude(), time), + time_since_action_change, + skeleton_attr, + ), (_, Block { .. }) => anim::character::BlockAnimation::update_skeleton( &target_base, time, From d84c07c1cbea16d75a5ed129b15b8f8d0e19f4f6 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Wed, 28 Aug 2019 01:24:57 -0400 Subject: [PATCH 07/16] fixed tiny feet in char creation --- voxygen/src/anim/character/idle.rs | 8 ++++++++ voxygen/src/scene/figure.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index dae68319fb..d65386ad11 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -75,6 +75,14 @@ impl Animation for IdleAnimation { next.r_hand.ori = Quaternion::rotation_x(0.0 + wave_ultra_slow * -0.06); next.r_hand.scale = Vec3::one(); + next.l_foot.offset = Vec3::new(-3.4, -0.1, 8.0); + next.l_foot.ori = Quaternion::identity(); + next.l_foot.scale = Vec3::one(); + + next.r_foot.offset = Vec3::new(3.4, -0.1, 8.0); + next.r_foot.ori = Quaternion::identity(); + next.r_foot.scale = Vec3::one(); + next.weapon.offset = Vec3::new( -7.0 + skeleton_attr.weapon_x, -5.0 + skeleton_attr.weapon_y, diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 39989b65b5..a952209eba 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -702,7 +702,7 @@ impl FigureMgr { state.last_movement_change.elapsed().as_secs_f64(); let time_since_action_change = state.last_action_change.elapsed().as_secs_f64(); - let target_base = match &character.movement { + let target_base = match dbg!(&character).movement { Stand => anim::character::StandAnimation::update_skeleton( &CharacterSkeleton::new(), time, From 77a48c61a1b60c61c271d060f43981cfedcf125f Mon Sep 17 00:00:00 2001 From: timokoesters Date: Wed, 28 Aug 2019 14:46:20 +0200 Subject: [PATCH 08/16] Fix rolling for the player --- client/src/lib.rs | 13 +++++++++---- common/src/comp/last.rs | 6 ------ server/src/lib.rs | 14 ++++++++++---- voxygen/src/scene/figure.rs | 11 ++++++++--- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 6c2bbf8f3e..faa9cab266 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -286,17 +286,22 @@ impl Client { { let ecs = self.state.ecs_mut(); for (entity, _) in (&ecs.entities(), &ecs.read_storage::()).join() { - let mut last_character_state = + let mut last_character_states = ecs.write_storage::>(); if let Some(client_character_state) = ecs.read_storage::().get(entity) { - if last_character_state + if last_character_states .get(entity) - .map(|&l| l != *client_character_state) + .map(|&l| { + std::mem::discriminant(&l.0.movement) + != std::mem::discriminant(&client_character_state.movement) + || std::mem::discriminant(&l.0.action) + != std::mem::discriminant(&client_character_state.action) + }) .unwrap_or(true) { - let _ = last_character_state + let _ = last_character_states .insert(entity, comp::Last(*client_character_state)); } } diff --git a/common/src/comp/last.rs b/common/src/comp/last.rs index 2ec18b6712..94561f1c5d 100644 --- a/common/src/comp/last.rs +++ b/common/src/comp/last.rs @@ -7,9 +7,3 @@ pub struct Last(pub C); impl Component for Last { type Storage = VecStorage; } - -impl PartialEq for Last { - fn eq(&self, other: &C) -> bool { - self.0 == *other - } -} diff --git a/server/src/lib.rs b/server/src/lib.rs index 52c7fc7cd4..df0be23575 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -1105,7 +1105,7 @@ impl Server { if let Some(client_pos) = ecs.read_storage::().get(entity) { if last_pos .get(entity) - .map(|&l| l != *client_pos) + .map(|&l| l.0 != *client_pos) .unwrap_or(true) { let _ = last_pos.insert(entity, comp::Last(*client_pos)); @@ -1123,7 +1123,7 @@ impl Server { if let Some(client_vel) = ecs.read_storage::().get(entity) { if last_vel .get(entity) - .map(|&l| l != *client_vel) + .map(|&l| l.0 != *client_vel) .unwrap_or(true) { let _ = last_vel.insert(entity, comp::Last(*client_vel)); @@ -1141,7 +1141,7 @@ impl Server { if let Some(client_ori) = ecs.read_storage::().get(entity) { if last_ori .get(entity) - .map(|&l| l != *client_ori) + .map(|&l| l.0 != *client_ori) .unwrap_or(true) { let _ = last_ori.insert(entity, comp::Last(*client_ori)); @@ -1161,7 +1161,13 @@ impl Server { { if last_character_state .get(entity) - .map(|&l| l != *client_character_state) + .map(|&l| { + // Check if enum item is the same without looking at the inner data + std::mem::discriminant(&l.0.movement) + != std::mem::discriminant(&client_character_state.movement) + || std::mem::discriminant(&l.0.action) + != std::mem::discriminant(&client_character_state.action) + }) .unwrap_or(true) { let _ = diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index a952209eba..23c99bc015 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -691,10 +691,15 @@ impl FigureMgr { _ => continue, }; - if last_character.0.movement != character.movement { + if std::mem::discriminant(&last_character.0.movement) + != std::mem::discriminant(&character.movement) + { state.last_movement_change = Instant::now(); } - if last_character.0.action != character.action { + + if std::mem::discriminant(&last_character.0.action) + != std::mem::discriminant(&character.action) + { state.last_action_change = Instant::now(); } @@ -702,7 +707,7 @@ impl FigureMgr { state.last_movement_change.elapsed().as_secs_f64(); let time_since_action_change = state.last_action_change.elapsed().as_secs_f64(); - let target_base = match dbg!(&character).movement { + let target_base = match &character.movement { Stand => anim::character::StandAnimation::update_skeleton( &CharacterSkeleton::new(), time, From b99bac87dbeacf3366194c36835de001c9841f86 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Wed, 28 Aug 2019 15:55:35 +0200 Subject: [PATCH 09/16] Make npcs roll correctly --- client/src/lib.rs | 9 ++--- common/src/sys/animation.rs | 65 ------------------------------------- common/src/sys/mod.rs | 5 +-- voxygen/src/scene/figure.rs | 8 +++-- 4 files changed, 12 insertions(+), 75 deletions(-) delete mode 100644 common/src/sys/animation.rs diff --git a/client/src/lib.rs b/client/src/lib.rs index faa9cab266..c0b5a4c91d 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -279,10 +279,7 @@ impl Client { // 2) Build up a list of events for this frame, to be passed to the frontend. let mut frontend_events = Vec::new(); - // Handle new messages from the server. - frontend_events.append(&mut self.handle_new_messages()?); - - // 3) Update client local data + // Prepare for new events { let ecs = self.state.ecs_mut(); for (entity, _) in (&ecs.entities(), &ecs.read_storage::()).join() { @@ -307,6 +304,10 @@ impl Client { } } } + // Handle new messages from the server. + frontend_events.append(&mut self.handle_new_messages()?); + + // 3) Update client local data // 4) Tick the client's LocalState self.state.tick(dt); diff --git a/common/src/sys/animation.rs b/common/src/sys/animation.rs deleted file mode 100644 index d9ec094db9..0000000000 --- a/common/src/sys/animation.rs +++ /dev/null @@ -1,65 +0,0 @@ -use crate::{ - comp::{ - ActionState::*, Animation, AnimationInfo, CharacterState, MovementState::*, PhysicsState, - Stats, - }, - state::DeltaTime, -}; -use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; -use std::fmt::Debug; - -/// This system will apply the animation that fits best to the users actions -pub struct Sys; -impl<'a> System<'a> for Sys { - type SystemData = ( - Entities<'a>, - Read<'a, DeltaTime>, - ReadStorage<'a, Stats>, - ReadStorage<'a, CharacterState>, - ReadStorage<'a, PhysicsState>, - WriteStorage<'a, AnimationInfo>, - ); - - fn run( - &mut self, - (entities, dt, stats, character_states, physics_states, mut animation_infos): Self::SystemData, - ) { - for (entity, stats, character, physics) in - (&entities, &stats, &character_states, &physics_states).join() - { - if stats.is_dead { - continue; - } - - let animation = match (physics.on_ground, &character.movement, &character.action) { - //(_, Roll { .. }, _) => Animation::Roll, - //(true, Stand, _) => Animation::Stand, //if standing still, legs still - //(true, Stand, Idle) => Animation::Idle, //if standing still and not acting, idle the body - //(true, Run, _) => Animation::Run, //if running, legs run - //(true, Run, Idle) => Animation::Lean, //if running and not acting, lean the body - //(false, Jump, Idle) => Animation::Jump, - //(true, Stand, Wield { .. }) => Animation::Cidle, - //(true, Run, Wield { .. }) => Animation::Crun, - //(false, Jump, Wield { .. }) => Animation::Cjump, - //(_, Glide, Idle) => Animation::Gliding, - //(_, _, Attack { .. }) => Animation::Attack, - //(_, _, Block { .. }) => Animation::Block, - // Impossible animation (Caused by missing animations or syncing delays) - _ => Animation::Gliding, - }; - - let new_time = animation_infos - .get(entity) - .filter(|i| i.animation == animation) - .map(|i| i.time + f64::from(dt.0)); - - let _ = animation_infos.insert( - entity, - AnimationInfo { - animation, - time: new_time.unwrap_or(0.0), - }, - ); - } - } -} diff --git a/common/src/sys/mod.rs b/common/src/sys/mod.rs index d1d7895e08..d177fde4b2 100644 --- a/common/src/sys/mod.rs +++ b/common/src/sys/mod.rs @@ -1,5 +1,4 @@ pub mod agent; -pub mod animation; mod cleanup; pub mod combat; pub mod controller; @@ -16,7 +15,6 @@ const CONTROLLER_SYS: &str = "controller_sys"; const PHYS_SYS: &str = "phys_sys"; const MOVEMENT_SYS: &str = "movement_sys"; const COMBAT_SYS: &str = "combat_sys"; -const ANIMATION_SYS: &str = "animation_sys"; const STATS_SYS: &str = "stats_sys"; const CLEANUP_SYS: &str = "cleanup_sys"; @@ -26,7 +24,6 @@ pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) { dispatch_builder.add(phys::Sys, PHYS_SYS, &[CONTROLLER_SYS]); dispatch_builder.add(movement::Sys, MOVEMENT_SYS, &[PHYS_SYS]); dispatch_builder.add(combat::Sys, COMBAT_SYS, &[CONTROLLER_SYS]); - dispatch_builder.add(animation::Sys, ANIMATION_SYS, &[MOVEMENT_SYS]); dispatch_builder.add(stats::Sys, STATS_SYS, &[COMBAT_SYS]); - dispatch_builder.add(cleanup::Sys, CLEANUP_SYS, &[STATS_SYS, ANIMATION_SYS]); + dispatch_builder.add(cleanup::Sys, CLEANUP_SYS, &[STATS_SYS, MOVEMENT_SYS]); } diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 23c99bc015..2bc2e34355 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -782,7 +782,9 @@ impl FigureMgr { _ => continue, }; - if last_character.0.movement != character.movement { + if std::mem::discriminant(&last_character.0.movement) + != std::mem::discriminant(&character.movement) + { state.last_movement_change = Instant::now(); } @@ -829,7 +831,9 @@ impl FigureMgr { _ => continue, }; - if last_character.0.movement != character.movement { + if std::mem::discriminant(&last_character.0.movement) + != std::mem::discriminant(&character.movement) + { state.last_movement_change = Instant::now(); } From 78bf7a09973e7bd5b1fb8dab3cc5a39a747b5fb8 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Wed, 28 Aug 2019 22:17:08 -0400 Subject: [PATCH 10/16] slowed movement for block/attack, cleaned up code, made foot speed velocity dependent, tweaked blocking animation --- common/src/sys/movement.rs | 17 ++ voxygen/src/anim/character/block.rs | 12 +- voxygen/src/anim/character/blockidle.rs | 252 ++++++++++++++++++ voxygen/src/anim/character/crun.rs | 4 +- voxygen/src/anim/character/idle.rs | 2 +- voxygen/src/anim/character/lean.rs | 107 -------- voxygen/src/anim/character/mod.rs | 14 +- voxygen/src/anim/character/run.rs | 10 +- voxygen/src/anim/character/stand.rs | 2 - .../src/anim/character/{cjump.rs => wield.rs} | 98 ++----- voxygen/src/scene/figure.rs | 10 +- 11 files changed, 322 insertions(+), 206 deletions(-) create mode 100644 voxygen/src/anim/character/blockidle.rs delete mode 100644 voxygen/src/anim/character/lean.rs rename voxygen/src/anim/character/{cjump.rs => wield.rs} (61%) diff --git a/common/src/sys/movement.rs b/common/src/sys/movement.rs index d89b89b2c5..1042989bb6 100644 --- a/common/src/sys/movement.rs +++ b/common/src/sys/movement.rs @@ -20,6 +20,8 @@ const HUMANOID_AIR_SPEED: f32 = 100.0; const ROLL_SPEED: f32 = 13.0; const GLIDE_ACCEL: f32 = 15.0; const GLIDE_SPEED: f32 = 45.0; +const BLOCK_ACCEL: f32 = 30.0; +const BLOCK_SPEED: f32 = 75.0; // Gravity is 9.81 * 4, so this makes gravity equal to .15 const GLIDE_ANTIGRAV: f32 = 9.81 * 3.95; @@ -80,6 +82,21 @@ impl<'a> System<'a> for Sys { .try_normalized() .unwrap_or(Vec2::from(vel.0).try_normalized().unwrap_or_default()) * ROLL_SPEED + } + if character.action.is_block() { + vel.0 += Vec2::broadcast(dt.0) + * controller.move_dir + * match (physics.on_ground) { + (true) if vel.0.magnitude_squared() < BLOCK_SPEED.powf(2.0) => BLOCK_ACCEL, + _ => 0.0, + } + } else if character.action.is_attack() { + vel.0 += Vec2::broadcast(dt.0) + * controller.move_dir + * match (physics.on_ground) { + (true) if vel.0.magnitude_squared() < BLOCK_SPEED.powf(2.0) => BLOCK_ACCEL, + _ => 0.0, + } } else { // Move player according to move_dir vel.0 += Vec2::broadcast(dt.0) diff --git a/voxygen/src/anim/character/block.rs b/voxygen/src/anim/character/block.rs index 594cec571b..f3ff71c066 100644 --- a/voxygen/src/anim/character/block.rs +++ b/voxygen/src/anim/character/block.rs @@ -107,23 +107,23 @@ impl Animation for BlockAnimation { next.weapon.scale = Vec3::one(); } Tool::Hammer => { - next.l_hand.offset = Vec3::new(-5.5, 9.0, 5.5); + next.l_hand.offset = Vec3::new(-5.5, 10.0, 9.5); next.l_hand.ori = Quaternion::rotation_x(-0.3) - * Quaternion::rotation_y(-1.57) + * Quaternion::rotation_y(-1.35) * Quaternion::rotation_z(0.5); next.l_hand.scale = Vec3::one() * 1.01; - next.r_hand.offset = Vec3::new(8.4, 9.3, 5.5); + next.r_hand.offset = Vec3::new(8.4, 9.3, 7.5); next.r_hand.ori = Quaternion::rotation_x(-0.3) - * Quaternion::rotation_y(-1.57) + * Quaternion::rotation_y(-1.35) * Quaternion::rotation_z(0.5); next.r_hand.scale = Vec3::one() * 1.01; next.weapon.offset = Vec3::new( 7.0 + skeleton_attr.weapon_x, 10.75 + skeleton_attr.weapon_y, - 5.5, + 7.5, ); next.weapon.ori = Quaternion::rotation_x(-0.3) - * Quaternion::rotation_y(-1.57) + * Quaternion::rotation_y(-1.35) * Quaternion::rotation_z(0.5); next.weapon.scale = Vec3::one(); } diff --git a/voxygen/src/anim/character/blockidle.rs b/voxygen/src/anim/character/blockidle.rs new file mode 100644 index 0000000000..a2e5c4f839 --- /dev/null +++ b/voxygen/src/anim/character/blockidle.rs @@ -0,0 +1,252 @@ +use super::{ + super::{Animation, SkeletonAttr}, + CharacterSkeleton, +}; +use common::comp::item::Tool; +use std::{f32::consts::PI, ops::Mul}; +use vek::*; + +pub struct Input { + pub attack: bool, +} +pub struct BlockIdleAnimation; + +impl Animation for BlockIdleAnimation { + type Skeleton = CharacterSkeleton; + type Dependency = f64; + + fn update_skeleton( + skeleton: &Self::Skeleton, + global_time: f64, + anim_time: f64, + skeleton_attr: &SkeletonAttr, + ) -> Self::Skeleton { + let mut next = (*skeleton).clone(); + + let wave_ultra_slow = (anim_time as f32 * 3.0 + PI).sin(); + let wave_ultra_slow_cos = (anim_time as f32 * 3.0 + PI).cos(); + let wave_slow_cos = (anim_time as f32 * 6.0 + PI).cos(); + + let _head_look = Vec2::new( + ((global_time + anim_time) as f32 / 1.5) + .floor() + .mul(7331.0) + .sin() + * 0.3, + ((global_time + anim_time) as f32 / 1.5) + .floor() + .mul(1337.0) + .sin() + * 0.15, + ); + next.head.offset = Vec3::new( + 0.0 + skeleton_attr.neck_right + wave_slow_cos * 0.2, + 1.0 + skeleton_attr.neck_forward, + skeleton_attr.neck_height + 13.5 + wave_ultra_slow * 0.2, + ); + next.head.ori = Quaternion::rotation_x(-0.25); + next.head.scale = Vec3::one() * 1.01 * skeleton_attr.head_scale; + + next.chest.offset = Vec3::new(0.0 + wave_slow_cos * 0.2, 0.0, 5.0 + wave_ultra_slow * 0.2); + next.chest.ori = + Quaternion::rotation_x(-0.15) * Quaternion::rotation_y(wave_ultra_slow_cos * 0.01); + next.chest.scale = Vec3::one(); + + next.belt.offset = Vec3::new(0.0 + wave_slow_cos * 0.2, 0.0, 3.0 + wave_ultra_slow * 0.2); + next.belt.ori = + Quaternion::rotation_x(0.0) * Quaternion::rotation_y(wave_ultra_slow_cos * 0.008); + next.belt.scale = Vec3::one() * 1.01; + + next.shorts.offset = Vec3::new(0.0 + wave_slow_cos * 0.2, 0.0, 1.0 + wave_ultra_slow * 0.2); + next.shorts.ori = Quaternion::rotation_x(0.1); + next.shorts.scale = Vec3::one(); + + match Tool::Hammer { + //TODO: Inventory + Tool::Sword => { + next.l_hand.offset = Vec3::new(-6.0, 3.5, 0.0 + wave_ultra_slow * 1.0); + next.l_hand.ori = Quaternion::rotation_x(-0.3); + next.l_hand.scale = Vec3::one() * 1.01; + next.r_hand.offset = Vec3::new(-6.0, 3.0, -2.0); + next.r_hand.ori = Quaternion::rotation_x(-0.3); + next.r_hand.scale = Vec3::one() * 1.01; + next.weapon.offset = Vec3::new( + -6.0 + skeleton_attr.weapon_x, + 4.5 + skeleton_attr.weapon_y, + 0.0, + ); + next.weapon.ori = Quaternion::rotation_x(-0.3) + * Quaternion::rotation_y(0.0) + * Quaternion::rotation_z(0.0); + next.weapon.scale = Vec3::one(); + } + Tool::Axe => { + next.l_hand.offset = Vec3::new( + -6.0 + wave_ultra_slow_cos * 1.0, + 3.5 + wave_ultra_slow_cos * 0.5, + 0.0 + wave_ultra_slow * 1.0, + ); + next.l_hand.ori = Quaternion::rotation_x(-0.3); + next.l_hand.scale = Vec3::one() * 1.01; + next.r_hand.offset = Vec3::new( + -6.0 + wave_ultra_slow_cos * 1.0, + 3.0 + wave_ultra_slow_cos * 0.5, + -2.0 + wave_ultra_slow * 1.0, + ); + next.r_hand.ori = Quaternion::rotation_x(-0.3); + next.r_hand.scale = Vec3::one() * 1.01; + next.weapon.offset = Vec3::new( + -6.0 + skeleton_attr.weapon_x, + 4.5 + skeleton_attr.weapon_y, + 0.0 + wave_ultra_slow * 1.0, + ); + next.weapon.ori = Quaternion::rotation_x(-0.3) + * Quaternion::rotation_y(0.0) + * Quaternion::rotation_z(0.0); + next.weapon.scale = Vec3::one(); + } + Tool::Hammer => { + next.l_hand.offset = Vec3::new(-5.5, 10.0 + wave_ultra_slow * 2.0, 9.5); + next.l_hand.ori = Quaternion::rotation_x(-0.3) + * Quaternion::rotation_y(-1.35) + * Quaternion::rotation_z(0.5); + next.l_hand.scale = Vec3::one() * 1.01; + next.r_hand.offset = Vec3::new(8.4, 9.3 + wave_ultra_slow * 2.0, 7.5); + next.r_hand.ori = Quaternion::rotation_x(-0.3) + * Quaternion::rotation_y(-1.35) + * Quaternion::rotation_z(0.5); + next.r_hand.scale = Vec3::one() * 1.01; + next.weapon.offset = Vec3::new( + 7.0 + skeleton_attr.weapon_x, + 10.75 + skeleton_attr.weapon_y + wave_ultra_slow * 2.0, + 7.5, + ); + next.weapon.ori = Quaternion::rotation_x(-0.3) + * Quaternion::rotation_y(-1.35) + * Quaternion::rotation_z(0.5); + next.weapon.scale = Vec3::one(); + } + Tool::Staff => { + next.l_hand.offset = Vec3::new( + -6.0 + wave_ultra_slow_cos * 1.0, + 3.5 + wave_ultra_slow_cos * 0.5, + 0.0 + wave_ultra_slow * 1.0, + ); + next.l_hand.ori = Quaternion::rotation_x(-0.3); + next.l_hand.scale = Vec3::one() * 1.01; + next.r_hand.offset = Vec3::new( + -6.0 + wave_ultra_slow_cos * 1.0, + 3.0 + wave_ultra_slow_cos * 0.5, + -2.0 + wave_ultra_slow * 1.0, + ); + next.r_hand.ori = Quaternion::rotation_x(-0.3); + next.r_hand.scale = Vec3::one() * 1.01; + next.weapon.offset = Vec3::new( + -6.0 + skeleton_attr.weapon_x + wave_ultra_slow_cos * 1.0, + 4.5 + skeleton_attr.weapon_y + wave_ultra_slow_cos * 0.5, + 0.0 + wave_ultra_slow * 1.0, + ); + next.weapon.ori = Quaternion::rotation_x(-0.3) + * Quaternion::rotation_y(0.0) + * Quaternion::rotation_z(0.0); + next.weapon.scale = Vec3::one(); + } + Tool::SwordShield => { + next.l_hand.offset = Vec3::new( + -6.0 + wave_ultra_slow_cos * 1.0, + 3.5 + wave_ultra_slow_cos * 0.5, + 0.0 + wave_ultra_slow * 1.0, + ); + next.l_hand.ori = Quaternion::rotation_x(-0.3); + next.l_hand.scale = Vec3::one() * 1.01; + next.r_hand.offset = Vec3::new( + -6.0 + wave_ultra_slow_cos * 1.0, + 3.0 + wave_ultra_slow_cos * 0.5, + -2.0 + wave_ultra_slow * 1.0, + ); + next.r_hand.ori = Quaternion::rotation_x(-0.3); + next.r_hand.scale = Vec3::one() * 1.01; + next.weapon.offset = Vec3::new( + -6.0 + skeleton_attr.weapon_x + wave_ultra_slow_cos * 1.0, + 4.5 + skeleton_attr.weapon_y + wave_ultra_slow_cos * 0.5, + 0.0 + wave_ultra_slow * 1.0, + ); + next.weapon.ori = Quaternion::rotation_x(-0.3) + * Quaternion::rotation_y(0.0) + * Quaternion::rotation_z(0.0); + next.weapon.scale = Vec3::one(); + } + Tool::Bow => { + next.l_hand.offset = Vec3::new( + -6.0 + wave_ultra_slow_cos * 1.0, + 3.5 + wave_ultra_slow_cos * 0.5, + 0.0 + wave_ultra_slow * 1.0, + ); + next.l_hand.ori = Quaternion::rotation_x(-0.3); + next.l_hand.scale = Vec3::one() * 1.01; + next.r_hand.offset = Vec3::new( + -6.0 + wave_ultra_slow_cos * 1.0, + 3.0 + wave_ultra_slow_cos * 0.5, + -2.0 + wave_ultra_slow * 1.0, + ); + next.r_hand.ori = Quaternion::rotation_x(-0.3); + next.r_hand.scale = Vec3::one() * 1.01; + next.weapon.offset = Vec3::new( + -6.0 + skeleton_attr.weapon_x + wave_ultra_slow_cos * 1.0, + 4.5 + skeleton_attr.weapon_y + wave_ultra_slow_cos * 0.5, + 0.0 + wave_ultra_slow * 1.0, + ); + next.weapon.ori = Quaternion::rotation_x(-0.3) + * Quaternion::rotation_y(0.0) + * Quaternion::rotation_z(0.0); + next.weapon.scale = Vec3::one(); + } + Tool::Daggers => { + next.l_hand.offset = Vec3::new( + -6.0 + wave_ultra_slow_cos * 1.0, + 3.5 + wave_ultra_slow_cos * 0.5, + 0.0 + wave_ultra_slow * 1.0, + ); + next.l_hand.ori = Quaternion::rotation_x(-0.3); + next.l_hand.scale = Vec3::one() * 1.01; + next.r_hand.offset = Vec3::new(-6.0, 3.0, -2.0); + next.r_hand.ori = Quaternion::rotation_x(-0.3); + next.r_hand.scale = Vec3::one() * 1.01; + next.weapon.offset = Vec3::new( + -6.0 + skeleton_attr.weapon_x, + 4.5 + skeleton_attr.weapon_y, + 0.0, + ); + next.weapon.ori = Quaternion::rotation_x(-0.3) + * Quaternion::rotation_y(0.0) + * Quaternion::rotation_z(0.0); + next.weapon.scale = Vec3::one(); + } + } + next.l_foot.offset = Vec3::new(-3.4, 0.3, 8.0 + wave_ultra_slow_cos * 0.1); + next.l_foot.ori = Quaternion::rotation_x(-0.3); + next.l_foot.scale = Vec3::one(); + + next.r_foot.offset = Vec3::new(3.4, 1.2, 8.0 + wave_ultra_slow * 0.1); + next.r_foot.ori = Quaternion::rotation_x(0.3); + next.r_foot.scale = Vec3::one(); + + next.l_shoulder.offset = Vec3::new(-5.0, 0.0, 4.7); + next.l_shoulder.ori = Quaternion::rotation_x(0.0); + next.l_shoulder.scale = Vec3::one() * 1.1; + + next.r_shoulder.offset = Vec3::new(5.0, 0.0, 4.7); + next.r_shoulder.ori = Quaternion::rotation_x(0.0); + next.r_shoulder.scale = Vec3::one() * 1.1; + + next.draw.offset = Vec3::new(0.0, 5.0, 0.0); + next.draw.ori = Quaternion::rotation_y(0.0); + next.draw.scale = Vec3::one() * 0.0; + + next.torso.offset = Vec3::new(0.0, -0.2, 0.1) * skeleton_attr.scaler; + next.torso.ori = Quaternion::rotation_x(0.0); + next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; + + next + } +} diff --git a/voxygen/src/anim/character/crun.rs b/voxygen/src/anim/character/crun.rs index b5bd6f2057..def3c9c8d5 100644 --- a/voxygen/src/anim/character/crun.rs +++ b/voxygen/src/anim/character/crun.rs @@ -7,9 +7,9 @@ use std::f32::consts::PI; use std::ops::Mul; use vek::*; -pub struct CrunAnimation; +pub struct WieldAnimation; -impl Animation for CrunAnimation { +impl Animation for WieldAnimation { type Skeleton = CharacterSkeleton; type Dependency = (f32, f64); diff --git a/voxygen/src/anim/character/idle.rs b/voxygen/src/anim/character/idle.rs index d65386ad11..f5ab828a78 100644 --- a/voxygen/src/anim/character/idle.rs +++ b/voxygen/src/anim/character/idle.rs @@ -82,7 +82,7 @@ impl Animation for IdleAnimation { next.r_foot.offset = Vec3::new(3.4, -0.1, 8.0); next.r_foot.ori = Quaternion::identity(); next.r_foot.scale = Vec3::one(); - + next.weapon.offset = Vec3::new( -7.0 + skeleton_attr.weapon_x, -5.0 + skeleton_attr.weapon_y, diff --git a/voxygen/src/anim/character/lean.rs b/voxygen/src/anim/character/lean.rs deleted file mode 100644 index 1d60609225..0000000000 --- a/voxygen/src/anim/character/lean.rs +++ /dev/null @@ -1,107 +0,0 @@ -use super::{ - super::{Animation, SkeletonAttr}, - CharacterSkeleton, -}; -use std::f32::consts::PI; -use std::ops::Mul; -use vek::*; - -pub struct LeanAnimation; - -impl Animation for LeanAnimation { - type Skeleton = CharacterSkeleton; - type Dependency = (f32, f64); - - fn update_skeleton( - skeleton: &Self::Skeleton, - (velocity, global_time): Self::Dependency, - anim_time: f64, - skeleton_attr: &SkeletonAttr, - ) -> Self::Skeleton { - let mut next = (*skeleton).clone(); - - let wave = (anim_time as f32 * 12.0).sin(); - let wave_cos = (anim_time as f32 * 12.0).cos(); - let wave_diff = (anim_time as f32 * 12.0 + PI / 2.0).sin(); - let wave_cos_dub = (anim_time as f32 * 24.0).cos(); - let wave_stop = (anim_time as f32 * 2.6).min(PI / 2.0).sin(); - - let head_look = Vec2::new( - ((global_time + anim_time) as f32 / 2.0) - .floor() - .mul(7331.0) - .sin() - * 0.2, - ((global_time + anim_time) as f32 / 2.0) - .floor() - .mul(1337.0) - .sin() - * 0.1, - ); - - next.head.offset = Vec3::new( - 0.0, - -1.0 + skeleton_attr.neck_forward, - skeleton_attr.neck_height + 15.0 + wave_cos * 1.3, - ); - next.head.ori = Quaternion::rotation_z(head_look.x + wave * 0.1) - * Quaternion::rotation_x(head_look.y + 0.35); - next.head.scale = Vec3::one() * skeleton_attr.head_scale; - - next.chest.offset = Vec3::new(0.0, 0.0, 7.0 + wave_cos * 1.1); - next.chest.ori = Quaternion::rotation_z(wave * 0.2); - next.chest.scale = Vec3::one(); - - next.belt.offset = Vec3::new(0.0, 0.0, 5.0 + wave_cos * 1.1); - next.belt.ori = Quaternion::rotation_z(wave * 0.35); - next.belt.scale = Vec3::one(); - - next.shorts.offset = Vec3::new(0.0, 0.0, 2.0 + wave_cos * 1.1); - next.shorts.ori = Quaternion::rotation_z(wave * 0.6); - next.shorts.scale = Vec3::one(); - - next.l_hand.offset = Vec3::new( - -7.5 + wave_cos_dub * 1.0, - 2.0 + wave_cos * 5.0, - 0.0 - wave * 1.5, - ); - next.l_hand.ori = Quaternion::rotation_x(wave_cos * 0.8); - next.l_hand.scale = Vec3::one(); - - next.r_hand.offset = Vec3::new( - 7.5 - wave_cos_dub * 1.0, - 2.0 - wave_cos * 5.0, - 0.0 + wave * 1.5, - ); - next.r_hand.ori = Quaternion::rotation_x(wave_cos * -0.8); - next.r_hand.scale = Vec3::one(); - - next.weapon.offset = Vec3::new( - -7.0 + skeleton_attr.weapon_x, - -5.0 + skeleton_attr.weapon_y, - 15.0, - ); - next.weapon.ori = - Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57 + wave_cos * 0.25); - next.weapon.scale = Vec3::one(); - - next.l_shoulder.offset = Vec3::new(-5.0, 0.0, 4.7); - next.l_shoulder.ori = Quaternion::rotation_x(wave_cos * 0.15); - next.l_shoulder.scale = Vec3::one() * 1.1; - - next.r_shoulder.offset = Vec3::new(5.0, 0.0, 4.7); - next.r_shoulder.ori = Quaternion::rotation_x(wave * 0.15); - next.r_shoulder.scale = Vec3::one() * 1.1; - - next.draw.offset = Vec3::new(0.0, 5.0, 0.0); - next.draw.ori = Quaternion::rotation_y(0.0); - next.draw.scale = Vec3::one() * 0.0; - - next.torso.offset = Vec3::new(0.0, -0.2 + wave * -0.08, 0.4) * skeleton_attr.scaler; - next.torso.ori = - Quaternion::rotation_x(wave_stop * velocity * -0.06 + wave_diff * velocity * -0.005); - next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; - - next - } -} diff --git a/voxygen/src/anim/character/mod.rs b/voxygen/src/anim/character/mod.rs index 0837dcb881..c8ec0efbcf 100644 --- a/voxygen/src/anim/character/mod.rs +++ b/voxygen/src/anim/character/mod.rs @@ -1,29 +1,27 @@ pub mod attack; pub mod block; +pub mod blockidle; pub mod cidle; -pub mod cjump; -pub mod crun; pub mod gliding; pub mod idle; -pub mod stand; pub mod jump; pub mod roll; pub mod run; -pub mod lean; +pub mod stand; +pub mod wield; // Reexports pub use self::attack::AttackAnimation; pub use self::block::BlockAnimation; +pub use self::blockidle::BlockIdleAnimation; pub use self::cidle::CidleAnimation; -pub use self::cjump::CjumpAnimation; -pub use self::crun::CrunAnimation; pub use self::gliding::GlidingAnimation; pub use self::idle::IdleAnimation; -pub use self::stand::StandAnimation; pub use self::jump::JumpAnimation; pub use self::roll::RollAnimation; pub use self::run::RunAnimation; -pub use self::lean::LeanAnimation; +pub use self::stand::StandAnimation; +pub use self::wield::WieldAnimation; use super::{Bone, Skeleton}; use crate::render::FigureBoneData; diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index 274f6174ce..a0b1b6d008 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -20,10 +20,11 @@ impl Animation for RunAnimation { ) -> Self::Skeleton { let mut next = (*skeleton).clone(); - let wave = (anim_time as f32 * 12.0).sin(); - let wave_cos = (anim_time as f32 * 12.0).cos(); - let wave_diff = (anim_time as f32 * 12.0 + PI / 2.0).sin(); - let wave_cos_dub = (anim_time as f32 * 24.0).cos(); + let wave = (anim_time as f32 * velocity * 1.2).sin(); + let wave_cos = (anim_time as f32 * velocity * 1.2).cos(); + + let wave_diff = (anim_time as f32 * velocity * 0.6).sin(); + let wave_cos_dub = (anim_time as f32 * velocity * 2.4).cos(); let wave_stop = (anim_time as f32 * 2.6).min(PI / 2.0).sin(); let head_look = Vec2::new( ((global_time + anim_time) as f32 / 2.0) @@ -108,7 +109,6 @@ impl Animation for RunAnimation { Quaternion::rotation_x(wave_stop * velocity * -0.06 + wave_diff * velocity * -0.005); next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; - next } } diff --git a/voxygen/src/anim/character/stand.rs b/voxygen/src/anim/character/stand.rs index 00d0ec0b8f..c7057b1f1e 100644 --- a/voxygen/src/anim/character/stand.rs +++ b/voxygen/src/anim/character/stand.rs @@ -75,7 +75,6 @@ impl Animation for StandAnimation { next.r_hand.ori = Quaternion::rotation_x(0.0 + wave_ultra_slow * -0.06); next.r_hand.scale = Vec3::one(); - next.l_foot.offset = Vec3::new(-3.4, -0.1, 8.0); next.l_foot.ori = Quaternion::identity(); next.l_foot.scale = Vec3::one(); @@ -108,7 +107,6 @@ impl Animation for StandAnimation { next.torso.ori = Quaternion::rotation_x(0.0); next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; - next } } diff --git a/voxygen/src/anim/character/cjump.rs b/voxygen/src/anim/character/wield.rs similarity index 61% rename from voxygen/src/anim/character/cjump.rs rename to voxygen/src/anim/character/wield.rs index 6f4cf9720d..56bce3625e 100644 --- a/voxygen/src/anim/character/cjump.rs +++ b/voxygen/src/anim/character/wield.rs @@ -3,59 +3,37 @@ use super::{ CharacterSkeleton, }; use common::comp::item::Tool; -use std::f32::consts::PI; use vek::*; -pub struct CjumpAnimation; +pub struct WieldAnimation; -impl Animation for CjumpAnimation { +impl Animation for WieldAnimation { type Skeleton = CharacterSkeleton; - type Dependency = f64; + type Dependency = (f32, f64); fn update_skeleton( skeleton: &Self::Skeleton, - _global_time: f64, + (_velocity, _global_time): Self::Dependency, anim_time: f64, skeleton_attr: &SkeletonAttr, ) -> Self::Skeleton { let mut next = (*skeleton).clone(); - let wave_slow = (anim_time as f32 * 7.0).sin(); - let wave_stop = (anim_time as f32 * 4.5).min(PI / 2.0).sin(); - - next.head.offset = Vec3::new( - 0.0 + skeleton_attr.neck_right, - 0.0 + skeleton_attr.neck_forward, - skeleton_attr.neck_height + 15.0, - ); - next.head.ori = Quaternion::rotation_x(0.25 + wave_stop * 0.1 + wave_slow * 0.04); - next.head.scale = Vec3::one() * skeleton_attr.head_scale; - - next.chest.offset = Vec3::new(0.0, 0.0, 8.0); - next.chest.ori = Quaternion::rotation_z(0.0); - next.chest.scale = Vec3::one(); - - next.belt.offset = Vec3::new(0.0, 0.0, 6.0); - next.belt.ori = Quaternion::rotation_z(0.0); - next.belt.scale = Vec3::one(); - - next.shorts.offset = Vec3::new(0.0, 0.0, 3.0); - next.shorts.ori = Quaternion::rotation_z(0.0); - next.shorts.scale = Vec3::one(); + let wave = (anim_time as f32 * 12.0).sin(); match Tool::Hammer { //TODO: Inventory Tool::Sword => { - next.l_hand.offset = Vec3::new(-7.0, 3.25, 0.25 + wave_stop * 2.0); + next.l_hand.offset = Vec3::new(-6.0, 3.75, 0.25); next.l_hand.ori = Quaternion::rotation_x(-0.3); next.l_hand.scale = Vec3::one() * 1.01; - next.r_hand.offset = Vec3::new(-7.0, 3.0, -2.0 + wave_stop * 2.0); + next.r_hand.offset = Vec3::new(-6.0, 3.0, -2.0); next.r_hand.ori = Quaternion::rotation_x(-0.3); next.r_hand.scale = Vec3::one() * 1.01; next.weapon.offset = Vec3::new( - -7.0 + skeleton_attr.weapon_x, + -6.0 + skeleton_attr.weapon_x, 4.0 + skeleton_attr.weapon_y, - 0.0 + wave_stop * 2.0, + 0.0, ); next.weapon.ori = Quaternion::rotation_x(-0.3) * Quaternion::rotation_y(0.0) @@ -80,45 +58,41 @@ impl Animation for CjumpAnimation { next.weapon.scale = Vec3::one(); } Tool::Hammer => { - next.l_hand.offset = Vec3::new(-7.0, 8.25, 2.0 + wave_stop * 2.0); + next.l_hand.offset = Vec3::new(-7.0, 8.25, 3.0); next.l_hand.ori = Quaternion::rotation_x(-0.3) * Quaternion::rotation_y(-1.2) - * Quaternion::rotation_z(0.0); + * Quaternion::rotation_z(wave * -0.25); next.l_hand.scale = Vec3::one() * 1.01; - next.r_hand.offset = Vec3::new(7.0, 7.0, -3.0 + wave_stop * 2.0); + next.r_hand.offset = Vec3::new(7.0, 7.0, -1.5); next.r_hand.ori = Quaternion::rotation_x(-0.3) * Quaternion::rotation_y(-1.2) - * Quaternion::rotation_z(0.0); + * Quaternion::rotation_z(wave * -0.25); next.r_hand.scale = Vec3::one() * 1.01; next.weapon.offset = Vec3::new( 5.0 + skeleton_attr.weapon_x, 8.75 + skeleton_attr.weapon_y, - -2.5 + wave_stop * 2.0, + -2.0, ); next.weapon.ori = Quaternion::rotation_x(-0.3) * Quaternion::rotation_y(-1.2) - * Quaternion::rotation_z(0.0); + * Quaternion::rotation_z(wave * -0.25); next.weapon.scale = Vec3::one(); } Tool::Staff => { - next.l_hand.offset = Vec3::new(-7.0, 7.5, 0.0); - next.l_hand.ori = Quaternion::rotation_x(-0.3) - * Quaternion::rotation_y(-1.7) - * Quaternion::rotation_z(1.0); + next.l_hand.offset = Vec3::new(-6.0, 3.5, 0.0); + next.l_hand.ori = Quaternion::rotation_x(-0.3); next.l_hand.scale = Vec3::one() * 1.01; - next.r_hand.offset = Vec3::new(7.0, 6.25, 1.5); - next.r_hand.ori = Quaternion::rotation_x(-0.3) - * Quaternion::rotation_y(-1.7) - * Quaternion::rotation_z(1.0); + next.r_hand.offset = Vec3::new(-6.0, 3.0, -2.0); + next.r_hand.ori = Quaternion::rotation_x(-0.3); next.r_hand.scale = Vec3::one() * 1.01; next.weapon.offset = Vec3::new( - 5.0 + skeleton_attr.weapon_x, - 8.0 + skeleton_attr.weapon_y, - 1.0, + -6.0 + skeleton_attr.weapon_x, + 4.5 + skeleton_attr.weapon_y, + 0.0, ); next.weapon.ori = Quaternion::rotation_x(-0.3) - * Quaternion::rotation_y(-1.7) - * Quaternion::rotation_z(1.0); + * Quaternion::rotation_y(0.0) + * Quaternion::rotation_z(0.0); next.weapon.scale = Vec3::one(); } Tool::SwordShield => { @@ -174,30 +148,6 @@ impl Animation for CjumpAnimation { } } - next.l_foot.offset = Vec3::new(-3.4, 1.0, 6.0); - next.l_foot.ori = Quaternion::rotation_x(wave_stop * -1.2 - wave_slow * 0.2); - next.l_foot.scale = Vec3::one(); - - next.r_foot.offset = Vec3::new(3.4, -1.0, 6.0); - next.r_foot.ori = Quaternion::rotation_x(wave_stop * 1.2 + wave_slow * 0.2); - next.r_foot.scale = Vec3::one(); - - next.l_shoulder.offset = Vec3::new(-5.0, 0.0, 4.7); - next.l_shoulder.ori = Quaternion::rotation_x(0.0); - next.l_shoulder.scale = Vec3::one() * 1.1; - - next.r_shoulder.offset = Vec3::new(5.0, 0.0, 4.7); - next.r_shoulder.ori = Quaternion::rotation_x(0.0); - next.r_shoulder.scale = Vec3::one() * 1.1; - - next.draw.offset = Vec3::new(0.0, 5.0, 0.0); - next.draw.ori = Quaternion::rotation_y(0.0); - next.draw.scale = Vec3::one() * 0.0; - - next.torso.offset = Vec3::new(0.0, -0.2, 0.0) * skeleton_attr.scaler; - next.torso.ori = Quaternion::rotation_x(-0.2); - next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; - next } } diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 2bc2e34355..17601bb537 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -747,13 +747,21 @@ impl FigureMgr { time_since_action_change, skeleton_attr, ), + (Stand, Block { .. }) => { + anim::character::BlockIdleAnimation::update_skeleton( + &target_base, + time, + time_since_action_change, + skeleton_attr, + ) + } (_, Attack { .. }) => anim::character::AttackAnimation::update_skeleton( &target_base, time, time_since_action_change, skeleton_attr, ), - (_, Wield { .. }) => anim::character::CrunAnimation::update_skeleton( + (_, Wield { .. }) => anim::character::WieldAnimation::update_skeleton( &target_base, (vel.0.magnitude(), time), time_since_action_change, From d8223561615e1ab7d061dae979f44fd181744059 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Thu, 29 Aug 2019 20:02:13 +0200 Subject: [PATCH 11/16] Remove warning --- voxygen/src/scene/figure.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 17601bb537..bbb91f6dd2 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -14,7 +14,7 @@ use common::{ assets, comp::{ - self, humanoid, item::Tool, object, quadruped, quadruped_medium, Body, Equipment, Item, ActionState::*, Animation, Body, + self, humanoid, item::Tool, object, quadruped, quadruped_medium, Body, Equipment, Item, ActionState::*, Body, CharacterState, Last, MovementState::*, Ori, Pos, Scale, Stats, Vel, }, figure::Segment, From 9a832dd56b53acd5ddb5bd1a13eaadeec0b1cbaa Mon Sep 17 00:00:00 2001 From: timokoesters Date: Fri, 30 Aug 2019 20:40:22 +0200 Subject: [PATCH 12/16] Move std::mem::discriminant into new method --- client/src/lib.rs | 7 +------ common/src/comp/character_state.rs | 14 ++++++++++++++ server/src/lib.rs | 8 +------- voxygen/src/scene/figure.rs | 17 ++++------------- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index c0b5a4c91d..c74050b4b6 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -290,12 +290,7 @@ impl Client { { if last_character_states .get(entity) - .map(|&l| { - std::mem::discriminant(&l.0.movement) - != std::mem::discriminant(&client_character_state.movement) - || std::mem::discriminant(&l.0.action) - != std::mem::discriminant(&client_character_state.action) - }) + .map(|&l| !client_character_state.is_same_state(&l.0)) .unwrap_or(true) { let _ = last_character_states diff --git a/common/src/comp/character_state.rs b/common/src/comp/character_state.rs index c9d5c55b17..fb34afefd5 100644 --- a/common/src/comp/character_state.rs +++ b/common/src/comp/character_state.rs @@ -63,6 +63,20 @@ pub struct CharacterState { pub action: ActionState, } +impl CharacterState { + pub fn is_same_movement(&self, other: &Self) -> bool { + // Check if enum item is the same without looking at the inner data + std::mem::discriminant(&self.movement) == std::mem::discriminant(&other.movement) + } + pub fn is_same_action(&self, other: &Self) -> bool { + // Check if enum item is the same without looking at the inner data + std::mem::discriminant(&self.action) == std::mem::discriminant(&other.action) + } + pub fn is_same_state(&self, other: &Self) -> bool { + self.is_same_movement(other) && self.is_same_action(other) + } +} + impl Default for CharacterState { fn default() -> Self { Self { diff --git a/server/src/lib.rs b/server/src/lib.rs index df0be23575..c1ebb8d86b 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -1161,13 +1161,7 @@ impl Server { { if last_character_state .get(entity) - .map(|&l| { - // Check if enum item is the same without looking at the inner data - std::mem::discriminant(&l.0.movement) - != std::mem::discriminant(&client_character_state.movement) - || std::mem::discriminant(&l.0.action) - != std::mem::discriminant(&client_character_state.action) - }) + .map(|&l| !client_character_state.is_same_state(&l.0)) .unwrap_or(true) { let _ = diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index bbb91f6dd2..f6993f8bbe 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -691,15 +691,10 @@ impl FigureMgr { _ => continue, }; - if std::mem::discriminant(&last_character.0.movement) - != std::mem::discriminant(&character.movement) - { + if !character.is_same_movement(&last_character.0) { state.last_movement_change = Instant::now(); } - - if std::mem::discriminant(&last_character.0.action) - != std::mem::discriminant(&character.action) - { + if !character.is_same_action(&last_character.0) { state.last_action_change = Instant::now(); } @@ -790,9 +785,7 @@ impl FigureMgr { _ => continue, }; - if std::mem::discriminant(&last_character.0.movement) - != std::mem::discriminant(&character.movement) - { + if !character.is_same_movement(&last_character.0) { state.last_movement_change = Instant::now(); } @@ -839,9 +832,7 @@ impl FigureMgr { _ => continue, }; - if std::mem::discriminant(&last_character.0.movement) - != std::mem::discriminant(&character.movement) - { + if !character.is_same_movement(&last_character.0) { state.last_movement_change = Instant::now(); } From b81cd6a8f9a2b11f905fa2cc26d7d74783f2a31f Mon Sep 17 00:00:00 2001 From: jshipsey Date: Fri, 30 Aug 2019 22:37:27 -0400 Subject: [PATCH 13/16] combine character.action movement blocks --- common/src/sys/movement.rs | 9 +-------- voxygen/src/anim/character/run.rs | 21 ++++++++++++++++++--- voxygen/src/scene/figure.rs | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/common/src/sys/movement.rs b/common/src/sys/movement.rs index 1042989bb6..3d2b767dfd 100644 --- a/common/src/sys/movement.rs +++ b/common/src/sys/movement.rs @@ -83,14 +83,7 @@ impl<'a> System<'a> for Sys { .unwrap_or(Vec2::from(vel.0).try_normalized().unwrap_or_default()) * ROLL_SPEED } - if character.action.is_block() { - vel.0 += Vec2::broadcast(dt.0) - * controller.move_dir - * match (physics.on_ground) { - (true) if vel.0.magnitude_squared() < BLOCK_SPEED.powf(2.0) => BLOCK_ACCEL, - _ => 0.0, - } - } else if character.action.is_attack() { + if character.action.is_block() || character.action.is_attack() { vel.0 += Vec2::broadcast(dt.0) * controller.move_dir * match (physics.on_ground) { diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index a0b1b6d008..759ae0c396 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -10,11 +10,11 @@ pub struct RunAnimation; impl Animation for RunAnimation { type Skeleton = CharacterSkeleton; - type Dependency = (f32, f64); + type Dependency = (f32, f32, f64); fn update_skeleton( skeleton: &Self::Skeleton, - (velocity, global_time): Self::Dependency, + (velocity, orientation, global_time): Self::Dependency, anim_time: f64, skeleton_attr: &SkeletonAttr, ) -> Self::Skeleton { @@ -38,6 +38,20 @@ impl Animation for RunAnimation { .sin() * 0.1, ); + + let vel = Vec2::from(velocity); + let ori = (Vec2::from(orientation)).normalized(); + + let _tilt = if Vec2::new(ori, vel) + .map(|v| Vec2::::from(v).magnitude_squared()) + .reduce_partial_min() + > 0.001 + { + vel.normalized().dot(ori.normalized()).min(1.0).acos() + } else { + 0.0 + }; + next.head.offset = Vec3::new( 0.0, -1.0 + skeleton_attr.neck_forward, @@ -106,7 +120,8 @@ impl Animation for RunAnimation { next.torso.offset = Vec3::new(0.0, -0.2 + wave * -0.08, 0.4) * skeleton_attr.scaler; next.torso.ori = - Quaternion::rotation_x(wave_stop * velocity * -0.06 + wave_diff * velocity * -0.005); + Quaternion::rotation_x(wave_stop * velocity * -0.06 + wave_diff * velocity * -0.005) + * Quaternion::rotation_y(0.0); next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; next diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index f6993f8bbe..df479a3660 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -711,7 +711,7 @@ impl FigureMgr { ), Run => anim::character::RunAnimation::update_skeleton( &CharacterSkeleton::new(), - (vel.0.magnitude(), time), + (vel.0.magnitude(), ori.0.magnitude(), time), time_since_movement_change, skeleton_attr, ), From 3c473d6d6c343f256c6ad4a238457d57022a0613 Mon Sep 17 00:00:00 2001 From: jshipsey Date: Fri, 30 Aug 2019 23:01:29 -0400 Subject: [PATCH 14/16] rebase --- voxygen/src/scene/figure.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index df479a3660..98fbe6796d 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -13,9 +13,8 @@ use client::Client; use common::{ assets, comp::{ - - self, humanoid, item::Tool, object, quadruped, quadruped_medium, Body, Equipment, Item, ActionState::*, Body, - CharacterState, Last, MovementState::*, Ori, Pos, Scale, Stats, Vel, + self, humanoid, item::Tool, object, quadruped, quadruped_medium, ActionState::*, Body, + CharacterState, Equipment, Item, Last, MovementState::*, Ori, Pos, Scale, Stats, Vel, }, figure::Segment, terrain::TerrainChunkSize, From bb71bdd4a2b5b4b3bc2126c6c66dcb6e126da0cb Mon Sep 17 00:00:00 2001 From: jshipsey Date: Fri, 30 Aug 2019 23:18:56 -0400 Subject: [PATCH 15/16] removing to make gitlab compiler happy --- voxygen/src/scene/figure.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 98fbe6796d..3a868bf71b 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -13,7 +13,7 @@ use client::Client; use common::{ assets, comp::{ - self, humanoid, item::Tool, object, quadruped, quadruped_medium, ActionState::*, Body, + humanoid, item::Tool, object, quadruped, quadruped_medium, ActionState::*, Body, CharacterState, Equipment, Item, Last, MovementState::*, Ori, Pos, Scale, Stats, Vel, }, figure::Segment, From ecbf7cad5beb246b0536e762e31706c08698d884 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Sat, 31 Aug 2019 09:00:20 +0200 Subject: [PATCH 16/16] Remove old code --- client/src/lib.rs | 6 ------ common/src/comp/animation.rs | 37 ------------------------------------ common/src/comp/mod.rs | 2 -- common/src/state.rs | 3 --- 4 files changed, 48 deletions(-) delete mode 100644 common/src/comp/animation.rs diff --git a/client/src/lib.rs b/client/src/lib.rs index c74050b4b6..1dd3cc0e1c 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -100,12 +100,6 @@ impl Client { // We reduce the thread count by 1 to keep rendering smooth thread_pool.set_num_threads((num_cpus::get() - 1).max(1)); - // Set client-only components - let _ = state - .ecs_mut() - .write_storage() - .insert(entity, comp::AnimationInfo::default()); - Ok(Self { client_state, thread_pool, diff --git a/common/src/comp/animation.rs b/common/src/comp/animation.rs deleted file mode 100644 index 001d292059..0000000000 --- a/common/src/comp/animation.rs +++ /dev/null @@ -1,37 +0,0 @@ -use specs::{Component, FlaggedStorage}; -use specs_idvs::IDVStorage; - -#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] -pub enum Animation { - Idle, - Stand, - Run, - Lean, - Jump, - Gliding, - Attack, - Block, - Roll, - Crun, - Cidle, - Cjump, -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] -pub struct AnimationInfo { - pub animation: Animation, - pub time: f64, -} - -impl Default for AnimationInfo { - fn default() -> Self { - Self { - animation: Animation::Idle, - time: 0.0, - } - } -} - -impl Component for AnimationInfo { - type Storage = FlaggedStorage>; -} diff --git a/common/src/comp/mod.rs b/common/src/comp/mod.rs index 18bb53be8b..450b67b271 100644 --- a/common/src/comp/mod.rs +++ b/common/src/comp/mod.rs @@ -1,6 +1,5 @@ mod admin; mod agent; -mod animation; mod body; mod character_state; mod controller; @@ -15,7 +14,6 @@ mod visual; // Reexports pub use admin::Admin; pub use agent::Agent; -pub use animation::{Animation, AnimationInfo}; pub use body::{humanoid, object, quadruped, quadruped_medium, Body}; pub use character_state::{ActionState, CharacterState, MovementState}; pub use controller::Controller; diff --git a/common/src/state.rs b/common/src/state.rs index fbe80d206b..43c9d5a9ba 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -133,9 +133,6 @@ impl State { ecs.register::(); ecs.register::(); - // Register client-local components - ecs.register::(); - // Register server-local components ecs.register::>(); ecs.register::>();