look-based anims

This commit is contained in:
jshipsey 2021-02-27 16:19:33 -05:00
parent 5589a7b714
commit b4627dfe19
4 changed files with 60 additions and 42 deletions

View File

@ -34,7 +34,7 @@ impl Animation for ShootAnimation {
velocity, velocity,
orientation, orientation,
last_ori, last_ori,
_look_dir, look_dir,
_global_time, _global_time,
stage_section, stage_section,
): Self::Dependency, ): Self::Dependency,
@ -65,7 +65,7 @@ impl Animation for ShootAnimation {
Some(ToolKind::Staff) | Some(ToolKind::Sceptre) => { Some(ToolKind::Staff) | Some(ToolKind::Sceptre) => {
let (move1, move2, move3) = match stage_section { let (move1, move2, move3) = match stage_section {
Some(StageSection::Buildup) => (anim_time as f32, 0.0, 0.0), Some(StageSection::Buildup) => (anim_time as f32, 0.0, 0.0),
Some(StageSection::Swing) => (1.0, (anim_time as f32).powf(0.25), 0.0), Some(StageSection::Shoot) => (1.0, (anim_time as f32).powf(0.25), 0.0),
Some(StageSection::Recover) => (1.0, 1.0, anim_time as f32), Some(StageSection::Recover) => (1.0, 1.0, anim_time as f32),
_ => (0.0, 0.0, 0.0), _ => (0.0, 0.0, 0.0),
}; };
@ -84,10 +84,10 @@ impl Animation for ShootAnimation {
next.control.position = Vec3::new( next.control.position = Vec3::new(
s_a.stc.0 + (xmove * 3.0 + move1 * -4.0) * (1.0 - move3), s_a.stc.0 + (xmove * 3.0 + move1 * -4.0) * (1.0 - move3),
s_a.stc.1 + (2.0 + ymove * 3.0 + move2 * 3.0) * (1.0 - move3), s_a.stc.1 + (2.0 + ymove * 3.0 + move2 * 3.0) * (1.0 - move3),
s_a.stc.2, s_a.stc.2 + look_dir.z * 4.0,
); );
next.control.orientation = next.control.orientation =
Quaternion::rotation_x(s_a.stc.3 + (move2 * 0.6) * (1.0 - move3)) Quaternion::rotation_x(look_dir.z + s_a.stc.3 + (move2 * 0.6) * (1.0 - move3))
* Quaternion::rotation_y(s_a.stc.4 + (move1 * 0.5 + move2 * -0.5)) * Quaternion::rotation_y(s_a.stc.4 + (move1 * 0.5 + move2 * -0.5))
* Quaternion::rotation_z( * Quaternion::rotation_z(
s_a.stc.5 - (0.2 + move1 * -0.5 + move2 * 0.8) * (1.0 - move3), s_a.stc.5 - (0.2 + move1 * -0.5 + move2 * 0.8) * (1.0 - move3),
@ -95,9 +95,10 @@ impl Animation for ShootAnimation {
next.chest.orientation = next.chest.orientation =
Quaternion::rotation_z((move1 * 0.3 + move2 * 0.2) * (1.0 - move3)); Quaternion::rotation_z((move1 * 0.3 + move2 * 0.2) * (1.0 - move3));
next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1); next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
next.head.orientation = Quaternion::rotation_z( next.head.orientation = Quaternion::rotation_x(look_dir.z * 0.7)
tilt * -2.5 + (move1 * -0.2 + move2 * -0.4) * (1.0 - move3), * Quaternion::rotation_z(
); tilt * -2.5 + (move1 * -0.2 + move2 * -0.4) * (1.0 - move3),
);
if speed < 0.5 { if speed < 0.5 {
next.belt.orientation = next.belt.orientation =
@ -118,18 +119,19 @@ impl Animation for ShootAnimation {
Some(ToolKind::Bow) => { Some(ToolKind::Bow) => {
let (_move1, move2, _move3) = match stage_section { let (_move1, move2, _move3) = match stage_section {
Some(StageSection::Buildup) => ((anim_time as f32).powf(0.25), 0.0, 0.0), Some(StageSection::Buildup) => ((anim_time as f32).powf(0.25), 0.0, 0.0),
Some(StageSection::Swing) => (1.0, anim_time as f32, 0.0), Some(StageSection::Shoot) => (1.0, anim_time as f32, 0.0),
Some(StageSection::Recover) => (1.0, 1.0, (anim_time as f32).powi(4)), Some(StageSection::Recover) => (1.0, 1.0, (anim_time as f32).powi(4)),
_ => (0.0, 0.0, 0.0), _ => (0.0, 0.0, 0.0),
}; };
next.main.position = Vec3::new(0.0, 0.0, 0.0); next.main.position = Vec3::new(0.0, 0.0, 0.0);
next.main.orientation = Quaternion::rotation_x(0.0); next.main.orientation = Quaternion::rotation_x(0.0);
next.hand_l.position = Vec3::new( next.hand_l.position = Vec3::new(
s_a.bhl.0 + move2 * -2.0, s_a.bhl.0 + move2 * -8.0,
s_a.bhl.1 + move2 * -6.0, s_a.bhl.1 + move2 * -10.0,
s_a.bhl.2 + move2 * -3.0, s_a.bhl.2,
); );
next.hand_l.orientation = Quaternion::rotation_x(s_a.bhl.3); next.hand_l.orientation =
Quaternion::rotation_x(s_a.bhl.3) * Quaternion::rotation_y(move2 * 0.7);
next.hand_r.position = Vec3::new(s_a.bhr.0, s_a.bhr.1, s_a.bhr.2); next.hand_r.position = Vec3::new(s_a.bhr.0, s_a.bhr.1, s_a.bhr.2);
next.hand_r.orientation = Quaternion::rotation_x(s_a.bhr.3); next.hand_r.orientation = Quaternion::rotation_x(s_a.bhr.3);
@ -137,25 +139,25 @@ impl Animation for ShootAnimation {
next.hold.orientation = Quaternion::rotation_x(-1.57); next.hold.orientation = Quaternion::rotation_x(-1.57);
next.hold.scale = Vec3::one() * 1.0 * (1.0 - move2); next.hold.scale = Vec3::one() * 1.0 * (1.0 - move2);
next.control.position = Vec3::new(s_a.bc.0 + 11.0, s_a.bc.1 + 2.0, s_a.bc.2 + 8.0); next.control.position = Vec3::new(
next.control.orientation = Quaternion::rotation_x(0.0 + (move2 as f32 * 0.1).sin()) s_a.bc.0 + 11.0 + move2 * 2.0,
* Quaternion::rotation_y(s_a.bc.4 - 1.25) s_a.bc.1 + 2.0 + (look_dir.z * -5.0).min(-2.0) + move2 * -1.0,
* Quaternion::rotation_z(s_a.bc.5 - 0.2 + (move2 as f32 * -0.2).sin()); s_a.bc.2 + 8.0 + (look_dir.z * 15.0).max(-8.0),
next.chest.orientation = Quaternion::rotation_z(0.8); );
next.control.orientation = Quaternion::rotation_x(look_dir.z + move2 * -0.0)
* Quaternion::rotation_y(-look_dir.z + s_a.bc.4 - 1.25 + move2 * -0.0)
* Quaternion::rotation_z(s_a.bc.5 - 0.2 + move2 * -0.1);
next.chest.orientation = Quaternion::rotation_z(0.8 + move2 * 0.5);
next.head.position = Vec3::new(0.0 - 2.0, s_a.head.0, s_a.head.1); next.head.position = Vec3::new(0.0 - 2.0, s_a.head.0, s_a.head.1);
next.head.orientation = next.head.orientation = Quaternion::rotation_x(look_dir.z * 0.7)
Quaternion::rotation_z(tilt * -2.5 - 0.5 + (move2 as f32 * 0.2).sin()); * Quaternion::rotation_z(tilt * -2.5 - 0.5 + (move2 as f32 * -0.2).sin());
next.chest.orientation = Quaternion::rotation_z(0.8 + move2 * 0.2);
next.belt.orientation = Quaternion::rotation_z(move2 * 0.3);
next.shorts.orientation = Quaternion::rotation_z(move2 * 0.5);
next.shoulder_l.orientation = Quaternion::rotation_x(move2 * 0.5);
if speed < 0.5 { if speed < 0.5 {
next.chest.orientation =
Quaternion::rotation_z(0.8 + (move2 as f32 * 0.1).sin());
next.belt.orientation = Quaternion::rotation_x(0.07)
* Quaternion::rotation_z((move2 as f32 * -0.1).sin());
next.shorts.orientation = Quaternion::rotation_x(0.08)
* Quaternion::rotation_z((move2 as f32 * -0.15).sin());
next.foot_l.position = Vec3::new(-s_a.foot.0, s_a.foot.1 - 5.0, s_a.foot.2); next.foot_l.position = Vec3::new(-s_a.foot.0, s_a.foot.1 - 5.0, s_a.foot.2);
next.foot_l.orientation = Quaternion::rotation_x(-0.5); next.foot_l.orientation = Quaternion::rotation_x(-0.5);

View File

@ -2,13 +2,13 @@ use super::{
super::{vek::*, Animation}, super::{vek::*, Animation},
CharacterSkeleton, SkeletonAttr, CharacterSkeleton, SkeletonAttr,
}; };
use common::comp::item::ToolKind; use common::{comp::item::ToolKind, util::Dir};
use std::f32::consts::PI; use std::f32::consts::PI;
pub struct TalkAnimation; pub struct TalkAnimation;
impl Animation for TalkAnimation { impl Animation for TalkAnimation {
type Dependency = (Option<ToolKind>, Option<ToolKind>, f32, f64); type Dependency = (Option<ToolKind>, Option<ToolKind>, f32, f64, Dir);
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")] #[cfg(feature = "use-dyn-lib")]
@ -18,7 +18,7 @@ impl Animation for TalkAnimation {
#[allow(clippy::approx_constant)] // TODO: Pending review in #587 #[allow(clippy::approx_constant)] // TODO: Pending review in #587
fn update_skeleton_inner( fn update_skeleton_inner(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(_active_tool_kind, _second_tool_kind, _velocity, _global_time): Self::Dependency, (_active_tool_kind, _second_tool_kind, _velocity, _global_time, look_dir): Self::Dependency,
anim_time: f64, anim_time: f64,
rate: &mut f32, rate: &mut f32,
s_a: &SkeletonAttr, s_a: &SkeletonAttr,
@ -30,7 +30,7 @@ impl Animation for TalkAnimation {
let slowb = (anim_time as f32 * 4.0 + PI / 2.0).sin(); let slowb = (anim_time as f32 * 4.0 + PI / 2.0).sin();
let slowc = (anim_time as f32 * 12.0 + PI / 2.0).sin(); let slowc = (anim_time as f32 * 12.0 + PI / 2.0).sin();
next.head.orientation = Quaternion::rotation_x(slowc * 0.035); next.head.orientation = Quaternion::rotation_x(slowc * 0.035 + look_dir.z * 0.7);
next.hand_l.position = Vec3::new( next.hand_l.position = Vec3::new(
-s_a.hand.0 + 0.5 + slowb * 0.5, -s_a.hand.0 + 0.5 + slowb * 0.5,
s_a.hand.1 + 5.0 + slowc * 1.0, s_a.hand.1 + 5.0 + slowc * 1.0,

View File

@ -2,7 +2,7 @@ use super::{
super::{vek::*, Animation}, super::{vek::*, Animation},
CharacterSkeleton, SkeletonAttr, CharacterSkeleton, SkeletonAttr,
}; };
use common::comp::item::ToolKind; use common::{comp::item::ToolKind, util::Dir};
use std::{f32::consts::PI, ops::Mul}; use std::{f32::consts::PI, ops::Mul};
pub struct WieldAnimation; pub struct WieldAnimation;
@ -12,6 +12,7 @@ type WieldAnimationDependency = (
Option<ToolKind>, Option<ToolKind>,
Vec3<f32>, Vec3<f32>,
Vec3<f32>, Vec3<f32>,
Dir,
Vec3<f32>, Vec3<f32>,
f64, f64,
); );
@ -26,7 +27,15 @@ impl Animation for WieldAnimation {
#[allow(clippy::approx_constant)] // TODO: Pending review in #587 #[allow(clippy::approx_constant)] // TODO: Pending review in #587
fn update_skeleton_inner( fn update_skeleton_inner(
skeleton: &Self::Skeleton, skeleton: &Self::Skeleton,
(active_tool_kind, _second_tool_kind, orientation, last_ori, velocity, global_time): Self::Dependency, (
active_tool_kind,
_second_tool_kind,
orientation,
last_ori,
look_dir,
velocity,
global_time,
): Self::Dependency,
anim_time: f64, anim_time: f64,
rate: &mut f32, rate: &mut f32,
s_a: &SkeletonAttr, s_a: &SkeletonAttr,
@ -94,7 +103,9 @@ impl Animation for WieldAnimation {
* Quaternion::rotation_x(((direction * 0.8).min(0.3)) * (1.0 - tilt.abs())); * Quaternion::rotation_x(((direction * 0.8).min(0.3)) * (1.0 - tilt.abs()));
next.head.orientation = next.head.orientation =
Quaternion::rotation_z(tilt * -0.5 + strafe * 0.4 * direction + strafe * -0.7) Quaternion::rotation_z(tilt * -0.5 + strafe * 0.4 * direction + strafe * -0.7)
* Quaternion::rotation_x((0.3 - direction * 0.4) * (1.0 - tilt.abs())); * Quaternion::rotation_x(
(0.3 - direction * 0.4) * (1.0 - tilt.abs()) + look_dir.z * 0.7,
);
next.chest.position = Vec3::new( next.chest.position = Vec3::new(
0.0 + short * strafe, 0.0 + short * strafe,
@ -103,15 +114,13 @@ impl Animation for WieldAnimation {
); );
} else { } else {
next.head.position = Vec3::new(0.0, 0.0 + s_a.head.0, s_a.head.1 + u_slow * 0.1); next.head.position = Vec3::new(0.0, 0.0 + s_a.head.0, s_a.head.1 + u_slow * 0.1);
next.head.orientation = next.head.orientation = Quaternion::rotation_z(head_look.x + tilt * -0.75)
Quaternion::rotation_z(head_look.x) * Quaternion::rotation_x(head_look.y.abs()); * Quaternion::rotation_x(head_look.y.abs() + look_dir.z * 0.7);
next.chest.position = next.chest.position =
Vec3::new(0.0 + slowalt * 0.5, s_a.chest.0, s_a.chest.1 + u_slow * 0.5); Vec3::new(0.0 + slowalt * 0.5, s_a.chest.0, s_a.chest.1 + u_slow * 0.5);
next.belt.orientation = Quaternion::rotation_z(0.15 + beltstatic * tilt * 0.1); next.belt.orientation = Quaternion::rotation_z(0.15 + beltstatic * tilt * 0.1);
next.head.orientation = Quaternion::rotation_z(tilt * -0.75);
next.shorts.orientation = Quaternion::rotation_z(0.3 + beltstatic * tilt * 0.2); next.shorts.orientation = Quaternion::rotation_z(0.3 + beltstatic * tilt * 0.2);
next.torso.orientation = Quaternion::rotation_z(tilt * 0.4); next.torso.orientation = Quaternion::rotation_z(tilt * 0.4);
@ -193,7 +202,7 @@ impl Animation for WieldAnimation {
next.head.position = next.head.position =
Vec3::new(0.0, 0.0 + s_a.head.0, s_a.head.1 + u_slow * 0.1); Vec3::new(0.0, 0.0 + s_a.head.0, s_a.head.1 + u_slow * 0.1);
next.head.orientation = Quaternion::rotation_z(head_look.x) next.head.orientation = Quaternion::rotation_z(head_look.x)
* Quaternion::rotation_x(0.35 + head_look.y.abs()); * Quaternion::rotation_x(0.35 + head_look.y.abs() + look_dir.z * 0.7);
next.chest.orientation = Quaternion::rotation_x(-0.35) next.chest.orientation = Quaternion::rotation_x(-0.35)
* Quaternion::rotation_y(u_slowalt * 0.04) * Quaternion::rotation_y(u_slowalt * 0.04)
* Quaternion::rotation_z(0.15); * Quaternion::rotation_z(0.15);
@ -309,7 +318,7 @@ impl Animation for WieldAnimation {
Some(ToolKind::Farming) => { Some(ToolKind::Farming) => {
if speed < 0.5 { if speed < 0.5 {
next.head.orientation = Quaternion::rotation_z(head_look.x) next.head.orientation = Quaternion::rotation_z(head_look.x)
* Quaternion::rotation_x(-0.2 + head_look.y.abs()); * Quaternion::rotation_x(-0.2 + head_look.y.abs() + look_dir.z * 0.7);
} }
next.hand_l.position = Vec3::new(9.0, 1.0, 1.0); next.hand_l.position = Vec3::new(9.0, 1.0, 1.0);
next.hand_l.orientation = Quaternion::rotation_x(1.57); next.hand_l.orientation = Quaternion::rotation_x(1.57);

View File

@ -1338,7 +1338,13 @@ impl FigureMgr {
}, },
CharacterState::Talk => anim::character::TalkAnimation::update_skeleton( CharacterState::Talk => anim::character::TalkAnimation::update_skeleton(
&target_base, &target_base,
(active_tool_kind, second_tool_kind, vel.0.magnitude(), time), (
active_tool_kind,
second_tool_kind,
vel.0.magnitude(),
time,
look_dir,
),
state.state_time, state.state_time,
&mut state_animation_rate, &mut state_animation_rate,
skeleton_attr, skeleton_attr,
@ -1361,6 +1367,7 @@ impl FigureMgr {
// TODO: Update to use the quaternion. // TODO: Update to use the quaternion.
ori * anim::vek::Vec3::<f32>::unit_y(), ori * anim::vek::Vec3::<f32>::unit_y(),
state.last_ori * anim::vek::Vec3::<f32>::unit_y(), state.last_ori * anim::vek::Vec3::<f32>::unit_y(),
look_dir,
vel.0, vel.0,
time, time,
), ),