veloren_voxygen_anim/quadruped_medium/
jump.rs

1use super::{
2    super::{Animation, vek::*},
3    QuadrupedMediumSkeleton, SkeletonAttr,
4};
5
6pub struct JumpAnimation;
7
8impl Animation for JumpAnimation {
9    type Dependency<'a> = (f32, Vec3<f32>, Vec3<f32>);
10    type Skeleton = QuadrupedMediumSkeleton;
11
12    #[cfg(feature = "use-dyn-lib")]
13    const UPDATE_FN: &'static [u8] = b"quadruped_medium_jump\0";
14
15    #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_jump")]
16    fn update_skeleton_inner(
17        skeleton: &Self::Skeleton,
18        (_global_time, velocity, avg_vel): Self::Dependency<'_>,
19        _anim_time: f32,
20        _rate: &mut f32,
21        s_a: &SkeletonAttr,
22    ) -> Self::Skeleton {
23        let mut next = (*skeleton).clone();
24
25        next.neck.scale = Vec3::one() * 1.02;
26        next.jaw.scale = Vec3::one() * 1.02;
27        next.leg_fl.scale = Vec3::one() * 1.02;
28        next.leg_fr.scale = Vec3::one() * 1.02;
29        next.leg_bl.scale = Vec3::one() * 1.02;
30        next.leg_br.scale = Vec3::one() * 1.02;
31        next.foot_fl.scale = Vec3::one() * 0.96;
32        next.foot_fr.scale = Vec3::one() * 0.96;
33        next.foot_bl.scale = Vec3::one() * 0.96;
34        next.foot_br.scale = Vec3::one() * 0.96;
35        next.ears.scale = Vec3::one() * 1.02;
36        let speed = Vec2::<f32>::from(velocity).magnitude();
37        let velocityalt = speed.max(3.0);
38        let normalize = velocityalt / 22.0;
39
40        let x_tilt = (avg_vel.z.atan2(avg_vel.xy().magnitude()) * normalize).max(-0.28);
41        let x_tilt = if velocityalt < 3.5 {
42            x_tilt.abs()
43        } else {
44            x_tilt
45        };
46
47        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
48        next.head.orientation = Quaternion::rotation_x(x_tilt * -0.5);
49
50        next.neck.position = Vec3::new(0.0, s_a.neck.0, s_a.neck.1);
51        next.neck.orientation = Quaternion::rotation_x(x_tilt * -1.0);
52
53        next.jaw.position = Vec3::new(0.0, s_a.jaw.0, s_a.jaw.1);
54        next.jaw.orientation = Quaternion::rotation_x(0.0);
55
56        next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
57        next.tail.orientation = Quaternion::rotation_x(-0.6 * normalize + x_tilt * 2.0);
58
59        next.torso_front.position = Vec3::new(0.0, s_a.torso_front.0, s_a.torso_front.1);
60        next.torso_front.orientation = Quaternion::rotation_x(x_tilt * 3.5);
61
62        next.torso_back.position = Vec3::new(0.0, s_a.torso_back.0, s_a.torso_back.1);
63        next.torso_back.orientation = Quaternion::rotation_x(x_tilt * -1.2);
64
65        next.ears.position = Vec3::new(0.0, s_a.ears.0, s_a.ears.1);
66        next.ears.orientation = Quaternion::rotation_x(x_tilt * 1.5);
67
68        next.leg_fl.position = Vec3::new(-s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
69        next.leg_fl.orientation = Quaternion::rotation_x(1.2 * normalize + x_tilt.abs() * 0.8);
70
71        next.leg_fr.position = Vec3::new(s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
72        next.leg_fr.orientation = Quaternion::rotation_x(1.2 * normalize + x_tilt.abs() * 0.8);
73
74        next.leg_bl.position = Vec3::new(-s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
75        next.leg_bl.orientation = Quaternion::rotation_x(-0.8 * normalize + x_tilt * -0.8);
76
77        next.leg_br.position = Vec3::new(s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
78        next.leg_br.orientation = Quaternion::rotation_x(-0.8 * normalize + x_tilt * -0.8);
79
80        next.foot_fl.position = Vec3::new(-s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2);
81        next.foot_fl.orientation = Quaternion::rotation_x(-0.4 * normalize + x_tilt * -0.4);
82
83        next.foot_fr.position = Vec3::new(s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2);
84        next.foot_fr.orientation = Quaternion::rotation_x(-0.4 * normalize + x_tilt * -0.4);
85
86        next.foot_bl.position = Vec3::new(-s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2);
87        next.foot_bl.orientation = Quaternion::rotation_x(-0.4 * normalize + x_tilt * -0.4);
88
89        next.foot_br.position = Vec3::new(s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2);
90        next.foot_br.orientation = Quaternion::rotation_x(-0.4 * normalize + x_tilt * -0.4);
91
92        next
93    }
94}