veloren_voxygen_anim/character/
gliding.rs

1use super::{
2    super::{Animation, vek::*},
3    CharacterSkeleton, SkeletonAttr,
4};
5use std::ops::Mul;
6
7pub struct GlidingAnimation;
8
9type GlidingAnimationDependency = (Vec3<f32>, Quaternion<f32>, Quaternion<f32>, f32, f32);
10
11impl Animation for GlidingAnimation {
12    type Dependency<'a> = GlidingAnimationDependency;
13    type Skeleton = CharacterSkeleton;
14
15    #[cfg(feature = "use-dyn-lib")]
16    const UPDATE_FN: &'static [u8] = b"character_gliding\0";
17
18    #[cfg_attr(feature = "be-dyn-lib", export_name = "character_gliding")]
19
20    fn update_skeleton_inner(
21        skeleton: &Self::Skeleton,
22        (velocity, orientation, glider_orientation, global_time, acc_vel): Self::Dependency<'_>,
23        anim_time: f32,
24        _rate: &mut f32,
25        s_a: &SkeletonAttr,
26    ) -> Self::Skeleton {
27        let mut next = (*skeleton).clone();
28
29        next.glider_trails = true;
30
31        let speednorm = velocity.magnitude().min(50.0) / 50.0;
32        let slow = (acc_vel * 0.1).sin();
33
34        let head_look = Vec2::new(
35            ((global_time + anim_time) / 4.0).floor().mul(7331.0).sin() * 0.5,
36            ((global_time + anim_time) / 4.0).floor().mul(1337.0).sin() * 0.25,
37        );
38
39        let speedlog = speednorm.powi(2);
40        let chest_ori = Quaternion::rotation_z(slow * 0.01);
41        let chest_global_inv = (orientation * chest_ori).inverse();
42        let glider_ori = chest_global_inv * glider_orientation;
43        let glider_pos = Vec3::new(0.0, -5.0 + speedlog * 2.0, 13.0);
44
45        next.head.orientation = Quaternion::rotation_x(0.5 + head_look.y * speednorm)
46            * Quaternion::rotation_z(head_look.x);
47
48        next.glider.position = glider_pos;
49        next.glider.orientation = glider_ori;
50        next.glider.scale = Vec3::one();
51
52        next.chest.orientation = chest_ori;
53
54        //necessary for overwriting jump anim
55        next.belt.orientation = Quaternion::rotation_z(0.0);
56        next.belt.position = Vec3::new(0.0, s_a.belt.0, s_a.belt.1);
57        next.shorts.position = Vec3::new(0.0, s_a.shorts.0, s_a.shorts.1);
58        next.shorts.orientation = Quaternion::rotation_z(slow * 0.15);
59
60        next.shoulder_r.orientation = glider_ori * Quaternion::rotation_x(2.0);
61        next.shoulder_l.orientation = next.shoulder_r.orientation;
62
63        next.hand_l.position =
64            glider_pos + glider_ori * Vec3::new(-s_a.hand.0 + -2.0, s_a.hand.1 + 8.0, s_a.hand.2);
65        next.hand_l.orientation = Quaternion::rotation_x(3.35) * Quaternion::rotation_y(0.2);
66
67        next.hand_r.position =
68            glider_pos + glider_ori * Vec3::new(s_a.hand.0 + 2.0, s_a.hand.1 + 8.0, s_a.hand.2);
69        next.hand_r.orientation = Quaternion::rotation_x(3.35) * Quaternion::rotation_y(-0.2);
70
71        next.foot_l.position = Vec3::new(
72            -s_a.foot.0,
73            s_a.foot.1 + speedlog * -1.0 - slow * 2.3,
74            s_a.foot.2,
75        );
76        next.foot_l.orientation = Quaternion::rotation_x(-speedlog + slow * -1.3 * speedlog);
77
78        next.foot_r.position = Vec3::new(
79            s_a.foot.0,
80            s_a.foot.1 + speedlog * -1.0 + slow * 2.3,
81            s_a.foot.2,
82        );
83        next.foot_r.orientation = Quaternion::rotation_x(-speedlog + slow * 1.3 * speedlog);
84
85        next
86    }
87}