From 37c733a06760e23abcfa0d5515ccaf6b527f7caa Mon Sep 17 00:00:00 2001 From: jshipsey Date: Sat, 8 Aug 2020 17:04:50 -0400 Subject: [PATCH] clippy, consdensed climb, corrected some swim bugs --- voxygen/src/anim/src/character/climb.rs | 302 ++++++++---------------- voxygen/src/anim/src/character/sneak.rs | 5 +- voxygen/src/anim/src/character/swim.rs | 14 +- 3 files changed, 102 insertions(+), 219 deletions(-) diff --git a/voxygen/src/anim/src/character/climb.rs b/voxygen/src/anim/src/character/climb.rs index adcb48b5c4..aee0be362b 100644 --- a/voxygen/src/anim/src/character/climb.rs +++ b/voxygen/src/anim/src/character/climb.rs @@ -28,7 +28,7 @@ impl Animation for ClimbAnimation { skeleton_attr: &SkeletonAttr, ) -> Self::Skeleton { let mut next = (*skeleton).clone(); - + let lateral = Vec2::::from(velocity).magnitude(); let speed = velocity.z; *rate = speed; let constant = 1.0; @@ -60,7 +60,8 @@ impl Animation for ClimbAnimation { .sin() * 0.15, ); - if speed > 0.7 { + let stagnant = if speed > -0.7 { 1.0 } else { 0.0 }; //sets static position when there is no movement + if speed > 0.7 || lateral > 0.1 { next.head.offset = Vec3::new( 0.0, -4.0 + skeleton_attr.head.0, @@ -203,232 +204,113 @@ impl Animation for ClimbAnimation { next.torso.offset = Vec3::new(0.0, -0.2 + smooth * -0.08, 0.4) * skeleton_attr.scaler; next.torso.ori = Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0); next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; - - next.control.scale = Vec3::one(); - - next.l_control.scale = Vec3::one(); - - next.r_control.scale = Vec3::one(); } else { - if speed > -0.7 { - next.head.offset = - Vec3::new(0.0, -2.0 + skeleton_attr.head.0, skeleton_attr.head.1); - next.head.ori = Quaternion::rotation_x(2.0 * head_look.y.abs()) - * Quaternion::rotation_z(3.5 * head_look.x.abs()); - next.head.scale = Vec3::one() * skeleton_attr.head_scale; + next.head.offset = Vec3::new( + 0.0, + -1.0 - stagnant + skeleton_attr.head.0, + skeleton_attr.head.1, + ); + next.head.ori = Quaternion::rotation_x( + -0.25 * (1.0 - stagnant) + stagnant * 2.0 * head_look.x.abs(), + ) * Quaternion::rotation_z(stagnant * 3.5 * head_look.x.abs()); + next.head.scale = Vec3::one() * skeleton_attr.head_scale; - next.chest.offset = Vec3::new( - 0.0, - -2.0 + skeleton_attr.chest.0 + 3.0, - skeleton_attr.chest.1, - ); - next.chest.ori = Quaternion::rotation_z(0.0) - * Quaternion::rotation_x(0.3) - * Quaternion::rotation_z(0.6); - next.chest.scale = Vec3::one(); + next.chest.offset = Vec3::new(0.0, 1.0 + skeleton_attr.chest.0, skeleton_attr.chest.1); + next.chest.ori = Quaternion::rotation_z(0.6 * stagnant) + * Quaternion::rotation_x((0.2 + drop * 0.05) * (1.0 - stagnant)); + next.chest.scale = Vec3::one(); - next.belt.offset = Vec3::new(0.0, skeleton_attr.belt.0 + 0.5, skeleton_attr.belt.1); - next.belt.ori = Quaternion::rotation_z(0.0) * Quaternion::rotation_x(0.1); - next.belt.scale = Vec3::one(); + next.belt.offset = Vec3::new(0.0, skeleton_attr.belt.0 + 0.5, skeleton_attr.belt.1); + next.belt.ori = Quaternion::rotation_x(0.1 + dropa * 0.1); + next.belt.scale = Vec3::one(); - next.back.offset = Vec3::new(0.0, skeleton_attr.back.0, skeleton_attr.back.1); - next.back.ori = Quaternion::rotation_x(-0.2); - next.back.scale = Vec3::one() * 1.02; + next.back.offset = Vec3::new(0.0, skeleton_attr.back.0, skeleton_attr.back.1); + next.back.ori = Quaternion::rotation_x( + -0.2 + dropa * 0.1 - 0.15 * (1.0 - stagnant) + stagnant * 0.1, + ); + next.back.scale = Vec3::one() * 1.02; - next.shorts.offset = - Vec3::new(0.0, skeleton_attr.shorts.0 + 1.0, skeleton_attr.shorts.1); - next.shorts.ori = Quaternion::rotation_z(0.0) - * Quaternion::rotation_x(0.1) - * Quaternion::rotation_y(0.0); - next.shorts.scale = Vec3::one(); + next.shorts.offset = + Vec3::new(0.0, skeleton_attr.shorts.0 + 1.0, skeleton_attr.shorts.1); + next.shorts.ori = Quaternion::rotation_x(0.1 + dropa * 0.12 * (1.0 - stagnant)); + next.shorts.scale = Vec3::one(); - next.l_hand.offset = Vec3::new( - -skeleton_attr.hand.0, - 2.0 + skeleton_attr.hand.1, - skeleton_attr.hand.2, - ); - next.l_hand.ori = Quaternion::rotation_x(0.8); - next.l_hand.scale = Vec3::one(); + next.l_hand.offset = Vec3::new( + -skeleton_attr.hand.0, + 7.5 + stagnant * -5.0 + skeleton_attr.hand.1, + 7.0 + stagnant * -7.0 + skeleton_attr.hand.2 + dropa * -1.0 * (1.0 - stagnant), + ); + next.l_hand.ori = Quaternion::rotation_x(2.2 + stagnant * -1.4) + * Quaternion::rotation_y((0.3 + dropa * 0.1) * (1.0 - stagnant)); + next.l_hand.scale = Vec3::one(); - next.r_hand.offset = Vec3::new( - skeleton_attr.hand.0, - 5.5 + skeleton_attr.hand.1, - 5.0 + skeleton_attr.hand.2, - ); - next.r_hand.ori = Quaternion::rotation_x(2.2) * Quaternion::rotation_y(-0.5); - next.r_hand.scale = Vec3::one(); + next.r_hand.offset = Vec3::new( + skeleton_attr.hand.0, + 7.5 + stagnant * -2.5 + skeleton_attr.hand.1, + 5.0 + skeleton_attr.hand.2 + drop * -1.0 * (1.0 - stagnant), + ); + next.r_hand.ori = Quaternion::rotation_x(2.2) + * Quaternion::rotation_y(-0.3 + drop * 0.1 * (1.0 - stagnant)); + next.r_hand.scale = Vec3::one(); - next.l_foot.offset = Vec3::new( - -skeleton_attr.foot.0, - 5.0 + skeleton_attr.foot.1, - 1.0 + skeleton_attr.foot.2, - ); - next.l_foot.ori = Quaternion::rotation_x(0.55); - next.l_foot.scale = Vec3::one(); + next.l_foot.offset = Vec3::new( + -skeleton_attr.foot.0, + 4.0 + stagnant * 3.0 + skeleton_attr.foot.1, + 1.0 + skeleton_attr.foot.2 + drop * -2.0 * (1.0 - stagnant), + ); + next.l_foot.ori = Quaternion::rotation_x(0.55 + drop * 0.1 * (1.0 - stagnant)); + next.l_foot.scale = Vec3::one(); - next.r_foot.offset = Vec3::new( - skeleton_attr.foot.0, - 5.0 + skeleton_attr.foot.1, - -2.0 + skeleton_attr.foot.2, - ); - next.r_foot.ori = Quaternion::rotation_x(0.2); - next.r_foot.scale = Vec3::one(); + next.r_foot.offset = Vec3::new( + skeleton_attr.foot.0, + 2.0 + stagnant * 4.0 + skeleton_attr.foot.1, + -2.0 + skeleton_attr.foot.2 + smooth * 1.0 * (1.0 - stagnant), + ); + next.r_foot.ori = Quaternion::rotation_x(0.2 + smooth * 0.15 * (1.0 - stagnant)); + next.r_foot.scale = Vec3::one(); - next.l_shoulder.offset = Vec3::new( - -skeleton_attr.shoulder.0, - skeleton_attr.shoulder.1, - skeleton_attr.shoulder.2, - ); - next.l_shoulder.ori = Quaternion::rotation_x(0.0); - next.l_shoulder.scale = Vec3::one() * 1.1; + next.l_shoulder.offset = Vec3::new( + -skeleton_attr.shoulder.0, + skeleton_attr.shoulder.1, + skeleton_attr.shoulder.2, + ); + next.l_shoulder.ori = Quaternion::rotation_x(0.0); + next.l_shoulder.scale = Vec3::one() * 1.1; - next.r_shoulder.offset = Vec3::new( - skeleton_attr.shoulder.0, - skeleton_attr.shoulder.1, - skeleton_attr.shoulder.2, - ); - next.r_shoulder.ori = Quaternion::rotation_x(0.0); - next.r_shoulder.scale = Vec3::one() * 1.1; + next.r_shoulder.offset = Vec3::new( + skeleton_attr.shoulder.0, + skeleton_attr.shoulder.1, + skeleton_attr.shoulder.2, + ); + next.r_shoulder.ori = Quaternion::rotation_x(0.0); + next.r_shoulder.scale = Vec3::one() * 1.1; - next.glider.offset = Vec3::new(0.0, 0.0, 10.0); - next.glider.scale = Vec3::one() * 0.0; + next.glider.offset = Vec3::new(0.0, 0.0, 10.0); + next.glider.scale = Vec3::one() * 0.0; - next.main.offset = Vec3::new(-7.0, -5.0, 18.0); - next.main.ori = Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57); - next.main.scale = Vec3::one(); + next.main.offset = Vec3::new(-7.0, -5.0, 18.0); + next.main.ori = Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57); + next.main.scale = Vec3::one(); - next.second.offset = Vec3::new(0.0, 0.0, 0.0); - next.second.ori = Quaternion::rotation_y(0.0); - next.second.scale = Vec3::one() * 0.0; + next.second.offset = Vec3::new(0.0, 0.0, 0.0); + next.second.ori = Quaternion::rotation_y(0.0); + next.second.scale = Vec3::one() * 0.0; - next.lantern.offset = Vec3::new( - skeleton_attr.lantern.0, - skeleton_attr.lantern.1, - skeleton_attr.lantern.2, - ); - next.lantern.ori = Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0); - next.lantern.scale = Vec3::one() * 0.65; + next.lantern.offset = Vec3::new( + skeleton_attr.lantern.0, + skeleton_attr.lantern.1, + skeleton_attr.lantern.2, + ); + next.lantern.ori = Quaternion::rotation_x(0.0); + next.lantern.scale = Vec3::one() * 0.65; - next.torso.offset = Vec3::new(0.0, -0.2, 0.4) * skeleton_attr.scaler; - next.torso.ori = Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0); - next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; - - next.control.scale = Vec3::one(); - - next.l_control.scale = Vec3::one(); - - next.r_control.scale = Vec3::one(); - } else { - next.head.offset = - Vec3::new(0.0, -1.0 + skeleton_attr.head.0, skeleton_attr.head.1); - next.head.ori = Quaternion::rotation_x(-0.25) * Quaternion::rotation_z(0.0); - next.head.scale = Vec3::one() * skeleton_attr.head_scale; - - next.chest.offset = Vec3::new( - 0.0, - -2.0 + skeleton_attr.chest.0 + 3.0, - skeleton_attr.chest.1, - ); - next.chest.ori = Quaternion::rotation_z(0.0) - * Quaternion::rotation_x(0.2 + drop * 0.05) - * Quaternion::rotation_z(0.0); - next.chest.scale = Vec3::one(); - - next.belt.offset = Vec3::new(0.0, skeleton_attr.belt.0 + 0.5, skeleton_attr.belt.1); - next.belt.ori = - Quaternion::rotation_z(0.0) * Quaternion::rotation_x(0.1 + dropa * 0.1); - next.belt.scale = Vec3::one(); - - next.back.offset = Vec3::new(0.0, skeleton_attr.back.0, skeleton_attr.back.1); - next.back.ori = Quaternion::rotation_x(-0.15); - next.back.scale = Vec3::one() * 1.02; - - next.shorts.offset = - Vec3::new(0.0, skeleton_attr.shorts.0 + 1.0, skeleton_attr.shorts.1); - next.shorts.ori = Quaternion::rotation_z(0.0) - * Quaternion::rotation_x(0.1 + dropa * 0.12) - * Quaternion::rotation_y(0.0); - next.shorts.scale = Vec3::one(); - - next.l_hand.offset = Vec3::new( - -skeleton_attr.hand.0, - 7.5 + skeleton_attr.hand.1, - 7.0 + skeleton_attr.hand.2 + dropa * -1.0, - ); - next.l_hand.ori = - Quaternion::rotation_x(2.2) * Quaternion::rotation_y(0.3 + dropa * 0.1); - next.l_hand.scale = Vec3::one(); - - next.r_hand.offset = Vec3::new( - skeleton_attr.hand.0, - 7.5 + skeleton_attr.hand.1, - 5.0 + skeleton_attr.hand.2 + drop * -1.0, - ); - next.r_hand.ori = - Quaternion::rotation_x(2.2) * Quaternion::rotation_y(-0.3 + drop * 0.1); - next.r_hand.scale = Vec3::one(); - - next.l_foot.offset = Vec3::new( - -skeleton_attr.foot.0, - 4.0 + skeleton_attr.foot.1, - 1.0 + skeleton_attr.foot.2 + drop * -2.0, - ); - next.l_foot.ori = Quaternion::rotation_x(0.55 + drop * 0.1); - next.l_foot.scale = Vec3::one(); - - next.r_foot.offset = Vec3::new( - skeleton_attr.foot.0, - 2.0 + skeleton_attr.foot.1, - -2.0 + skeleton_attr.foot.2 + smooth * 1.0, - ); - next.r_foot.ori = Quaternion::rotation_x(0.2 + smooth * 0.15); - next.r_foot.scale = Vec3::one(); - - next.l_shoulder.offset = Vec3::new( - -skeleton_attr.shoulder.0, - skeleton_attr.shoulder.1, - skeleton_attr.shoulder.2, - ); - next.l_shoulder.ori = Quaternion::rotation_x(0.0); - next.l_shoulder.scale = Vec3::one() * 1.1; - - next.r_shoulder.offset = Vec3::new( - skeleton_attr.shoulder.0, - skeleton_attr.shoulder.1, - skeleton_attr.shoulder.2, - ); - next.r_shoulder.ori = Quaternion::rotation_x(0.0); - next.r_shoulder.scale = Vec3::one() * 1.1; - - next.glider.offset = Vec3::new(0.0, 0.0, 10.0); - next.glider.scale = Vec3::one() * 0.0; - - next.main.offset = Vec3::new(-7.0, -5.0, 18.0); - next.main.ori = Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57); - next.main.scale = Vec3::one(); - - next.second.offset = Vec3::new(0.0, 0.0, 0.0); - next.second.ori = Quaternion::rotation_y(0.0); - next.second.scale = Vec3::one() * 0.0; - - next.lantern.offset = Vec3::new( - skeleton_attr.lantern.0, - skeleton_attr.lantern.1, - skeleton_attr.lantern.2, - ); - next.lantern.ori = Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0); - next.lantern.scale = Vec3::one() * 0.65; - - next.torso.offset = Vec3::new(0.0, -0.2, 0.4) * skeleton_attr.scaler; - next.torso.ori = Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0); - next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; - - next.control.scale = Vec3::one(); - - next.l_control.scale = Vec3::one(); - } + next.torso.offset = Vec3::new(0.0, -0.2, 0.4) * skeleton_attr.scaler; + next.torso.ori = Quaternion::rotation_x(0.0); + next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; }; + next.control.scale = Vec3::one(); next.r_control.scale = Vec3::one(); + next.l_control.scale = Vec3::one(); next.second.scale = match ( active_tool_kind.map(|tk| tk.hands()), diff --git a/voxygen/src/anim/src/character/sneak.rs b/voxygen/src/anim/src/character/sneak.rs index 281607f259..52563090a1 100644 --- a/voxygen/src/anim/src/character/sneak.rs +++ b/voxygen/src/anim/src/character/sneak.rs @@ -13,7 +13,6 @@ impl Animation for SneakAnimation { const UPDATE_FN: &'static [u8] = b"character_sneak\0"; #[cfg_attr(feature = "be-dyn-lib", export_name = "character_sneak")] - #[allow(clippy::identity_conversion)] // TODO: Pending review in #587 fn update_skeleton_inner( skeleton: &Self::Skeleton, @@ -75,10 +74,10 @@ impl Animation for SneakAnimation { * 0.1, ); - let ori = Vec2::from(orientation); + let ori: Vec2 = Vec2::from(orientation); let last_ori = Vec2::from(last_ori); let tilt = if Vec2::new(ori, last_ori) - .map(|o| Vec2::::from(o).magnitude_squared()) + .map(|o| o.magnitude_squared()) .map(|m| m > 0.001 && m.is_finite()) .reduce_and() && ori.angle_between(last_ori).is_finite() diff --git a/voxygen/src/anim/src/character/swim.rs b/voxygen/src/anim/src/character/swim.rs index 939eda7fd4..b0c2c33d32 100644 --- a/voxygen/src/anim/src/character/swim.rs +++ b/voxygen/src/anim/src/character/swim.rs @@ -33,9 +33,10 @@ impl Animation for SwimAnimation { ) -> Self::Skeleton { let mut next = (*skeleton).clone(); let avgspeed = Vec2::::from(avg_vel).magnitude(); - let avgtotal = Vec3::::from(avg_vel).magnitude(); - let speed = Vec3::::from(velocity).magnitude(); + let avgtotal = avg_vel.magnitude(); + + let speed = velocity.magnitude(); *rate = 1.0; let tempo = if speed > 0.5 { 1.5 } else { 0.7 }; let intensity = if speed > 0.5 { 1.0 } else { 0.3 }; @@ -96,12 +97,12 @@ impl Animation for SwimAnimation { skeleton_attr.head.1 - 1.0 + short * 0.3, ); next.head.ori = - Quaternion::rotation_z(head_look.x * 0.5 + short * -0.2 * intensity + tilt * 3.0) + Quaternion::rotation_z(head_look.x * 0.3 + short * -0.2 * intensity + tilt * 3.0) * Quaternion::rotation_x( (0.4 * head_look.y * (1.0 / intensity)).abs() + 0.45 * intensity + velocity.z * 0.03 - - (abstilt * 1.8), + - (abstilt * 1.8).min(0.0), ); next.head.scale = Vec3::one() * skeleton_attr.head_scale; @@ -230,11 +231,12 @@ impl Animation for SwimAnimation { } else { avgtotal }; - next.torso.offset = Vec3::new(0.0, 0.0, 1.0) * skeleton_attr.scaler; + next.torso.offset = Vec3::new(0.0, 0.0, 1.0 - avgspeed * 0.05) * skeleton_attr.scaler; next.torso.ori = Quaternion::rotation_x( (((1.0 / switch) * PI / 2.0 + avg_vel.z * 0.12).min(1.57) - PI / 2.0) + avgspeed * avg_vel.z * -0.003, - ) * Quaternion::rotation_z(tilt * 8.0); + ) * Quaternion::rotation_y(tilt * 8.0) + * Quaternion::rotation_z(tilt * 8.0); next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler; next.control.scale = Vec3::one(); //avgspeed*-0.14*reverse +