mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Adds accumulated velocity for animation
This commit is contained in:
parent
526d3bd035
commit
2e8ac0688c
@ -6,7 +6,7 @@ use std::f32::consts::PI;
|
||||
|
||||
pub struct SwimAnimation;
|
||||
|
||||
type SwimAnimationDependency = (Vec3<f32>, Vec3<f32>, Vec3<f32>, f64, Vec3<f32>);
|
||||
type SwimAnimationDependency = (Vec3<f32>, Vec3<f32>, Vec3<f32>, f64, Vec3<f32>, f32);
|
||||
|
||||
impl Animation for SwimAnimation {
|
||||
type Dependency = SwimAnimationDependency;
|
||||
@ -19,16 +19,16 @@ impl Animation for SwimAnimation {
|
||||
|
||||
fn update_skeleton_inner(
|
||||
skeleton: &Self::Skeleton,
|
||||
(velocity, orientation, last_ori, _global_time, avg_vel): Self::Dependency,
|
||||
(velocity, orientation, last_ori, _global_time, avg_vel, acc_vel): Self::Dependency,
|
||||
anim_time: f64,
|
||||
_rate: &mut f32,
|
||||
s_a: &SkeletonAttr,
|
||||
) -> Self::Skeleton {
|
||||
let mut next = (*skeleton).clone();
|
||||
|
||||
let slowalt = (anim_time as f32 * 3.5 + PI + 0.2).sin();
|
||||
let fast = (anim_time as f32 * 5.5 + PI).sin();
|
||||
let fastalt = (anim_time as f32 * 5.5 + PI + 0.2).sin();
|
||||
let slowalt = (anim_time as f32 * 2.5 + PI + 0.2).sin();
|
||||
let fast = (acc_vel * 4.0 + PI).sin();
|
||||
let fastalt = (acc_vel * 4.0 + PI + 0.2).sin();
|
||||
|
||||
let ori: Vec2<f32> = Vec2::from(orientation);
|
||||
let last_ori = Vec2::from(last_ori);
|
||||
@ -46,6 +46,8 @@ impl Animation for SwimAnimation {
|
||||
let abstilt = tilt.abs();
|
||||
let x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude());
|
||||
|
||||
println!("{}", acc_vel);
|
||||
|
||||
next.chest_front.scale = Vec3::one() / 11.0;
|
||||
|
||||
next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
|
||||
@ -56,19 +58,24 @@ impl Animation for SwimAnimation {
|
||||
|
||||
next.chest_front.position = Vec3::new(0.0, s_a.chest_front.0, s_a.chest_front.1) / 11.0;
|
||||
next.chest_front.orientation =
|
||||
Quaternion::rotation_x(velocity.z.abs() * -0.005 + abstilt * 1.0 + x_tilt);
|
||||
Quaternion::rotation_x(velocity.z.abs() * -0.005 + abstilt * 1.0 + x_tilt)
|
||||
* Quaternion::rotation_z(fast * velocity.magnitude() * -0.02);
|
||||
|
||||
next.chest_back.position = Vec3::new(0.0, s_a.chest_back.0, s_a.chest_back.1);
|
||||
next.chest_back.orientation = Quaternion::rotation_z(fastalt * 0.3 + tilt * 2.0);
|
||||
next.chest_back.orientation =
|
||||
Quaternion::rotation_z(fastalt * velocity.magnitude() * 0.1 + tilt * 2.0);
|
||||
|
||||
next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
|
||||
next.tail.orientation = Quaternion::rotation_z(fast * 0.3 + tilt * 2.0);
|
||||
next.tail.orientation =
|
||||
Quaternion::rotation_z(fast * velocity.magnitude() * 0.1 + tilt * 2.0);
|
||||
|
||||
next.fin_l.position = Vec3::new(-s_a.fin.0, s_a.fin.1, s_a.fin.2);
|
||||
next.fin_l.orientation = Quaternion::rotation_z(fast * 0.3 - 0.1 + tilt * -0.5);
|
||||
next.fin_l.orientation =
|
||||
Quaternion::rotation_z(fast * velocity.magnitude() * 0.1 - 0.1 + tilt * -0.5);
|
||||
|
||||
next.fin_r.position = Vec3::new(s_a.fin.0, s_a.fin.1, s_a.fin.2);
|
||||
next.fin_r.orientation = Quaternion::rotation_z(-fast * 0.3 + 0.1 + tilt * -0.5);
|
||||
next.fin_r.orientation =
|
||||
Quaternion::rotation_z(fast * velocity.magnitude() * -0.1 + 0.1 + tilt * -0.5);
|
||||
next
|
||||
}
|
||||
}
|
@ -21,9 +21,9 @@ impl Animation for IdleAnimation {
|
||||
) -> Self::Skeleton {
|
||||
let mut next = (*skeleton).clone();
|
||||
|
||||
next.chest.scale = Vec3::one() / 11.0;
|
||||
next.chest.scale = Vec3::one() / 13.0;
|
||||
|
||||
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 11.0;
|
||||
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 13.0;
|
||||
next.chest.orientation = Quaternion::rotation_x(0.0);
|
||||
|
||||
next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
|
||||
|
@ -21,9 +21,9 @@ impl Animation for JumpAnimation {
|
||||
) -> Self::Skeleton {
|
||||
let mut next = (*skeleton).clone();
|
||||
|
||||
next.chest.scale = Vec3::one() / 11.0;
|
||||
next.chest.scale = Vec3::one() / 13.0;
|
||||
|
||||
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 11.0;
|
||||
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 13.0;
|
||||
next.chest.orientation = Quaternion::rotation_x(0.0);
|
||||
|
||||
next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
|
||||
|
@ -21,9 +21,9 @@ impl Animation for RunAnimation {
|
||||
) -> Self::Skeleton {
|
||||
let mut next = (*skeleton).clone();
|
||||
|
||||
next.chest.scale = Vec3::one() / 11.0;
|
||||
next.chest.scale = Vec3::one() / 13.0;
|
||||
|
||||
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 11.0;
|
||||
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 13.0;
|
||||
next.chest.orientation = Quaternion::rotation_x(0.0);
|
||||
|
||||
next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
|
||||
|
@ -6,7 +6,7 @@ use std::f32::consts::PI;
|
||||
|
||||
pub struct SwimAnimation;
|
||||
|
||||
type SwimAnimationDependency = (Vec3<f32>, Vec3<f32>, Vec3<f32>, f64, Vec3<f32>);
|
||||
type SwimAnimationDependency = (Vec3<f32>, Vec3<f32>, Vec3<f32>, f64, Vec3<f32>, f32);
|
||||
|
||||
impl Animation for SwimAnimation {
|
||||
type Dependency = SwimAnimationDependency;
|
||||
@ -19,14 +19,14 @@ impl Animation for SwimAnimation {
|
||||
|
||||
fn update_skeleton_inner(
|
||||
skeleton: &Self::Skeleton,
|
||||
(velocity, orientation, last_ori, _global_time, avg_vel): Self::Dependency,
|
||||
anim_time: f64,
|
||||
(velocity, orientation, last_ori, _global_time, avg_vel, acc_vel): Self::Dependency,
|
||||
_anim_time: f64,
|
||||
_rate: &mut f32,
|
||||
s_a: &SkeletonAttr,
|
||||
) -> Self::Skeleton {
|
||||
let mut next = (*skeleton).clone();
|
||||
|
||||
let fast = (anim_time as f32 * 7.0 + PI).sin();
|
||||
let fast = (acc_vel * 5.0 + PI).sin();
|
||||
|
||||
let ori: Vec2<f32> = Vec2::from(orientation);
|
||||
let last_ori = Vec2::from(last_ori);
|
||||
@ -44,20 +44,19 @@ impl Animation for SwimAnimation {
|
||||
let abstilt = tilt.abs();
|
||||
let x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude());
|
||||
|
||||
next.chest.scale = Vec3::one() / 11.0;
|
||||
next.chest.scale = Vec3::one() / 13.0;
|
||||
|
||||
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 11.0;
|
||||
next.chest.orientation = Quaternion::rotation_z(fast * -0.1)
|
||||
+ Quaternion::rotation_x(velocity.z.abs() * -0.005 + abstilt * 1.0 + x_tilt);
|
||||
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 13.0;
|
||||
next.chest.orientation = Quaternion::rotation_x(velocity.z.abs() * -0.005 + abstilt * 1.0 + x_tilt) * Quaternion::rotation_z(fast * -0.1);
|
||||
|
||||
next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
|
||||
next.tail.orientation = Quaternion::rotation_z(fast * 0.3 + tilt * 2.0);
|
||||
next.tail.orientation = Quaternion::rotation_z(fast * -1.0 * velocity.magnitude() * 0.1 + tilt * 2.0);
|
||||
|
||||
next.fin_l.position = Vec3::new(-s_a.fin.0, s_a.fin.1, s_a.fin.2);
|
||||
next.fin_l.orientation = Quaternion::rotation_z(fast * 0.3 - 0.3 + tilt * -0.5);
|
||||
next.fin_l.orientation = Quaternion::rotation_z(fast * 0.6 * velocity.magnitude() * 0.1 - 0.3 + tilt * -0.5);
|
||||
|
||||
next.fin_r.position = Vec3::new(s_a.fin.0, s_a.fin.1, s_a.fin.2);
|
||||
next.fin_r.orientation = Quaternion::rotation_z(-fast * 0.3 + 0.3 + tilt * -0.5);
|
||||
next.fin_r.orientation = Quaternion::rotation_z(fast * -0.6 * velocity.magnitude() * 0.1 + 0.3 + tilt * -0.5);
|
||||
next
|
||||
}
|
||||
}
|
@ -28,9 +28,9 @@ impl Animation for SwimIdleAnimation {
|
||||
|
||||
let slow = (anim_time as f32 * 3.5 + PI).sin();
|
||||
|
||||
next.chest.scale = Vec3::one() / 11.0;
|
||||
next.chest.scale = Vec3::one() / 13.0;
|
||||
|
||||
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 11.0;
|
||||
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1) / 13.0;
|
||||
next.chest.orientation = Quaternion::rotation_x(0.0);
|
||||
|
||||
next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
|
@ -2170,6 +2170,13 @@ impl FigureMgr {
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
// Bad, can potentially overflow
|
||||
if vel.0.magnitude_squared() != 0.0 {
|
||||
state.acc_vel += vel.0.magnitude() * dt;
|
||||
} else {
|
||||
state.acc_vel = 0.0;
|
||||
}
|
||||
|
||||
if !character.same_variant(&last_character.0) {
|
||||
state.state_time = 0.0;
|
||||
}
|
||||
@ -2214,7 +2221,14 @@ impl FigureMgr {
|
||||
// Swim
|
||||
(_, true, true) => anim::fish_medium::SwimAnimation::update_skeleton(
|
||||
&FishMediumSkeleton::default(),
|
||||
(vel.0, ori, state.last_ori, time, state.avg_vel),
|
||||
(
|
||||
vel.0,
|
||||
ori,
|
||||
state.last_ori,
|
||||
time,
|
||||
state.avg_vel,
|
||||
state.acc_vel,
|
||||
),
|
||||
state.state_time,
|
||||
&mut state_animation_rate,
|
||||
skeleton_attr,
|
||||
@ -2572,6 +2586,13 @@ impl FigureMgr {
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
// Bad, can potentially overflow
|
||||
if vel.0.magnitude_squared() != 0.0 {
|
||||
state.acc_vel += vel.0.magnitude() * dt;
|
||||
} else {
|
||||
state.acc_vel = 0.0;
|
||||
}
|
||||
|
||||
if !character.same_variant(&last_character.0) {
|
||||
state.state_time = 0.0;
|
||||
}
|
||||
@ -2616,7 +2637,14 @@ impl FigureMgr {
|
||||
// Swim
|
||||
(_, true, true) => anim::fish_small::SwimAnimation::update_skeleton(
|
||||
&FishSmallSkeleton::default(),
|
||||
(vel.0, ori, state.last_ori, time, state.avg_vel),
|
||||
(
|
||||
vel.0,
|
||||
ori,
|
||||
state.last_ori,
|
||||
time,
|
||||
state.avg_vel,
|
||||
state.acc_vel,
|
||||
),
|
||||
state.state_time,
|
||||
&mut state_animation_rate,
|
||||
skeleton_attr,
|
||||
@ -3775,6 +3803,7 @@ pub struct FigureStateMeta {
|
||||
avg_vel: anim::vek::Vec3<f32>,
|
||||
last_light: f32,
|
||||
last_glow: f32,
|
||||
acc_vel: f32,
|
||||
}
|
||||
|
||||
impl FigureStateMeta {
|
||||
@ -3821,6 +3850,7 @@ impl<S: Skeleton> FigureState<S> {
|
||||
avg_vel: anim::vek::Vec3::zero(),
|
||||
last_light: 1.0,
|
||||
last_glow: 0.0,
|
||||
acc_vel: 0.0,
|
||||
},
|
||||
skeleton,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user