1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use super::{
    super::{vek::*, Animation},
    CharacterSkeleton, SkeletonAttr,
};
use std::ops::Mul;

pub struct GlidingAnimation;

type GlidingAnimationDependency = (Vec3<f32>, Quaternion<f32>, Quaternion<f32>, f32, f32);

impl Animation for GlidingAnimation {
    type Dependency<'a> = GlidingAnimationDependency;
    type Skeleton = CharacterSkeleton;

    #[cfg(feature = "use-dyn-lib")]
    const UPDATE_FN: &'static [u8] = b"character_gliding\0";

    #[cfg_attr(feature = "be-dyn-lib", export_name = "character_gliding")]

    fn update_skeleton_inner(
        skeleton: &Self::Skeleton,
        (velocity, orientation, glider_orientation, global_time, acc_vel): Self::Dependency<'_>,
        anim_time: f32,
        _rate: &mut f32,
        s_a: &SkeletonAttr,
    ) -> Self::Skeleton {
        let mut next = (*skeleton).clone();

        next.glider_trails = true;

        let speednorm = velocity.magnitude().min(50.0) / 50.0;
        let slow = (acc_vel * 0.1).sin();

        let head_look = Vec2::new(
            ((global_time + anim_time) / 4.0).floor().mul(7331.0).sin() * 0.5,
            ((global_time + anim_time) / 4.0).floor().mul(1337.0).sin() * 0.25,
        );

        let speedlog = speednorm.powi(2);
        let chest_ori = Quaternion::rotation_z(slow * 0.01);
        let chest_global_inv = (orientation * chest_ori).inverse();
        let glider_ori = chest_global_inv * glider_orientation;
        let glider_pos = Vec3::new(0.0, -5.0 + speedlog * 2.0, 13.0);

        next.head.orientation = Quaternion::rotation_x(0.5 + head_look.y * speednorm)
            * Quaternion::rotation_z(head_look.x);

        next.glider.position = glider_pos;
        next.glider.orientation = glider_ori;
        next.glider.scale = Vec3::one();

        next.chest.orientation = chest_ori;

        //necessary for overwriting jump anim
        next.belt.orientation = Quaternion::rotation_z(0.0);
        next.belt.position = Vec3::new(0.0, s_a.belt.0, s_a.belt.1);
        next.shorts.position = Vec3::new(0.0, s_a.shorts.0, s_a.shorts.1);
        next.shorts.orientation = Quaternion::rotation_z(slow * 0.15);

        next.shoulder_r.orientation = glider_ori * Quaternion::rotation_x(2.0);
        next.shoulder_l.orientation = next.shoulder_r.orientation;

        next.hand_l.position =
            glider_pos + glider_ori * Vec3::new(-s_a.hand.0 + -2.0, s_a.hand.1 + 8.0, s_a.hand.2);
        next.hand_l.orientation = Quaternion::rotation_x(3.35) * Quaternion::rotation_y(0.2);

        next.hand_r.position =
            glider_pos + glider_ori * Vec3::new(s_a.hand.0 + 2.0, s_a.hand.1 + 8.0, s_a.hand.2);
        next.hand_r.orientation = Quaternion::rotation_x(3.35) * Quaternion::rotation_y(-0.2);

        next.foot_l.position = Vec3::new(
            -s_a.foot.0,
            s_a.foot.1 + speedlog * -1.0 - slow * 2.3,
            s_a.foot.2,
        );
        next.foot_l.orientation = Quaternion::rotation_x(-speedlog + slow * -1.3 * speedlog);

        next.foot_r.position = Vec3::new(
            s_a.foot.0,
            s_a.foot.1 + speedlog * -1.0 + slow * 2.3,
            s_a.foot.2,
        );
        next.foot_r.orientation = Quaternion::rotation_x(-speedlog + slow * 1.3 * speedlog);

        next
    }
}