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", unsafe(export_name = "character_gliding"))]
19    fn update_skeleton_inner(
20        skeleton: &Self::Skeleton,
21        (velocity, orientation, glider_orientation, global_time, acc_vel): Self::Dependency<'_>,
22        anim_time: f32,
23        _rate: &mut f32,
24        s_a: &SkeletonAttr,
25    ) -> Self::Skeleton {
26        let mut next = (*skeleton).clone();
27
28        next.glider_trails = true;
29
30        let speednorm = velocity.magnitude().min(50.0) / 50.0;
31        let slow = (acc_vel * 0.1).sin();
32
33        let head_look = Vec2::new(
34            ((global_time + anim_time) / 4.0).floor().mul(7331.0).sin() * 0.5,
35            ((global_time + anim_time) / 4.0).floor().mul(1337.0).sin() * 0.25,
36        );
37
38        let speedlog = speednorm.powi(2);
39        let chest_ori = Quaternion::rotation_z(slow * 0.01);
40        let chest_global_inv = (orientation * chest_ori).inverse();
41        let glider_ori = chest_global_inv * glider_orientation;
42        let glider_pos = Vec3::new(0.0, -5.0 + speedlog * 2.0, 13.0);
43
44        next.head.orientation = Quaternion::rotation_x(0.5 + head_look.y * speednorm)
45            * Quaternion::rotation_z(head_look.x);
46
47        next.glider.position = glider_pos;
48        next.glider.orientation = glider_ori;
49        next.glider.scale = Vec3::one();
50
51        next.chest.orientation = chest_ori;
52
53        //necessary for overwriting jump anim
54        next.belt.orientation = Quaternion::rotation_z(0.0);
55        next.belt.position = Vec3::new(0.0, s_a.belt.0, s_a.belt.1);
56        next.shorts.position = Vec3::new(0.0, s_a.shorts.0, s_a.shorts.1);
57        next.shorts.orientation = Quaternion::rotation_z(slow * 0.15);
58
59        next.shoulder_r.orientation = glider_ori * Quaternion::rotation_x(2.0);
60        next.shoulder_l.orientation = next.shoulder_r.orientation;
61
62        next.hand_l.position =
63            glider_pos + glider_ori * Vec3::new(-s_a.hand.0 + -2.0, s_a.hand.1 + 8.0, s_a.hand.2);
64        next.hand_l.orientation = Quaternion::rotation_x(3.35) * Quaternion::rotation_y(0.2);
65
66        next.hand_r.position =
67            glider_pos + glider_ori * Vec3::new(s_a.hand.0 + 2.0, s_a.hand.1 + 8.0, s_a.hand.2);
68        next.hand_r.orientation = Quaternion::rotation_x(3.35) * Quaternion::rotation_y(-0.2);
69
70        next.foot_l.position = Vec3::new(
71            -s_a.foot.0,
72            s_a.foot.1 + speedlog * -1.0 - slow * 2.3,
73            s_a.foot.2,
74        );
75        next.foot_l.orientation = Quaternion::rotation_x(-speedlog + slow * -1.3 * speedlog);
76
77        next.foot_r.position = Vec3::new(
78            s_a.foot.0,
79            s_a.foot.1 + speedlog * -1.0 + slow * 2.3,
80            s_a.foot.2,
81        );
82        next.foot_r.orientation = Quaternion::rotation_x(-speedlog + slow * 1.3 * speedlog);
83
84        next
85    }
86}