2020-01-26 00:22:48 +00:00
|
|
|
use super::{super::Animation, CharacterSkeleton, SkeletonAttr};
|
2019-11-10 23:36:47 +00:00
|
|
|
use common::comp::item::Tool;
|
2019-05-16 04:40:35 +00:00
|
|
|
use std::{f32::consts::PI, ops::Mul};
|
|
|
|
use vek::*;
|
|
|
|
|
|
|
|
pub struct GlidingAnimation;
|
|
|
|
|
|
|
|
impl Animation for GlidingAnimation {
|
|
|
|
type Skeleton = CharacterSkeleton;
|
2019-11-10 23:36:47 +00:00
|
|
|
type Dependency = (Option<Tool>, Vec3<f32>, Vec3<f32>, Vec3<f32>, f64);
|
2019-05-16 04:40:35 +00:00
|
|
|
|
|
|
|
fn update_skeleton(
|
|
|
|
skeleton: &Self::Skeleton,
|
2019-11-10 23:36:47 +00:00
|
|
|
(_active_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency,
|
2019-05-16 04:40:35 +00:00
|
|
|
anim_time: f64,
|
2019-09-09 19:11:40 +00:00
|
|
|
_rate: &mut f32,
|
2019-06-28 08:24:13 +00:00
|
|
|
skeleton_attr: &SkeletonAttr,
|
2019-05-16 04:40:35 +00:00
|
|
|
) -> Self::Skeleton {
|
|
|
|
let mut next = (*skeleton).clone();
|
2019-09-09 19:11:40 +00:00
|
|
|
|
|
|
|
let speed = Vec2::<f32>::from(velocity).magnitude();
|
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
let wave_slow = (anim_time as f32 * 7.0).sin();
|
|
|
|
let wave_slow_cos = (anim_time as f32 * 7.0).cos();
|
2019-05-16 04:40:35 +00:00
|
|
|
let wave_stop = (anim_time as f32 * 1.5).min(PI / 2.0).sin();
|
2019-05-17 09:22:32 +00:00
|
|
|
let wave_very_slow = (anim_time as f32 * 3.0).sin();
|
|
|
|
let wave_very_slow_alt = (anim_time as f32 * 2.5).sin();
|
|
|
|
let wave_very_slow_cos = (anim_time as f32 * 3.0).cos();
|
2019-05-16 04:40:35 +00:00
|
|
|
|
|
|
|
let head_look = Vec2::new(
|
|
|
|
((global_time + anim_time) as f32 / 4.0)
|
|
|
|
.floor()
|
|
|
|
.mul(7331.0)
|
|
|
|
.sin()
|
|
|
|
* 0.5,
|
|
|
|
((global_time + anim_time) as f32 / 4.0)
|
|
|
|
.floor()
|
|
|
|
.mul(1337.0)
|
|
|
|
.sin()
|
|
|
|
* 0.25,
|
|
|
|
);
|
2019-09-09 19:11:40 +00:00
|
|
|
|
|
|
|
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.15)
|
|
|
|
* last_ori.determine_side(Vec2::zero(), ori).signum()
|
|
|
|
} else {
|
|
|
|
0.0
|
|
|
|
} * 0.8;
|
|
|
|
|
2019-06-28 08:24:13 +00:00
|
|
|
next.head.offset = Vec3::new(
|
2019-06-28 14:45:02 +00:00
|
|
|
0.0 + skeleton_attr.neck_right,
|
2019-10-02 10:05:17 +00:00
|
|
|
-2.0 + skeleton_attr.neck_forward,
|
|
|
|
skeleton_attr.neck_height + 12.0,
|
2019-06-28 08:24:13 +00:00
|
|
|
);
|
2019-05-17 09:22:32 +00:00
|
|
|
next.head.ori = Quaternion::rotation_x(0.35 - wave_very_slow * 0.10 + head_look.y)
|
|
|
|
* Quaternion::rotation_z(head_look.x + wave_very_slow_cos * 0.15);
|
2019-06-28 08:24:13 +00:00
|
|
|
next.head.scale = Vec3::one() * skeleton_attr.head_scale;
|
2019-05-16 04:40:35 +00:00
|
|
|
|
2019-06-16 02:16:22 +00:00
|
|
|
next.chest.offset = Vec3::new(0.0, 0.0, -2.0);
|
2019-06-28 08:24:13 +00:00
|
|
|
next.chest.ori = Quaternion::rotation_z(wave_very_slow_cos * 0.2);
|
2019-05-16 04:40:35 +00:00
|
|
|
next.chest.scale = Vec3::one();
|
|
|
|
|
2019-06-16 02:16:22 +00:00
|
|
|
next.belt.offset = Vec3::new(0.0, 0.0, -4.0);
|
2019-06-28 08:24:13 +00:00
|
|
|
next.belt.ori = Quaternion::rotation_z(wave_very_slow_cos * 0.25);
|
2019-05-16 04:40:35 +00:00
|
|
|
next.belt.scale = Vec3::one();
|
|
|
|
|
2019-06-16 02:16:22 +00:00
|
|
|
next.shorts.offset = Vec3::new(0.0, 0.0, -7.0);
|
2019-05-17 09:22:32 +00:00
|
|
|
next.shorts.ori = Quaternion::rotation_z(wave_very_slow_cos * 0.25);
|
2019-05-16 04:40:35 +00:00
|
|
|
next.shorts.scale = Vec3::one();
|
|
|
|
|
2019-06-30 22:52:25 +00:00
|
|
|
next.l_hand.offset = Vec3::new(
|
|
|
|
-9.5 + wave_very_slow_cos * -1.5,
|
2019-10-02 10:05:17 +00:00
|
|
|
-3.0 + wave_very_slow_cos * 1.5,
|
|
|
|
6.0,
|
2019-06-30 22:52:25 +00:00
|
|
|
);
|
2019-10-02 10:05:17 +00:00
|
|
|
next.l_hand.ori = Quaternion::rotation_x(-2.7 + wave_very_slow_cos * -0.1);
|
2019-06-16 02:16:22 +00:00
|
|
|
next.l_hand.scale = Vec3::one();
|
|
|
|
|
2019-06-30 22:52:25 +00:00
|
|
|
next.r_hand.offset = Vec3::new(
|
|
|
|
9.5 + wave_very_slow_cos * -1.5,
|
2019-10-02 10:05:17 +00:00
|
|
|
-3.0 + wave_very_slow_cos * -1.5,
|
|
|
|
6.0,
|
2019-06-30 22:52:25 +00:00
|
|
|
);
|
2019-10-02 10:05:17 +00:00
|
|
|
next.r_hand.ori = Quaternion::rotation_x(-2.7 + wave_very_slow_cos * -0.10);
|
2019-06-16 02:16:22 +00:00
|
|
|
next.r_hand.scale = Vec3::one();
|
|
|
|
|
|
|
|
next.l_foot.offset = Vec3::new(-3.4, 1.0, -2.0);
|
2019-05-17 09:22:32 +00:00
|
|
|
next.l_foot.ori = Quaternion::rotation_x(
|
2019-09-09 19:11:40 +00:00
|
|
|
(wave_stop * -0.7 - wave_slow_cos * -0.21 + wave_very_slow * 0.19) * speed * 0.04,
|
2019-05-17 09:22:32 +00:00
|
|
|
);
|
2019-06-28 08:24:13 +00:00
|
|
|
|
2019-05-16 04:40:35 +00:00
|
|
|
next.l_foot.scale = Vec3::one();
|
|
|
|
|
2019-06-16 02:16:22 +00:00
|
|
|
next.r_foot.offset = Vec3::new(3.4, 1.0, -2.0);
|
2019-05-17 09:22:32 +00:00
|
|
|
next.r_foot.ori = Quaternion::rotation_x(
|
2019-09-09 19:11:40 +00:00
|
|
|
(wave_stop * -0.8 + wave_slow * -0.25 + wave_very_slow_alt * 0.13) * speed * 0.04,
|
2019-05-17 09:22:32 +00:00
|
|
|
);
|
2019-05-16 04:40:35 +00:00
|
|
|
next.r_foot.scale = Vec3::one();
|
|
|
|
|
2019-12-03 06:30:08 +00:00
|
|
|
next.main.offset = Vec3::new(
|
2019-06-28 08:24:13 +00:00
|
|
|
-7.0 + skeleton_attr.weapon_x,
|
|
|
|
-5.0 + skeleton_attr.weapon_y,
|
|
|
|
15.0,
|
|
|
|
);
|
2019-12-03 06:30:08 +00:00
|
|
|
next.main.ori = Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57);
|
|
|
|
next.main.scale = Vec3::one();
|
2019-05-16 04:40:35 +00:00
|
|
|
|
2019-08-18 06:35:27 +00:00
|
|
|
next.l_shoulder.offset = Vec3::new(-5.0, 0.0, 4.7);
|
2019-05-16 04:40:35 +00:00
|
|
|
next.l_shoulder.ori = Quaternion::rotation_x(0.0);
|
2019-08-18 06:35:27 +00:00
|
|
|
next.l_shoulder.scale = Vec3::one() * 1.1;
|
2019-05-16 04:40:35 +00:00
|
|
|
|
2019-08-18 06:35:27 +00:00
|
|
|
next.r_shoulder.offset = Vec3::new(5.0, 0.0, 4.7);
|
2019-05-16 04:40:35 +00:00
|
|
|
next.r_shoulder.ori = Quaternion::rotation_x(0.0);
|
2019-08-18 06:35:27 +00:00
|
|
|
next.r_shoulder.scale = Vec3::one() * 1.1;
|
2019-05-19 17:36:55 +00:00
|
|
|
|
2019-12-03 06:30:08 +00:00
|
|
|
next.glider.offset = Vec3::new(0.0, -13.0 + wave_very_slow * 0.10, 6.0);
|
|
|
|
next.glider.ori =
|
2019-09-09 19:11:40 +00:00
|
|
|
Quaternion::rotation_x(1.0) * Quaternion::rotation_y(wave_very_slow_cos * 0.04);
|
2019-12-03 06:30:08 +00:00
|
|
|
next.glider.scale = Vec3::one();
|
|
|
|
|
|
|
|
next.lantern.offset = Vec3::new(0.0, 0.0, 0.0);
|
|
|
|
next.lantern.ori = Quaternion::rotation_x(0.0);
|
|
|
|
next.lantern.scale = Vec3::one() * 0.0;
|
2019-05-19 17:36:55 +00:00
|
|
|
|
2019-06-28 08:24:13 +00:00
|
|
|
next.torso.offset = Vec3::new(0.0, 6.0, 15.0) / 11.0 * skeleton_attr.scaler;
|
2019-09-09 19:11:40 +00:00
|
|
|
next.torso.ori = Quaternion::rotation_x(-0.05 * speed.max(12.0) + wave_very_slow * 0.10)
|
|
|
|
* Quaternion::rotation_y(tilt * 16.0);
|
2019-06-28 08:24:13 +00:00
|
|
|
next.torso.scale = Vec3::one() / 11.0 * skeleton_attr.scaler;
|
2019-05-16 04:40:35 +00:00
|
|
|
|
|
|
|
next
|
|
|
|
}
|
|
|
|
}
|