Make character anims conditional by Tool held

This commit is contained in:
Adam Whitehurst
2019-11-10 15:36:47 -08:00
parent 5fe1eecf1f
commit 64a0d8d91f
17 changed files with 114 additions and 107 deletions

View File

@ -2,6 +2,7 @@ use super::{
super::{Animation, SkeletonAttr}, super::{Animation, SkeletonAttr},
CharacterSkeleton, CharacterSkeleton,
}; };
use common::comp::item::Tool;
use std::f32::consts::PI; use std::f32::consts::PI;
use vek::*; use vek::*;
@ -12,11 +13,11 @@ pub struct AttackAnimation;
impl Animation for AttackAnimation { impl Animation for AttackAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = f64; type Dependency = (Option<Tool>, f64);
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
_global_time: f64, (_active_tool_kind, _global_time): Self::Dependency,
anim_time: f64, anim_time: f64,
_rate: &mut f32, _rate: &mut f32,
skeleton_attr: &SkeletonAttr, skeleton_attr: &SkeletonAttr,

View File

@ -13,11 +13,11 @@ pub struct BlockAnimation;
impl Animation for BlockAnimation { impl Animation for BlockAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = f64; type Dependency = (Option<Tool>, f64);
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
global_time: f64, (active_tool_kind, global_time): Self::Dependency,
anim_time: f64, anim_time: f64,
_rate: &mut f32, _rate: &mut f32,
skeleton_attr: &SkeletonAttr, skeleton_attr: &SkeletonAttr,
@ -63,9 +63,9 @@ impl Animation for BlockAnimation {
next.shorts.ori = Quaternion::rotation_x(0.1); next.shorts.ori = Quaternion::rotation_x(0.1);
next.shorts.scale = Vec3::one(); next.shorts.scale = Vec3::one();
match Tool::Hammer { match active_tool_kind {
//TODO: Inventory //TODO: Inventory
Tool::Sword => { Some(Tool::Sword) => {
next.l_hand.offset = Vec3::new(-6.0, 3.5, 0.0 + wave_ultra_slow * 1.0); 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.ori = Quaternion::rotation_x(-0.3);
next.l_hand.scale = Vec3::one() * 1.01; next.l_hand.scale = Vec3::one() * 1.01;
@ -82,7 +82,7 @@ impl Animation for BlockAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Axe => { Some(Tool::Axe) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -107,7 +107,7 @@ impl Animation for BlockAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Hammer => { Some(Tool::Hammer) => {
next.l_hand.offset = Vec3::new(-7.0, 3.5, 6.5); next.l_hand.offset = Vec3::new(-7.0, 3.5, 6.5);
next.l_hand.ori = Quaternion::rotation_x(2.07) next.l_hand.ori = Quaternion::rotation_x(2.07)
* Quaternion::rotation_y(0.0) * Quaternion::rotation_y(0.0)
@ -128,7 +128,7 @@ impl Animation for BlockAnimation {
* Quaternion::rotation_z(-0.85); * Quaternion::rotation_z(-0.85);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Staff => { Some(Tool::Staff) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -153,7 +153,7 @@ impl Animation for BlockAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Shield => { Some(Tool::Shield) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -178,7 +178,7 @@ impl Animation for BlockAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Bow => { Some(Tool::Bow) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -203,7 +203,7 @@ impl Animation for BlockAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Dagger => { Some(Tool::Dagger) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -224,7 +224,7 @@ impl Animation for BlockAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Debug(_) => { Some(Tool::Debug(_)) => {
next.l_hand.offset = Vec3::new(-7.0, 3.5, 6.5); next.l_hand.offset = Vec3::new(-7.0, 3.5, 6.5);
next.l_hand.ori = Quaternion::rotation_x(2.07) next.l_hand.ori = Quaternion::rotation_x(2.07)
* Quaternion::rotation_y(0.0) * Quaternion::rotation_y(0.0)
@ -245,6 +245,7 @@ impl Animation for BlockAnimation {
* Quaternion::rotation_z(-0.85); * Quaternion::rotation_z(-0.85);
next.weapon.scale = Vec3::one(); 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.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.ori = Quaternion::rotation_x(-0.3);

View File

@ -13,11 +13,11 @@ pub struct BlockIdleAnimation;
impl Animation for BlockIdleAnimation { impl Animation for BlockIdleAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = f64; type Dependency = (Option<Tool>, f64);
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
global_time: f64, (active_tool_kind, global_time): Self::Dependency,
anim_time: f64, anim_time: f64,
_rate: &mut f32, _rate: &mut f32,
skeleton_attr: &SkeletonAttr, skeleton_attr: &SkeletonAttr,
@ -62,9 +62,9 @@ impl Animation for BlockIdleAnimation {
next.shorts.ori = Quaternion::rotation_x(0.1); next.shorts.ori = Quaternion::rotation_x(0.1);
next.shorts.scale = Vec3::one(); next.shorts.scale = Vec3::one();
match Tool::Hammer { match active_tool_kind {
//TODO: Inventory //TODO: Inventory
Tool::Sword => { Some(Tool::Sword) => {
next.l_hand.offset = Vec3::new(-6.0, 3.5, 0.0 + wave_ultra_slow * 1.0); 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.ori = Quaternion::rotation_x(-0.3);
next.l_hand.scale = Vec3::one() * 1.01; next.l_hand.scale = Vec3::one() * 1.01;
@ -81,7 +81,7 @@ impl Animation for BlockIdleAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Axe => { Some(Tool::Axe) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -106,7 +106,7 @@ impl Animation for BlockIdleAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Hammer => { Some(Tool::Hammer) => {
next.l_hand.offset = Vec3::new(-7.0, 3.5 + wave_ultra_slow * 2.0, 6.5); next.l_hand.offset = Vec3::new(-7.0, 3.5 + wave_ultra_slow * 2.0, 6.5);
next.l_hand.ori = Quaternion::rotation_x(2.07) next.l_hand.ori = Quaternion::rotation_x(2.07)
* Quaternion::rotation_y(0.0) * Quaternion::rotation_y(0.0)
@ -127,7 +127,7 @@ impl Animation for BlockIdleAnimation {
* Quaternion::rotation_z(-0.85); * Quaternion::rotation_z(-0.85);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Staff => { Some(Tool::Staff) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -152,7 +152,7 @@ impl Animation for BlockIdleAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Shield => { Some(Tool::Shield) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -177,7 +177,7 @@ impl Animation for BlockIdleAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Bow => { Some(Tool::Bow) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -202,7 +202,7 @@ impl Animation for BlockIdleAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Dagger => { Some(Tool::Dagger) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -223,7 +223,7 @@ impl Animation for BlockIdleAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Debug(_) => { Some(Tool::Debug(_)) => {
next.l_hand.offset = Vec3::new(-7.0, 3.5 + wave_ultra_slow * 2.0, 6.5); next.l_hand.offset = Vec3::new(-7.0, 3.5 + wave_ultra_slow * 2.0, 6.5);
next.l_hand.ori = Quaternion::rotation_x(2.07) next.l_hand.ori = Quaternion::rotation_x(2.07)
* Quaternion::rotation_y(0.0) * Quaternion::rotation_y(0.0)
@ -244,6 +244,7 @@ impl Animation for BlockIdleAnimation {
* Quaternion::rotation_z(-0.85); * Quaternion::rotation_z(-0.85);
next.weapon.scale = Vec3::one(); 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.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.ori = Quaternion::rotation_x(-0.3);

View File

@ -2,6 +2,7 @@ use super::{
super::{Animation, SkeletonAttr}, super::{Animation, SkeletonAttr},
CharacterSkeleton, CharacterSkeleton,
}; };
use common::comp::item::Tool; use common::comp::item::Tool;
use std::{f32::consts::PI, ops::Mul}; use std::{f32::consts::PI, ops::Mul};
use vek::*; use vek::*;
@ -13,11 +14,11 @@ pub struct CidleAnimation;
impl Animation for CidleAnimation { impl Animation for CidleAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = f64; type Dependency = (Option<Tool>, f64);
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
global_time: f64, (active_tool_kind, global_time): Self::Dependency,
anim_time: f64, anim_time: f64,
_rate: &mut f32, _rate: &mut f32,
skeleton_attr: &SkeletonAttr, skeleton_attr: &SkeletonAttr,
@ -62,9 +63,9 @@ impl Animation for CidleAnimation {
next.shorts.ori = Quaternion::rotation_x(0.0); next.shorts.ori = Quaternion::rotation_x(0.0);
next.shorts.scale = Vec3::one(); next.shorts.scale = Vec3::one();
match Tool::Bow { match active_tool_kind {
//TODO: Inventory //TODO: Inventory
Tool::Sword => { Some(Tool::Sword) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -89,7 +90,7 @@ impl Animation for CidleAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Axe => { Some(Tool::Axe) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -114,7 +115,7 @@ impl Animation for CidleAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Hammer => { Some(Tool::Hammer) => {
next.l_hand.offset = Vec3::new(-7.0, 4.0, 3.0); next.l_hand.offset = Vec3::new(-7.0, 4.0, 3.0);
next.l_hand.ori = Quaternion::rotation_x(1.27 + wave_ultra_slow * -0.1) next.l_hand.ori = Quaternion::rotation_x(1.27 + wave_ultra_slow * -0.1)
* Quaternion::rotation_y(0.0) * Quaternion::rotation_y(0.0)
@ -135,7 +136,7 @@ impl Animation for CidleAnimation {
* Quaternion::rotation_z(wave_ultra_slow * 0.2); * Quaternion::rotation_z(wave_ultra_slow * 0.2);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Staff => { Some(Tool::Staff) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -160,7 +161,7 @@ impl Animation for CidleAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Shield => { Some(Tool::Shield) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -185,7 +186,7 @@ impl Animation for CidleAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Bow => { Some(Tool::Bow) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-4.0 + wave_ultra_slow_cos * 1.0, -4.0 + wave_ultra_slow_cos * 1.0,
5.0 + wave_ultra_slow_cos * 0.5, 5.0 + wave_ultra_slow_cos * 0.5,
@ -214,7 +215,7 @@ impl Animation for CidleAnimation {
* Quaternion::rotation_z(0.85); * Quaternion::rotation_z(0.85);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Dagger => { Some(Tool::Dagger) => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-6.0 + wave_ultra_slow_cos * 1.0, -6.0 + wave_ultra_slow_cos * 1.0,
3.5 + wave_ultra_slow_cos * 0.5, 3.5 + wave_ultra_slow_cos * 0.5,
@ -235,7 +236,7 @@ impl Animation for CidleAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Debug(_) => { Some(Tool::Debug(_)) => {
next.l_hand.offset = Vec3::new(-7.0, 4.0, 3.0); next.l_hand.offset = Vec3::new(-7.0, 4.0, 3.0);
next.l_hand.ori = Quaternion::rotation_x(1.27 + wave_ultra_slow * -0.1) next.l_hand.ori = Quaternion::rotation_x(1.27 + wave_ultra_slow * -0.1)
* Quaternion::rotation_y(0.0) * Quaternion::rotation_y(0.0)
@ -256,6 +257,7 @@ impl Animation for CidleAnimation {
* Quaternion::rotation_z(wave_ultra_slow * 0.2); * Quaternion::rotation_z(wave_ultra_slow * 0.2);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
_ => {}
} }
next.l_foot.offset = Vec3::new(-3.4, -1.5, 8.0 + wave_slow * 0.2); next.l_foot.offset = Vec3::new(-3.4, -1.5, 8.0 + wave_slow * 0.2);
next.l_foot.ori = Quaternion::rotation_x(wave_ultra_slow_cos * 0.015); next.l_foot.ori = Quaternion::rotation_x(wave_ultra_slow_cos * 0.015);

View File

@ -2,17 +2,18 @@ use super::{
super::{Animation, SkeletonAttr}, super::{Animation, SkeletonAttr},
CharacterSkeleton, CharacterSkeleton,
}; };
use common::comp::item::Tool;
use vek::*; use vek::*;
pub struct ClimbAnimation; pub struct ClimbAnimation;
impl Animation for ClimbAnimation { impl Animation for ClimbAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = (Vec3<f32>, Vec3<f32>, f64); type Dependency = (Option<Tool>, Vec3<f32>, Vec3<f32>, f64);
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(velocity, _orientation, _global_time): Self::Dependency, (_active_tool_kind, velocity, _orientation, _global_time): Self::Dependency,
anim_time: f64, anim_time: f64,
rate: &mut f32, rate: &mut f32,
skeleton_attr: &SkeletonAttr, skeleton_attr: &SkeletonAttr,

View File

@ -9,7 +9,7 @@ use vek::*;
pub struct WieldAnimation; pub struct WieldAnimation;
impl Animation for WieldAnimation { impl Animation<'_>for WieldAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = (f32, f64); type Dependency = (f32, f64);
@ -133,20 +133,12 @@ impl Animation for WieldAnimation {
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Bow => { Tool::Bow => {
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(-4.0, 5.0, 0.0);
-4.0,
5.0,
0.0,
);
next.l_hand.ori = Quaternion::rotation_x(0.0) next.l_hand.ori = Quaternion::rotation_x(0.0)
* Quaternion::rotation_y(-1.9) * Quaternion::rotation_y(-1.9)
* Quaternion::rotation_z(0.85); * Quaternion::rotation_z(0.85);
next.l_hand.scale = Vec3::one() * 1.01; next.l_hand.scale = Vec3::one() * 1.01;
next.r_hand.offset = Vec3::new( next.r_hand.offset = Vec3::new(2.0, 8.0, -3.5);
2.0,
8.0,
-3.5,
);
next.r_hand.ori = Quaternion::rotation_x(0.0) next.r_hand.ori = Quaternion::rotation_x(0.0)
* Quaternion::rotation_y(-1.7) * Quaternion::rotation_y(-1.7)
* Quaternion::rotation_z(0.85); * Quaternion::rotation_z(0.85);

View File

@ -2,6 +2,7 @@ use super::{
super::{Animation, SkeletonAttr}, super::{Animation, SkeletonAttr},
CharacterSkeleton, CharacterSkeleton,
}; };
use common::comp::item::Tool;
use std::{f32::consts::PI, ops::Mul}; use std::{f32::consts::PI, ops::Mul};
use vek::*; use vek::*;
@ -9,11 +10,11 @@ pub struct GlidingAnimation;
impl Animation for GlidingAnimation { impl Animation for GlidingAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = (Vec3<f32>, Vec3<f32>, Vec3<f32>, f64); type Dependency = (Option<Tool>, Vec3<f32>, Vec3<f32>, Vec3<f32>, f64);
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(velocity, orientation, last_ori, global_time): Self::Dependency, (_active_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency,
anim_time: f64, anim_time: f64,
_rate: &mut f32, _rate: &mut f32,
skeleton_attr: &SkeletonAttr, skeleton_attr: &SkeletonAttr,

View File

@ -2,6 +2,7 @@ use super::{
super::{Animation, SkeletonAttr}, super::{Animation, SkeletonAttr},
CharacterSkeleton, CharacterSkeleton,
}; };
use common::comp::item::Tool;
use std::f32::consts::PI; use std::f32::consts::PI;
use vek::*; use vek::*;
@ -9,11 +10,11 @@ pub struct JumpAnimation;
impl Animation for JumpAnimation { impl Animation for JumpAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = f64; type Dependency = (Option<Tool>, f64);
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
_global_time: f64, (_active_tool_kind, _global_time): Self::Dependency,
anim_time: f64, anim_time: f64,
_rate: &mut f32, _rate: &mut f32,
skeleton_attr: &SkeletonAttr, skeleton_attr: &SkeletonAttr,

View File

@ -2,6 +2,7 @@ use super::{
super::{Animation, SkeletonAttr}, super::{Animation, SkeletonAttr},
CharacterSkeleton, CharacterSkeleton,
}; };
use common::comp::item::Tool;
use std::f32::consts::PI; use std::f32::consts::PI;
use vek::*; use vek::*;
@ -9,11 +10,11 @@ pub struct RollAnimation;
impl Animation for RollAnimation { impl Animation for RollAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = f64; type Dependency = (Option<Tool>, f64);
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
_global_time: f64, (_active_tool_kind, _global_time): Self::Dependency,
anim_time: f64, anim_time: f64,
_rate: &mut f32, _rate: &mut f32,
skeleton_attr: &SkeletonAttr, skeleton_attr: &SkeletonAttr,

View File

@ -8,7 +8,7 @@ use vek::*;
pub struct SneakAnimation; pub struct SneakAnimation;
impl Animation for SneakAnimation { impl Animation<'_>for SneakAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = (Vec3<f32>, Vec3<f32>, Vec3<f32>, f64); type Dependency = (Vec3<f32>, Vec3<f32>, Vec3<f32>, f64);

View File

@ -2,6 +2,7 @@ use super::{
super::{Animation, SkeletonAttr}, super::{Animation, SkeletonAttr},
CharacterSkeleton, CharacterSkeleton,
}; };
use common::comp::item::Tool;
use std::f32::consts::PI; use std::f32::consts::PI;
use std::ops::Mul; use std::ops::Mul;
use vek::*; use vek::*;
@ -10,11 +11,11 @@ pub struct RunAnimation;
impl Animation for RunAnimation { impl Animation for RunAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = (Vec3<f32>, Vec3<f32>, Vec3<f32>, f64); type Dependency = (Option<Tool>, Vec3<f32>, Vec3<f32>, Vec3<f32>, f64);
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(velocity, orientation, last_ori, global_time): Self::Dependency, (_active_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency,
anim_time: f64, anim_time: f64,
rate: &mut f32, rate: &mut f32,
skeleton_attr: &SkeletonAttr, skeleton_attr: &SkeletonAttr,

View File

@ -2,6 +2,7 @@ use super::{
super::{Animation, SkeletonAttr}, super::{Animation, SkeletonAttr},
CharacterSkeleton, CharacterSkeleton,
}; };
use common::comp::item::Tool;
use std::{f32::consts::PI, ops::Mul}; use std::{f32::consts::PI, ops::Mul};
use vek::*; use vek::*;
@ -9,11 +10,11 @@ pub struct SitAnimation;
impl Animation for SitAnimation { impl Animation for SitAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = f64; type Dependency = (Option<Tool>, f64);
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
global_time: f64, (_active_tool_kind, global_time): Self::Dependency,
anim_time: f64, anim_time: f64,
_rate: &mut f32, _rate: &mut f32,
skeleton_attr: &SkeletonAttr, skeleton_attr: &SkeletonAttr,

View File

@ -8,7 +8,7 @@ use vek::*;
pub struct SneakAnimation; pub struct SneakAnimation;
impl Animation for SneakAnimation { impl Animation<'_>for SneakAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = (Vec3<f32>, Vec3<f32>, Vec3<f32>, f64); type Dependency = (Vec3<f32>, Vec3<f32>, Vec3<f32>, f64);
@ -93,20 +93,12 @@ impl Animation for SneakAnimation {
next.shorts.ori = Quaternion::rotation_x(0.2) * Quaternion::rotation_z(wave * 0.4); next.shorts.ori = Quaternion::rotation_x(0.2) * Quaternion::rotation_z(wave * 0.4);
next.shorts.scale = Vec3::one(); next.shorts.scale = Vec3::one();
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(-5.0 + wave_stop * -0.5, 2.25, 4.0 - wave * 1.0);
-5.0 + wave_stop * -0.5,
2.25,
4.0 - wave * 1.0,
);
next.l_hand.ori = next.l_hand.ori =
Quaternion::rotation_x(1.5 + wave_cos * 0.1) * Quaternion::rotation_y(wave_stop * 0.1); Quaternion::rotation_x(1.5 + wave_cos * 0.1) * Quaternion::rotation_y(wave_stop * 0.1);
next.l_hand.scale = Vec3::one(); next.l_hand.scale = Vec3::one();
next.r_hand.offset = Vec3::new( next.r_hand.offset = Vec3::new(5.0 + wave_stop * 0.5, 2.25, 4.0 + wave * 1.0);
5.0 + wave_stop * 0.5,
2.25,
4.0 + wave * 1.0,
);
next.r_hand.ori = Quaternion::rotation_x(1.5 + wave_cos * -0.1) next.r_hand.ori = Quaternion::rotation_x(1.5 + wave_cos * -0.1)
* Quaternion::rotation_y(wave_stop * -0.1); * Quaternion::rotation_y(wave_stop * -0.1);
next.r_hand.scale = Vec3::one(); next.r_hand.scale = Vec3::one();

View File

@ -2,6 +2,7 @@ use super::{
super::{Animation, SkeletonAttr}, super::{Animation, SkeletonAttr},
CharacterSkeleton, CharacterSkeleton,
}; };
use common::comp::item::Tool;
use std::{f32::consts::PI, ops::Mul}; use std::{f32::consts::PI, ops::Mul};
use vek::*; use vek::*;
@ -9,11 +10,10 @@ pub struct StandAnimation;
impl Animation for StandAnimation { impl Animation for StandAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = f64; type Dependency = (Option<Tool>, f64);
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
global_time: f64, (_active_tool_kind, global_time): Self::Dependency,
anim_time: f64, anim_time: f64,
_rate: &mut f32, _rate: &mut f32,
skeleton_attr: &SkeletonAttr, skeleton_attr: &SkeletonAttr,

View File

@ -2,6 +2,7 @@ use super::{
super::{Animation, SkeletonAttr}, super::{Animation, SkeletonAttr},
CharacterSkeleton, CharacterSkeleton,
}; };
use common::comp::item::Tool;
use std::f32::consts::PI; use std::f32::consts::PI;
use std::ops::Mul; use std::ops::Mul;
use vek::*; use vek::*;
@ -10,11 +11,11 @@ pub struct SwimAnimation;
impl Animation for SwimAnimation { impl Animation for SwimAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = (f32, f32, f64); type Dependency = (Option<Tool>, f32, f32, f64);
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(velocity, orientation, global_time): Self::Dependency, (_active_tool_kind, velocity, orientation, global_time): Self::Dependency,
anim_time: f64, anim_time: f64,
_rate: &mut f32, _rate: &mut f32,
skeleton_attr: &SkeletonAttr, skeleton_attr: &SkeletonAttr,

View File

@ -9,11 +9,11 @@ pub struct WieldAnimation;
impl Animation for WieldAnimation { impl Animation for WieldAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = (f32, f64); type Dependency = (Option<Tool>, f32, f64);
fn update_skeleton( fn update_skeleton(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(_velocity, _global_time): Self::Dependency, (active_tool_kind, _velocity, _global_time): Self::Dependency,
anim_time: f64, anim_time: f64,
_rate: &mut f32, _rate: &mut f32,
skeleton_attr: &SkeletonAttr, skeleton_attr: &SkeletonAttr,
@ -22,9 +22,9 @@ impl Animation for WieldAnimation {
let wave = (anim_time as f32 * 12.0).sin(); let wave = (anim_time as f32 * 12.0).sin();
match Tool::Bow { match active_tool_kind {
//TODO: Inventory //TODO: Inventory
Tool::Sword => { Some(Tool::Sword) => {
next.l_hand.offset = Vec3::new(-6.0, 3.75, 0.25); next.l_hand.offset = Vec3::new(-6.0, 3.75, 0.25);
next.l_hand.ori = Quaternion::rotation_x(-0.3); next.l_hand.ori = Quaternion::rotation_x(-0.3);
next.l_hand.scale = Vec3::one() * 1.01; next.l_hand.scale = Vec3::one() * 1.01;
@ -41,7 +41,7 @@ impl Animation for WieldAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Axe => { Some(Tool::Axe) => {
next.l_hand.offset = Vec3::new(-6.0, 3.5, 0.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.ori = Quaternion::rotation_x(-0.3);
next.l_hand.scale = Vec3::one() * 1.01; next.l_hand.scale = Vec3::one() * 1.01;
@ -58,7 +58,7 @@ impl Animation for WieldAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Hammer => { Some(Tool::Hammer) => {
next.l_hand.offset = Vec3::new(-7.0, 4.0, 3.0); next.l_hand.offset = Vec3::new(-7.0, 4.0, 3.0);
next.l_hand.ori = Quaternion::rotation_x(1.27 + wave * 0.25) next.l_hand.ori = Quaternion::rotation_x(1.27 + wave * 0.25)
* Quaternion::rotation_y(0.0) * Quaternion::rotation_y(0.0)
@ -79,7 +79,7 @@ impl Animation for WieldAnimation {
* Quaternion::rotation_z(wave * -0.25); * Quaternion::rotation_z(wave * -0.25);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Staff => { Some(Tool::Staff) => {
next.l_hand.offset = Vec3::new(-6.0, 3.5, 0.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.ori = Quaternion::rotation_x(-0.3);
next.l_hand.scale = Vec3::one() * 1.01; next.l_hand.scale = Vec3::one() * 1.01;
@ -96,7 +96,7 @@ impl Animation for WieldAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Shield => { Some(Tool::Shield) => {
next.l_hand.offset = Vec3::new(-6.0, 3.5, 0.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.ori = Quaternion::rotation_x(-0.3);
next.l_hand.scale = Vec3::one() * 1.01; next.l_hand.scale = Vec3::one() * 1.01;
@ -113,7 +113,7 @@ impl Animation for WieldAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Bow => { Some(Tool::Bow) => {
next.l_hand.offset = Vec3::new(-4.0, 5.0, 0.0); next.l_hand.offset = Vec3::new(-4.0, 5.0, 0.0);
next.l_hand.ori = Quaternion::rotation_x(0.0) next.l_hand.ori = Quaternion::rotation_x(0.0)
* Quaternion::rotation_y(-1.9) * Quaternion::rotation_y(-1.9)
@ -134,7 +134,7 @@ impl Animation for WieldAnimation {
* Quaternion::rotation_z(0.85); * Quaternion::rotation_z(0.85);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Dagger => { Some(Tool::Dagger) => {
next.l_hand.offset = Vec3::new(-6.0, 3.5, 0.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.ori = Quaternion::rotation_x(-0.3);
next.l_hand.scale = Vec3::one() * 1.01; next.l_hand.scale = Vec3::one() * 1.01;
@ -151,7 +151,7 @@ impl Animation for WieldAnimation {
* Quaternion::rotation_z(0.0); * Quaternion::rotation_z(0.0);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
Tool::Debug(_) => { Some(Tool::Debug(_)) => {
next.l_hand.offset = Vec3::new(-7.0, 4.0, 3.0); next.l_hand.offset = Vec3::new(-7.0, 4.0, 3.0);
next.l_hand.ori = Quaternion::rotation_x(1.27 + wave * 0.25) next.l_hand.ori = Quaternion::rotation_x(1.27 + wave * 0.25)
* Quaternion::rotation_y(0.0) * Quaternion::rotation_y(0.0)
@ -172,6 +172,7 @@ impl Animation for WieldAnimation {
* Quaternion::rotation_z(wave * -0.25); * Quaternion::rotation_z(wave * -0.25);
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
} }
_ => {}
} }
next next

View File

@ -18,7 +18,8 @@ use crate::{
use client::Client; use client::Client;
use common::{ use common::{
comp::{ comp::{
ActionState::*, Body, CharacterState, Last, MovementState::*, Ori, Pos, Scale, Stats, Vel, ActionState::*, Body, CharacterState, ItemKind, Last, MovementState::*, Ori, Pos, Scale,
Stats, Vel,
}, },
terrain::TerrainChunk, terrain::TerrainChunk,
vol::RectRasterableVol, vol::RectRasterableVol,
@ -168,6 +169,15 @@ impl FigureMgr {
.cloned() .cloned()
.unwrap_or_default(); .unwrap_or_default();
let active_tool_kind = if let Some(ItemKind::Tool { kind, .. }) = stats
.and_then(|s| s.equipment.main.as_ref())
.map(|i| &i.kind)
{
Some(*kind)
} else {
None
};
match body { match body {
Body::Humanoid(_) => { Body::Humanoid(_) => {
let state = self let state = self
@ -189,56 +199,56 @@ impl FigureMgr {
let target_base = match &character.movement { let target_base = match &character.movement {
Stand => anim::character::StandAnimation::update_skeleton( Stand => anim::character::StandAnimation::update_skeleton(
&CharacterSkeleton::new(), &CharacterSkeleton::new(),
time, (active_tool_kind, time),
state.movement_time, state.movement_time,
&mut movement_animation_rate, &mut movement_animation_rate,
skeleton_attr, skeleton_attr,
), ),
Run => anim::character::RunAnimation::update_skeleton( Run => anim::character::RunAnimation::update_skeleton(
&CharacterSkeleton::new(), &CharacterSkeleton::new(),
(vel.0, ori.0, state.last_ori, time), (active_tool_kind, vel.0, ori.0, state.last_ori, time),
state.movement_time, state.movement_time,
&mut movement_animation_rate, &mut movement_animation_rate,
skeleton_attr, skeleton_attr,
), ),
Jump => anim::character::JumpAnimation::update_skeleton( Jump => anim::character::JumpAnimation::update_skeleton(
&CharacterSkeleton::new(), &CharacterSkeleton::new(),
time, (active_tool_kind, time),
state.movement_time, state.movement_time,
&mut movement_animation_rate, &mut movement_animation_rate,
skeleton_attr, skeleton_attr,
), ),
Roll { .. } => anim::character::RollAnimation::update_skeleton( Roll { .. } => anim::character::RollAnimation::update_skeleton(
&CharacterSkeleton::new(), &CharacterSkeleton::new(),
time, (active_tool_kind, time),
state.movement_time, state.movement_time,
&mut movement_animation_rate, &mut movement_animation_rate,
skeleton_attr, skeleton_attr,
), ),
Glide => anim::character::GlidingAnimation::update_skeleton( Glide => anim::character::GlidingAnimation::update_skeleton(
&CharacterSkeleton::new(), &CharacterSkeleton::new(),
(vel.0, ori.0, state.last_ori, time), (active_tool_kind, vel.0, ori.0, state.last_ori, time),
state.movement_time, state.movement_time,
&mut movement_animation_rate, &mut movement_animation_rate,
skeleton_attr, skeleton_attr,
), ),
Swim => anim::character::SwimAnimation::update_skeleton( Swim => anim::character::SwimAnimation::update_skeleton(
&CharacterSkeleton::new(), &CharacterSkeleton::new(),
(vel.0.magnitude(), ori.0.magnitude(), time), (active_tool_kind, vel.0.magnitude(), ori.0.magnitude(), time),
state.movement_time, state.movement_time,
&mut movement_animation_rate, &mut movement_animation_rate,
skeleton_attr, skeleton_attr,
), ),
Climb => anim::character::ClimbAnimation::update_skeleton( Climb => anim::character::ClimbAnimation::update_skeleton(
&CharacterSkeleton::new(), &CharacterSkeleton::new(),
(vel.0, ori.0, time), (active_tool_kind, vel.0, ori.0, time),
state.movement_time, state.movement_time,
&mut movement_animation_rate, &mut movement_animation_rate,
skeleton_attr, skeleton_attr,
), ),
Sit => anim::character::SitAnimation::update_skeleton( Sit => anim::character::SitAnimation::update_skeleton(
&CharacterSkeleton::new(), &CharacterSkeleton::new(),
time, (active_tool_kind, time),
state.movement_time, state.movement_time,
&mut movement_animation_rate, &mut movement_animation_rate,
skeleton_attr, skeleton_attr,
@ -248,7 +258,7 @@ impl FigureMgr {
let target_bones = match (&character.movement, &character.action) { let target_bones = match (&character.movement, &character.action) {
(Stand, Wield { .. }) => anim::character::CidleAnimation::update_skeleton( (Stand, Wield { .. }) => anim::character::CidleAnimation::update_skeleton(
&target_base, &target_base,
time, (active_tool_kind, time),
state.action_time, state.action_time,
&mut action_animation_rate, &mut action_animation_rate,
skeleton_attr, skeleton_attr,
@ -256,7 +266,7 @@ impl FigureMgr {
(Stand, Block { .. }) => { (Stand, Block { .. }) => {
anim::character::BlockIdleAnimation::update_skeleton( anim::character::BlockIdleAnimation::update_skeleton(
&target_base, &target_base,
time, (active_tool_kind, time),
state.action_time, state.action_time,
&mut action_animation_rate, &mut action_animation_rate,
skeleton_attr, skeleton_attr,
@ -264,21 +274,21 @@ impl FigureMgr {
} }
(_, Attack { .. }) => anim::character::AttackAnimation::update_skeleton( (_, Attack { .. }) => anim::character::AttackAnimation::update_skeleton(
&target_base, &target_base,
time, (active_tool_kind, time),
state.action_time, state.action_time,
&mut action_animation_rate, &mut action_animation_rate,
skeleton_attr, skeleton_attr,
), ),
(_, Wield { .. }) => anim::character::WieldAnimation::update_skeleton( (_, Wield { .. }) => anim::character::WieldAnimation::update_skeleton(
&target_base, &target_base,
(vel.0.magnitude(), time), (active_tool_kind, vel.0.magnitude(), time),
state.action_time, state.action_time,
&mut action_animation_rate, &mut action_animation_rate,
skeleton_attr, skeleton_attr,
), ),
(_, Block { .. }) => anim::character::BlockAnimation::update_skeleton( (_, Block { .. }) => anim::character::BlockAnimation::update_skeleton(
&target_base, &target_base,
time, (active_tool_kind, time),
state.action_time, state.action_time,
&mut action_animation_rate, &mut action_animation_rate,
skeleton_attr, skeleton_attr,