Factored out common lantern animation

This commit is contained in:
Joshua Barretto 2023-10-14 15:46:20 +01:00
parent 30ecc997ea
commit 748cde14be
10 changed files with 57 additions and 170 deletions

View File

@ -3,7 +3,6 @@ use super::{
CharacterSkeleton, SkeletonAttr,
};
use common::comp::item::{Hands, ToolKind};
use core::f32::consts::PI;
use std::ops::Mul;
pub struct IdleAnimation;
@ -41,7 +40,6 @@ impl Animation for IdleAnimation {
next.hand_r.scale = Vec3::one() * 1.04;
next.back.scale = Vec3::one() * 1.02;
next.hold.scale = Vec3::one() * 0.0;
next.lantern.scale = Vec3::one() * 0.65;
next.shoulder_l.scale = Vec3::one() * 1.1;
next.shoulder_r.scale = Vec3::one() * 1.1;
@ -89,8 +87,7 @@ impl Animation for IdleAnimation {
next.do_tools_on_back(hands, active_tool_kind, second_tool_kind);
next.lantern.position = Vec3::new(s_a.lantern.0, s_a.lantern.1, s_a.lantern.2);
next.lantern.orientation = Quaternion::rotation_x(0.1) * Quaternion::rotation_y(0.1);
next.do_hold_lantern(s_a, anim_time, anim_time, 0.0, 0.0, 0.0);
next.torso.position = Vec3::new(0.0, 0.0, 0.0);

View File

@ -137,21 +137,7 @@ impl Animation for JumpAnimation {
next.do_tools_on_back(hands, active_tool_kind, second_tool_kind);
next.lantern.position = Vec3::new(s_a.lantern.0, s_a.lantern.1, s_a.lantern.2);
next.lantern.orientation = Quaternion::rotation_x(1.0 * switch + slow * 0.3 * switch)
* Quaternion::rotation_y(0.6 * switch + slow * 0.3 * switch);
next.lantern.scale = Vec3::one() * 0.65;
next.hold.scale = Vec3::one() * 0.0;
if skeleton.holding_lantern {
next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1 + 5.0, s_a.hand.2 + 9.0);
next.hand_r.orientation = Quaternion::rotation_x(2.25) * Quaternion::rotation_z(0.9);
next.lantern.position = Vec3::new(-0.5, -0.5, -2.5);
next.lantern.orientation = next.hand_r.orientation.inverse()
* Quaternion::rotation_x(slow * 0.5)
* Quaternion::rotation_y(tilt * 4.0 * slow + tilt * 3.0);
}
next.do_hold_lantern(s_a, anim_time, anim_time, speednorm, 0.0, tilt);
next.torso.position = Vec3::new(0.0, 0.0, 0.0);
next.torso.orientation = Quaternion::rotation_x(0.0);

View File

@ -338,6 +338,8 @@ impl<'a> From<&'a Body> for SkeletonAttr {
}
impl CharacterSkeleton {
/// Animate tools (main and secondary) on the character's back, taking in
/// account backpack offsets.
pub fn do_tools_on_back(
&mut self,
hands: (Option<Hands>, Option<Hands>),
@ -408,4 +410,50 @@ impl CharacterSkeleton {
(_, _) => {},
}
}
/// If we're holding a lantern, animate hold the lantern in a reasonable
/// position.
pub fn do_hold_lantern(
&mut self,
s_a: &SkeletonAttr,
anim_time: f32,
acc_vel: f32,
speednorm: f32,
impact: f32,
tilt: f32,
) {
let lab = 2.0 / s_a.scaler;
let short = ((5.0 / (1.5 + 3.5 * ((acc_vel * lab * 1.6 + PI * 0.5).sin()).powi(2))).sqrt())
* ((acc_vel * lab * 1.6 + PI * 0.5).sin());
let shorte = ((1.0 / (0.8 + 0.2 * ((acc_vel * lab * 1.6).sin()).powi(2))).sqrt())
* ((acc_vel * lab * 1.6).sin());
self.lantern.position = Vec3::new(s_a.lantern.0, s_a.lantern.1, s_a.lantern.2);
self.lantern.orientation =
Quaternion::rotation_x(shorte * 0.7 + 0.4) * Quaternion::rotation_y(shorte * 0.4);
self.lantern.scale = Vec3::one() * 0.65;
self.hold.scale = Vec3::one() * 0.0;
if self.holding_lantern {
self.hand_r.position = Vec3::new(
s_a.hand.0 + 1.0,
s_a.hand.1 + 2.0 - impact * 0.2,
s_a.hand.2 + 12.0 + impact * -0.1,
);
self.hand_r.orientation = Quaternion::rotation_x(2.25) * Quaternion::rotation_z(0.9);
self.shoulder_r.orientation = Quaternion::rotation_x(short * -0.15 + 2.0);
let fast = (anim_time * 8.0).sin();
let fast2 = (anim_time * 6.0 + 8.0).sin();
self.lantern.position = Vec3::new(-0.5, -0.5, -2.5);
self.lantern.orientation = self.hand_r.orientation.inverse()
* Quaternion::rotation_x(
(fast + 0.5) * 1.0 * speednorm + (tilt.abs() * 2.0).min(PI * 0.5),
)
* Quaternion::rotation_y(tilt * 1.0 * fast + tilt * 1.0 + fast2 * speednorm * 0.25);
}
}
}

View File

@ -130,27 +130,7 @@ impl Animation for MountAnimation {
next.shoulder_r.position = Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
next.shoulder_r.orientation = Quaternion::rotation_x(0.0);
if skeleton.holding_lantern {
next.hand_r.position = Vec3::new(
s_a.hand.0 + 1.0 - head_look.x * 8.0,
s_a.hand.1 + 5.0 + head_look.x * 6.0,
s_a.hand.2 + 9.0 + head_look.y * 6.0,
);
next.hand_r.orientation = Quaternion::rotation_x(2.25)
* Quaternion::rotation_z(0.9)
* Quaternion::rotation_y(head_look.x * 3.0)
* Quaternion::rotation_x(head_look.y * 3.0);
let fast = (anim_time * 5.0).sin();
let fast2 = (anim_time * 4.5 + 8.0).sin();
next.lantern.position = Vec3::new(-0.5, -0.5, -2.5);
next.lantern.orientation = next.hand_r.orientation.inverse()
* Quaternion::rotation_x(fast * 0.1)
* Quaternion::rotation_y(fast2 * 0.1);
} else {
next.lantern.position = Vec3::new(s_a.lantern.0, s_a.lantern.1, s_a.lantern.2);
};
next.do_hold_lantern(s_a, anim_time, 0.0, speed * 0.1 + 0.1, 0.0, tilt);
next.glider.position = Vec3::new(0.0, 0.0, 10.0);
next.glider.scale = Vec3::one() * 0.0;

View File

@ -67,9 +67,6 @@ impl Animation for RunAnimation {
let noisea = (acc_vel * 11.0 + PI / 6.0).sin();
let noiseb = (acc_vel * 19.0 + PI / 4.0).sin();
let shorte = ((1.0 / (0.8 + 0.2 * ((acc_vel * lab * 1.6).sin()).powi(2))).sqrt())
* ((acc_vel * lab * 1.6).sin());
let back_speed = 2.6;
let dirside = orientation.xy().dot(velocity.xy()).signum();
@ -232,29 +229,7 @@ impl Animation for RunAnimation {
next.do_tools_on_back(hands, active_tool_kind, second_tool_kind);
next.lantern.position = Vec3::new(s_a.lantern.0, s_a.lantern.1, s_a.lantern.2);
next.lantern.orientation =
Quaternion::rotation_x(shorte * 0.7 + 0.4) * Quaternion::rotation_y(shorte * 0.4);
next.lantern.scale = Vec3::one() * 0.65;
next.hold.scale = Vec3::one() * 0.0;
if skeleton.holding_lantern {
next.hand_r.position = Vec3::new(
s_a.hand.0 + 1.0,
s_a.hand.1 + 2.0 - impact * 0.2,
s_a.hand.2 + 12.0 + impact * -0.1,
);
next.hand_r.orientation = Quaternion::rotation_x(2.25) * Quaternion::rotation_z(0.9);
next.shoulder_r.orientation = Quaternion::rotation_x(short * -0.15 + 2.0);
let fast = (anim_time * 8.0).sin();
let fast2 = (anim_time * 6.0 + 8.0).sin();
next.lantern.position = Vec3::new(-0.5, -0.5, -2.5);
next.lantern.orientation = next.hand_r.orientation.inverse()
* Quaternion::rotation_x((fast + 0.5) * 1.0 * speednorm)
* Quaternion::rotation_y(tilt * 4.0 * fast + tilt * 3.0 + fast2 * speednorm * 0.25);
}
next.do_hold_lantern(s_a, anim_time, acc_vel, speednorm, impact, tilt);
next.torso.position = Vec3::new(0.0, 0.0, 0.0);

View File

@ -89,25 +89,7 @@ impl Animation for SitAnimation {
next.torso.position = Vec3::new(0.0, -2.2, stop * -1.76);
if skeleton.holding_lantern {
next.hand_r.position = Vec3::new(
s_a.hand.0 + 1.0 - head_look.x * 8.0,
s_a.hand.1 + 5.0 + head_look.x * 6.0,
s_a.hand.2 + 9.0 + head_look.y * 6.0,
);
next.hand_r.orientation = Quaternion::rotation_x(2.25)
* Quaternion::rotation_z(0.9)
* Quaternion::rotation_y(head_look.x * 3.0)
* Quaternion::rotation_x(head_look.y * 3.0);
let fast = (anim_time * 5.0).sin();
let fast2 = (anim_time * 4.5 + 8.0).sin();
next.lantern.position = Vec3::new(-0.5, -0.5, -2.5);
next.lantern.orientation = next.hand_r.orientation.inverse()
* Quaternion::rotation_x(fast * 0.1)
* Quaternion::rotation_y(fast2 * 0.1);
}
next.do_hold_lantern(s_a, anim_time, 0.0, 0.0, 0.0, 0.0);
next
}

View File

@ -159,13 +159,7 @@ impl Animation for SneakAnimation {
next.foot_r.position = Vec3::new(s_a.foot.0, 4.0 + s_a.foot.1, s_a.foot.2);
}
if skeleton.holding_lantern {
next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1 + 5.0, s_a.hand.2 + 9.0);
next.hand_r.orientation = Quaternion::rotation_x(2.5);
next.lantern.position = Vec3::new(0.0, 1.5, -5.5);
next.lantern.orientation = next.hand_r.orientation.inverse();
}
next.do_hold_lantern(s_a, anim_time, anim_time, speed / 10.0, 0.0, tilt);
next
}

View File

@ -66,9 +66,6 @@ impl Animation for SneakWieldAnimation {
let noisea = (anim_time * 11.0 + PI / 6.0).sin();
let noiseb = (anim_time * 19.0 + PI / 4.0).sin();
let shorte = ((5.0 / (4.0 + 1.0 * ((anim_time * lab * 7.0).sin()).powi(2))).sqrt())
* ((anim_time * lab * 7.0).sin());
let shortalt = (anim_time * lab * 7.0 + PI / 2.0).sin();
let head_look = Vec2::new(
@ -145,9 +142,6 @@ impl Animation for SneakWieldAnimation {
next.shoulder_l.orientation = Quaternion::rotation_x(short * 0.15 * walkintensity);
next.shoulder_r.orientation = Quaternion::rotation_x(short * -0.15 * walkintensity);
next.lantern.orientation =
Quaternion::rotation_x(shorte * 0.2 + 0.4) * Quaternion::rotation_y(shorte * 0.1);
} else {
next.head.position = Vec3::new(
0.0,
@ -178,14 +172,6 @@ impl Animation for SneakWieldAnimation {
next.foot_r.position = Vec3::new(s_a.foot.0, 4.0 + s_a.foot.1, s_a.foot.2);
}
if skeleton.holding_lantern {
next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1 + 5.0, s_a.hand.2 + 9.0);
next.hand_r.orientation = Quaternion::rotation_x(2.5);
next.lantern.position = Vec3::new(0.0, 1.5, -5.5);
next.lantern.orientation = next.hand_r.orientation.inverse();
}
match (hands, active_tool_kind, second_tool_kind) {
((Some(Hands::Two), _), tool, _) | ((None, Some(Hands::Two)), _, tool) => match tool {
Some(ToolKind::Sword) => {
@ -374,27 +360,8 @@ impl Animation for SneakWieldAnimation {
next.second = next.main;
}
if skeleton.holding_lantern {
next.hand_r.position = Vec3::new(
s_a.hand.0 - head_look.x * 6.0,
s_a.hand.1 + 5.0 - head_look.y * 10.0 + slow * 0.15,
s_a.hand.2 + 12.0 + head_look.y * 6.0 + slow * 0.5,
);
next.hand_r.orientation = Quaternion::rotation_x(2.25 + slow * -0.06)
* Quaternion::rotation_z(0.9)
* Quaternion::rotation_y(head_look.x * 1.5)
* Quaternion::rotation_x(head_look.y * 1.5);
next.do_hold_lantern(s_a, anim_time, anim_time, speednorm, 0.0, tilt);
let fast = (anim_time * 8.0).sin();
let fast2 = (anim_time * 6.0 + 8.0).sin();
next.lantern.position = Vec3::new(-0.5, -0.5, -2.5);
next.lantern.orientation = next.hand_r.orientation.inverse()
* Quaternion::rotation_x((fast + 0.5) * 1.0 * speednorm + fast * 0.1)
* Quaternion::rotation_y(
tilt * 1.0 * fast + tilt * 1.0 + fast2 * speednorm * 0.25 + fast2 * 0.1,
);
}
next
}
}

View File

@ -110,29 +110,7 @@ impl Animation for StandAnimation {
next.do_tools_on_back(hands, active_tool_kind, second_tool_kind);
next.lantern.position = Vec3::new(s_a.lantern.0, s_a.lantern.1, s_a.lantern.2);
next.lantern.orientation = Quaternion::rotation_x(0.1) * Quaternion::rotation_y(0.1);
if skeleton.holding_lantern {
next.hand_r.position = Vec3::new(
s_a.hand.0 - head_look.x * 10.0,
s_a.hand.1 + 5.0 - head_look.y * 8.0 + slow * 0.15 - impact * 0.2,
s_a.hand.2 + 12.0 + slow * 0.5 + impact * -0.1,
);
next.hand_r.orientation = Quaternion::rotation_x(2.5 + slow * -0.06 + impact * -0.1)
* Quaternion::rotation_z(0.9)
* Quaternion::rotation_y(head_look.x * 1.5)
* Quaternion::rotation_x(head_look.y * 1.5);
next.shoulder_r.orientation = Quaternion::rotation_x(slow * 0.15 + 2.0);
let fast = (anim_time * 5.0).sin();
let fast2 = (anim_time * 4.5 + 8.0).sin();
next.lantern.position = Vec3::new(-0.5, -0.5, -2.5);
next.lantern.orientation = next.hand_r.orientation.inverse()
* Quaternion::rotation_x(fast * 0.1)
* Quaternion::rotation_y(fast2 * 0.1 + tilt * 3.0);
}
next.do_hold_lantern(s_a, anim_time, 0.0, 0.0, impact, tilt);
next.torso.position = Vec3::new(0.0, 0.0, 0.0);
next.second.scale = Vec3::one();

View File

@ -551,27 +551,7 @@ impl Animation for WieldAnimation {
next.second = next.main;
}
if skeleton.holding_lantern {
next.hand_r.position = Vec3::new(
s_a.hand.0 - head_look.x * 6.0,
s_a.hand.1 + 5.0 - head_look.y * 10.0 + slow * 0.15,
s_a.hand.2 + 12.0 + head_look.y * 6.0 + slow * 0.5,
);
next.hand_r.orientation = Quaternion::rotation_x(2.25 + slow * -0.06)
* Quaternion::rotation_z(0.9)
* Quaternion::rotation_y(head_look.x * 1.5)
* Quaternion::rotation_x(head_look.y * 1.5);
let fast = (anim_time * 8.0).sin();
let fast2 = (anim_time * 6.0 + 8.0).sin();
next.lantern.position = Vec3::new(-0.5, -0.5, -2.5);
next.lantern.orientation = next.hand_r.orientation.inverse()
* Quaternion::rotation_x((fast + 0.5) * 1.0 * speednorm + fast * 0.1)
* Quaternion::rotation_y(
tilt * 1.0 * fast + tilt * 1.0 + fast2 * speednorm * 0.25 + fast2 * 0.1,
);
}
next.do_hold_lantern(s_a, anim_time, anim_time, speednorm, 0.0, tilt);
next
}