mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
orientation tilt, make run frequency proportional to species size
This commit is contained in:
parent
a7c23ea5be
commit
894a823aad
@ -5,7 +5,7 @@ use vek::*;
|
||||
pub struct RunAnimation;
|
||||
|
||||
impl Animation for RunAnimation {
|
||||
type Dependency = (f32, f64);
|
||||
type Dependency = (f32, Vec3<f32>, Vec3<f32>, f64);
|
||||
type Skeleton = QuadrupedLowSkeleton;
|
||||
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
@ -14,19 +14,19 @@ impl Animation for RunAnimation {
|
||||
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_low_run")]
|
||||
fn update_skeleton_inner(
|
||||
skeleton: &Self::Skeleton,
|
||||
(_velocity, _global_time): Self::Dependency,
|
||||
(_velocity, orientation, last_ori, _global_time): Self::Dependency,
|
||||
anim_time: f64,
|
||||
_rate: &mut f32,
|
||||
skeleton_attr: &SkeletonAttr,
|
||||
) -> Self::Skeleton {
|
||||
let mut next = (*skeleton).clone();
|
||||
|
||||
let lab = 0.5 * (skeleton_attr.lean.0 + 1.0);
|
||||
let lab = 0.7 * (skeleton_attr.lean.0 + 1.0)*(1.0/skeleton_attr.scaler);
|
||||
|
||||
let center = (anim_time as f32 * lab as f32 + PI / 2.0).sin();
|
||||
let centeroffset = (anim_time as f32 * lab as f32 + PI * 1.5).sin();
|
||||
|
||||
let short = (((0.0)
|
||||
let short = (((1.0)
|
||||
/ (0.72
|
||||
+ 0.28
|
||||
* ((anim_time as f32 * 16.0 * lab as f32 + PI * 0.25).sin())
|
||||
@ -96,16 +96,29 @@ impl Animation for RunAnimation {
|
||||
* ((anim_time as f32 * 16.0 * lab as f32 + PI * 0.2).sin()).powf(2.0 as f32)))
|
||||
.sqrt())
|
||||
* ((anim_time as f32 * 16.0 * lab as f32 + PI * 0.2).sin());
|
||||
|
||||
let ori = Vec2::from(orientation);
|
||||
let last_ori = Vec2::from(last_ori);
|
||||
let tilt = if Vec2::new(ori, last_ori)
|
||||
.map(|o| Vec2::<f32>::from(o).magnitude_squared())
|
||||
.map(|m| m > 0.001 && m.is_finite())
|
||||
.reduce_and()
|
||||
&& ori.angle_between(last_ori).is_finite()
|
||||
{
|
||||
ori.angle_between(last_ori).min(0.2)
|
||||
* last_ori.determine_side(Vec2::zero(), ori).signum()
|
||||
} else {
|
||||
0.0
|
||||
} * 1.3;
|
||||
//let tilt = 0.0;
|
||||
next.head_upper.offset =
|
||||
Vec3::new(0.0, skeleton_attr.head_upper.0, skeleton_attr.head_upper.1);
|
||||
next.head_upper.ori =
|
||||
Quaternion::rotation_x(-skeleton_attr.lean.0) * Quaternion::rotation_z(short * -0.06);
|
||||
Quaternion::rotation_x(-skeleton_attr.lean.0) * Quaternion::rotation_z(short * -0.06 + tilt * -1.5);
|
||||
next.head_upper.scale = Vec3::one();
|
||||
|
||||
next.head_lower.offset =
|
||||
Vec3::new(0.0, skeleton_attr.head_lower.0, skeleton_attr.head_lower.1);
|
||||
next.head_lower.ori = Quaternion::rotation_x(0.0) * Quaternion::rotation_z(short * -0.15);
|
||||
next.head_lower.ori = Quaternion::rotation_x(0.0) * Quaternion::rotation_z(short * -0.15 + tilt * -0.8);
|
||||
next.head_lower.scale = Vec3::one();
|
||||
|
||||
next.jaw.offset = Vec3::new(0.0, skeleton_attr.jaw.0, skeleton_attr.jaw.1);
|
||||
@ -117,7 +130,7 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.tail_front.0 + skeleton_attr.lean.0 * 2.0,
|
||||
skeleton_attr.tail_front.1 + skeleton_attr.lean.0 * 2.0,
|
||||
);
|
||||
next.tail_front.ori = Quaternion::rotation_z(shortalt * 0.18)
|
||||
next.tail_front.ori = Quaternion::rotation_z(shortalt * 0.18 + tilt * 1.8)
|
||||
* Quaternion::rotation_y(shortalt * 0.1)
|
||||
* Quaternion::rotation_x(0.06 - skeleton_attr.lean.0 * 1.2);
|
||||
next.tail_front.scale = Vec3::one();
|
||||
@ -127,13 +140,13 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.tail_rear.0,
|
||||
skeleton_attr.tail_rear.1 + centeroffset * 0.6,
|
||||
);
|
||||
next.tail_rear.ori = Quaternion::rotation_z(shortalt * 0.25)
|
||||
next.tail_rear.ori = Quaternion::rotation_z(shortalt * 0.25 + tilt * 1.6)
|
||||
* Quaternion::rotation_y(shortalt * 0.1)
|
||||
* Quaternion::rotation_x(-0.04);
|
||||
next.tail_rear.scale = Vec3::one();
|
||||
|
||||
next.chest.offset = Vec3::new(0.0, skeleton_attr.chest.0, skeleton_attr.chest.1) *skeleton_attr.scaler/11.0;
|
||||
next.chest.ori = Quaternion::rotation_z(short * 0.12)
|
||||
next.chest.ori = Quaternion::rotation_z(short * 0.13 + tilt * -1.9)
|
||||
* Quaternion::rotation_y(shortalt * 0.12)
|
||||
* Quaternion::rotation_x(skeleton_attr.lean.0);
|
||||
next.chest.scale = Vec3::one() *skeleton_attr.scaler/11.0;
|
||||
@ -155,7 +168,7 @@ impl Animation for RunAnimation {
|
||||
);
|
||||
next.foot_fr.ori =
|
||||
Quaternion::rotation_x(footrotr * -0.25 * skeleton_attr.lean.1 - skeleton_attr.lean.0)
|
||||
* Quaternion::rotation_z(footrotr * -0.4 * skeleton_attr.lean.1);
|
||||
* Quaternion::rotation_z(footrotr * -0.4 * skeleton_attr.lean.1 + tilt * 3.5);
|
||||
next.foot_fr.scale = Vec3::one();
|
||||
|
||||
next.foot_bl.offset = Vec3::new(
|
||||
|
@ -5,7 +5,7 @@ use vek::*;
|
||||
pub struct RunAnimation;
|
||||
|
||||
impl Animation for RunAnimation {
|
||||
type Dependency = (f32, f64);
|
||||
type Dependency = (f32, Vec3<f32>, Vec3<f32>, f64);
|
||||
type Skeleton = QuadrupedMediumSkeleton;
|
||||
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
@ -14,7 +14,7 @@ impl Animation for RunAnimation {
|
||||
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_run")]
|
||||
fn update_skeleton_inner(
|
||||
skeleton: &Self::Skeleton,
|
||||
(velocity, _global_time): Self::Dependency,
|
||||
(velocity, orientation, last_ori, _global_time): Self::Dependency,
|
||||
anim_time: f64,
|
||||
rate: &mut f32,
|
||||
skeleton_attr: &SkeletonAttr,
|
||||
@ -24,7 +24,7 @@ impl Animation for RunAnimation {
|
||||
*rate = 1.0;
|
||||
let lab = 0.6;
|
||||
|
||||
let speedmult = if speed > 8.0 { 1.0 } else { 0.8 };
|
||||
let speedmult = if speed > 8.0 { 1.2* (1.0/skeleton_attr.scaler) } else { 1.0*(1.0/skeleton_attr.scaler) };
|
||||
|
||||
let short = (((1.0)
|
||||
/ (0.72
|
||||
@ -107,11 +107,26 @@ impl Animation for RunAnimation {
|
||||
.max(0.2);
|
||||
let horichest = (anim_time as f32 * lab as f32 * speedmult + PI * 0.8).sin();
|
||||
|
||||
//
|
||||
let ori = Vec2::from(orientation);
|
||||
let last_ori = Vec2::from(last_ori);
|
||||
let tilt = if Vec2::new(ori, last_ori)
|
||||
.map(|o| Vec2::<f32>::from(o).magnitude_squared())
|
||||
.map(|m| m > 0.001 && m.is_finite())
|
||||
.reduce_and()
|
||||
&& ori.angle_between(last_ori).is_finite()
|
||||
{
|
||||
ori.angle_between(last_ori).min(0.2)
|
||||
* last_ori.determine_side(Vec2::zero(), ori).signum()
|
||||
} else {
|
||||
0.0
|
||||
} * 1.3;
|
||||
//let tilt = 0.0;
|
||||
if speed < 8.0 {
|
||||
//Trot
|
||||
next.head_upper.offset =
|
||||
Vec3::new(0.0, skeleton_attr.head_upper.0, skeleton_attr.head_upper.1);
|
||||
next.head_upper.ori = Quaternion::rotation_x(0.0) * Quaternion::rotation_z(0.0);
|
||||
next.head_upper.ori = Quaternion::rotation_x(0.0) * Quaternion::rotation_z(tilt *-1.2);
|
||||
next.head_upper.scale = Vec3::one();
|
||||
|
||||
next.head_lower.offset = Vec3::new(
|
||||
@ -119,7 +134,7 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.head_lower.0 + horichest * 0.4,
|
||||
skeleton_attr.head_lower.1 + vertchest * -0.8,
|
||||
);
|
||||
next.head_lower.ori = Quaternion::rotation_z(0.0);
|
||||
next.head_lower.ori = Quaternion::rotation_z(tilt *-0.8);
|
||||
next.head_lower.scale = Vec3::one() * 1.02;
|
||||
|
||||
next.jaw.offset = Vec3::new(0.0, skeleton_attr.jaw.0, skeleton_attr.jaw.1);
|
||||
@ -127,7 +142,7 @@ impl Animation for RunAnimation {
|
||||
next.jaw.scale = Vec3::one() * 1.02;
|
||||
|
||||
next.tail.offset = Vec3::new(0.0, skeleton_attr.tail.0, skeleton_attr.tail.1);
|
||||
next.tail.ori = Quaternion::rotation_x(shortalt * 0.08);
|
||||
next.tail.ori = Quaternion::rotation_x(shortalt * 0.08)* Quaternion::rotation_z(tilt *1.5);
|
||||
next.tail.scale = Vec3::one();
|
||||
|
||||
next.torso_front.offset = Vec3::new(
|
||||
@ -140,7 +155,7 @@ impl Animation for RunAnimation {
|
||||
|
||||
next.torso_back.offset =
|
||||
Vec3::new(0.0, skeleton_attr.torso_back.0, skeleton_attr.torso_back.1);
|
||||
next.torso_back.ori = Quaternion::rotation_x(short * -0.03);
|
||||
next.torso_back.ori = Quaternion::rotation_x(short * -0.03)*Quaternion::rotation_z(tilt*1.8);
|
||||
next.torso_back.scale = Vec3::one();
|
||||
|
||||
next.ears.offset = Vec3::new(0.0, skeleton_attr.ears.0, skeleton_attr.ears.1);
|
||||
@ -153,7 +168,7 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.leg_f.1 + foothoril * -1.0,
|
||||
skeleton_attr.leg_f.2 + footvertl * -0.4,
|
||||
);
|
||||
next.leg_fl.ori = Quaternion::rotation_x(footrotl * -0.3);
|
||||
next.leg_fl.ori = Quaternion::rotation_x(footrotl * -0.3)*Quaternion::rotation_z(tilt * -1.5);
|
||||
next.leg_fl.scale = Vec3::one() * 0.99;
|
||||
|
||||
next.leg_fr.offset = Vec3::new(
|
||||
@ -161,7 +176,7 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.leg_f.1 + foothorir * -1.0,
|
||||
skeleton_attr.leg_f.2 + footvertr * -0.4,
|
||||
);
|
||||
next.leg_fr.ori = Quaternion::rotation_x(footrotr * -0.3);
|
||||
next.leg_fr.ori = Quaternion::rotation_x(footrotr * -0.3)*Quaternion::rotation_z(tilt * -1.5);
|
||||
next.leg_fr.scale = Vec3::one() * 0.99;
|
||||
|
||||
next.leg_bl.offset = Vec3::new(
|
||||
@ -169,7 +184,7 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.leg_b.1 + foothorilb * -1.0,
|
||||
skeleton_attr.leg_b.2 + footvertlb * -0.4,
|
||||
);
|
||||
next.leg_bl.ori = Quaternion::rotation_x(footrotlb * -0.3);
|
||||
next.leg_bl.ori = Quaternion::rotation_x(footrotlb * -0.3)*Quaternion::rotation_z(tilt * -1.5);
|
||||
next.leg_bl.scale = Vec3::one() * 0.99;
|
||||
|
||||
next.leg_br.offset = Vec3::new(
|
||||
@ -177,7 +192,7 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.leg_b.1 + foothorirb * -1.0,
|
||||
skeleton_attr.leg_b.2 + footvertrb * -0.4,
|
||||
);
|
||||
next.leg_br.ori = Quaternion::rotation_x(footrotrb * -0.3);
|
||||
next.leg_br.ori = Quaternion::rotation_x(footrotrb * -0.3)*Quaternion::rotation_z(tilt * -1.5);
|
||||
next.leg_br.scale = Vec3::one() * 0.99;
|
||||
|
||||
next.foot_fl.offset = Vec3::new(
|
||||
@ -215,7 +230,7 @@ impl Animation for RunAnimation {
|
||||
//Gallop
|
||||
next.head_upper.offset =
|
||||
Vec3::new(0.0, skeleton_attr.head_upper.0, skeleton_attr.head_upper.1);
|
||||
next.head_upper.ori = Quaternion::rotation_x(0.0) * Quaternion::rotation_z(0.0);
|
||||
next.head_upper.ori = Quaternion::rotation_x(0.0) * Quaternion::rotation_z(tilt *-1.2);
|
||||
next.head_upper.scale = Vec3::one();
|
||||
|
||||
next.head_lower.offset = Vec3::new(
|
||||
@ -223,7 +238,7 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.head_lower.0 + horichest * 0.4,
|
||||
skeleton_attr.head_lower.1 + vertchest * -0.8,
|
||||
);
|
||||
next.head_lower.ori = Quaternion::rotation_z(0.0);
|
||||
next.head_lower.ori = Quaternion::rotation_z(tilt *-0.8);
|
||||
next.head_lower.scale = Vec3::one() * 1.02;
|
||||
|
||||
next.jaw.offset = Vec3::new(0.0, skeleton_attr.jaw.0, skeleton_attr.jaw.1);
|
||||
@ -231,7 +246,7 @@ impl Animation for RunAnimation {
|
||||
next.jaw.scale = Vec3::one() * 1.02;
|
||||
|
||||
next.tail.offset = Vec3::new(0.0, skeleton_attr.tail.0, skeleton_attr.tail.1);
|
||||
next.tail.ori = Quaternion::rotation_x(shortalt * 0.3);
|
||||
next.tail.ori = Quaternion::rotation_x(shortalt * 0.3)*Quaternion::rotation_z(tilt * 1.5);
|
||||
next.tail.scale = Vec3::one();
|
||||
|
||||
next.torso_front.offset = Vec3::new(
|
||||
@ -239,12 +254,12 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.torso_front.0,
|
||||
skeleton_attr.torso_front.1 + shortalt * 2.0,
|
||||
) *skeleton_attr.scaler/11.0;
|
||||
next.torso_front.ori = Quaternion::rotation_x(short * 0.13);
|
||||
next.torso_front.ori = Quaternion::rotation_x(short * 0.13)*Quaternion::rotation_z(tilt * -1.5);
|
||||
next.torso_front.scale = Vec3::one() *skeleton_attr.scaler/11.0;
|
||||
|
||||
next.torso_back.offset =
|
||||
Vec3::new(0.0, skeleton_attr.torso_back.0, skeleton_attr.torso_back.1);
|
||||
next.torso_back.ori = Quaternion::rotation_x(short * 0.1);
|
||||
next.torso_back.ori = Quaternion::rotation_x(short * 0.1)*Quaternion::rotation_z(tilt*1.8);
|
||||
next.torso_back.scale = Vec3::one();
|
||||
|
||||
next.ears.offset = Vec3::new(0.0, skeleton_attr.ears.0, skeleton_attr.ears.1);
|
||||
@ -257,7 +272,7 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.leg_f.1 + foothoril * -2.5,
|
||||
skeleton_attr.leg_f.2 + 1.0 + footvertl * -1.0,
|
||||
);
|
||||
next.leg_fl.ori = Quaternion::rotation_x(footrotl * -0.6);
|
||||
next.leg_fl.ori = Quaternion::rotation_x(footrotl * -0.6)*Quaternion::rotation_z(tilt * -0.5);
|
||||
next.leg_fl.scale = Vec3::one() * 0.99;
|
||||
|
||||
next.leg_fr.offset = Vec3::new(
|
||||
@ -265,7 +280,7 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.leg_f.1 + foothoril * -2.5,
|
||||
skeleton_attr.leg_f.2 + 1.0 + footvertl * -1.0,
|
||||
);
|
||||
next.leg_fr.ori = Quaternion::rotation_x(footrotl * -0.6);
|
||||
next.leg_fr.ori = Quaternion::rotation_x(footrotl * -0.6)*Quaternion::rotation_z(tilt * -0.5);
|
||||
next.leg_fr.scale = Vec3::one() * 0.99;
|
||||
|
||||
next.leg_bl.offset = Vec3::new(
|
||||
@ -273,7 +288,7 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.leg_b.1 + foothorirb * -2.5,
|
||||
skeleton_attr.leg_b.2 + 1.0 + footvertrb * -1.2,
|
||||
);
|
||||
next.leg_bl.ori = Quaternion::rotation_x(footrotrb * -0.6);
|
||||
next.leg_bl.ori = Quaternion::rotation_x(footrotrb * -0.6)*Quaternion::rotation_z(tilt * -1.5);
|
||||
next.leg_bl.scale = Vec3::one() * 0.99;
|
||||
|
||||
next.leg_br.offset = Vec3::new(
|
||||
@ -281,7 +296,7 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.leg_b.1 + foothorirb * -2.5,
|
||||
skeleton_attr.leg_b.2 + 1.0 + footvertrb * -1.2,
|
||||
);
|
||||
next.leg_br.ori = Quaternion::rotation_x(footrotrb * -0.6);
|
||||
next.leg_br.ori = Quaternion::rotation_x(footrotrb * -0.6)*Quaternion::rotation_z(tilt * -1.5);
|
||||
next.leg_br.scale = Vec3::one() * 0.99;
|
||||
|
||||
next.foot_fl.offset = Vec3::new(
|
||||
|
@ -978,7 +978,7 @@ impl FigureMgr {
|
||||
(true, true, false) => {
|
||||
anim::quadruped_medium::RunAnimation::update_skeleton(
|
||||
&QuadrupedMediumSkeleton::new(),
|
||||
(vel.0.magnitude(), time),
|
||||
(vel.0.magnitude(), ori, state.last_ori, time),
|
||||
state.state_time,
|
||||
&mut state_animation_rate,
|
||||
skeleton_attr,
|
||||
@ -1058,7 +1058,7 @@ impl FigureMgr {
|
||||
// Running
|
||||
(true, true, false) => anim::quadruped_low::RunAnimation::update_skeleton(
|
||||
&QuadrupedLowSkeleton::new(),
|
||||
(vel.0.magnitude(), time),
|
||||
(vel.0.magnitude(), ori, state.last_ori, time),
|
||||
state.state_time,
|
||||
&mut state_animation_rate,
|
||||
skeleton_attr,
|
||||
|
Loading…
Reference in New Issue
Block a user