veloren_voxygen_anim/character/
steer.rs

1use super::{
2    super::{Animation, vek::*},
3    CharacterSkeleton, SkeletonAttr,
4};
5use common::comp::item::ToolKind;
6use std::{f32::consts::PI, ops::Mul};
7
8pub struct SteerAnimation;
9
10impl Animation for SteerAnimation {
11    type Dependency<'a> = (Option<ToolKind>, Option<ToolKind>, f32, f32);
12    type Skeleton = CharacterSkeleton;
13
14    #[cfg(feature = "use-dyn-lib")]
15    const UPDATE_FN: &'static [u8] = b"character_steer\0";
16
17    #[cfg_attr(feature = "be-dyn-lib", export_name = "character_steer")]
18    fn update_skeleton_inner(
19        skeleton: &Self::Skeleton,
20        (_active_tool_kind, _second_tool_kind, steer_dir, global_time): Self::Dependency<'_>,
21        anim_time: f32,
22        _rate: &mut f32,
23        s_a: &SkeletonAttr,
24    ) -> Self::Skeleton {
25        let mut next = (*skeleton).clone();
26
27        let slow = (anim_time * 1.0).sin();
28        let head_look = Vec2::new(
29            (global_time + anim_time / 12.0).floor().mul(7331.0).sin() * 0.1,
30            (global_time + anim_time / 12.0).floor().mul(1337.0).sin() * 0.05,
31        );
32        next.head.scale = Vec3::one() * s_a.head_scale;
33        next.chest.scale = Vec3::one() * 1.01;
34        next.hand_l.scale = Vec3::one() * 1.04;
35        next.hand_r.scale = Vec3::one() * 1.04;
36        next.back.scale = Vec3::one() * 1.02;
37        next.hold.scale = Vec3::one() * 0.0;
38        next.lantern.scale = Vec3::one() * 0.65;
39        next.shoulder_l.scale = Vec3::one() * 1.1;
40        next.shoulder_r.scale = Vec3::one() * 1.1;
41
42        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + slow * 0.3);
43        next.head.orientation =
44            Quaternion::rotation_z(head_look.x) * Quaternion::rotation_x(head_look.y.abs());
45
46        next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + slow * 0.3);
47        next.chest.orientation = Quaternion::rotation_z(head_look.x * 0.06);
48
49        next.belt.position = Vec3::new(0.0, s_a.belt.0, s_a.belt.1);
50        next.belt.orientation = Quaternion::rotation_z(head_look.x * -0.1);
51
52        next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
53
54        next.shorts.position = Vec3::new(0.0, s_a.shorts.0, s_a.shorts.1);
55        next.shorts.orientation = Quaternion::rotation_z(head_look.x * -0.2);
56
57        next.hand_l.position = Vec3::new(
58            -s_a.hand.0,
59            s_a.hand.1 + slow * 0.15,
60            s_a.hand.2 + slow * 0.5,
61        );
62
63        let helm_center = Vec3::new(0.0, 0.6, 0.75) / s_a.scaler * 11.0;
64
65        let rot = steer_dir * 0.5;
66
67        let hand_rotation = Quaternion::rotation_y(rot) * Quaternion::rotation_x(PI / 2.0);
68
69        let hand_offset = Vec3::new(rot.cos(), 0.0, -rot.sin()) * 0.4 / s_a.scaler * 11.0;
70
71        next.hand_l.position = helm_center - hand_offset;
72        next.hand_r.position = helm_center + hand_offset;
73
74        let ori_l = Quaternion::rotation_x(
75            PI / 2.0 + (next.hand_l.position.z / next.hand_l.position.x).atan(),
76        );
77        let ori_r = Quaternion::rotation_x(
78            PI / 2.0 - (next.hand_r.position.z / next.hand_r.position.x).atan(),
79        );
80
81        next.hand_l.orientation = hand_rotation * ori_l;
82        next.hand_r.orientation = -hand_rotation * ori_r;
83
84        next.shoulder_l.position = Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
85        next.shoulder_l.orientation = ori_r;
86        next.shoulder_r.position = Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
87        next.shoulder_r.orientation = ori_l;
88
89        next.foot_l.position = Vec3::new(-s_a.foot.0, s_a.foot.1, s_a.foot.2);
90        next.foot_l.orientation = Quaternion::identity();
91
92        next.foot_r.position = Vec3::new(s_a.foot.0, s_a.foot.1, s_a.foot.2);
93        next.foot_r.orientation = Quaternion::identity();
94
95        next.glider.position = Vec3::new(0.0, 0.0, 10.0);
96        next.glider.scale = Vec3::one() * 0.0;
97        next.hold.position = Vec3::new(0.4, -0.3, -5.8);
98
99        if skeleton.holding_lantern {
100            next.hand_r.position = Vec3::new(
101                s_a.hand.0 - head_look.x * 6.0,
102                s_a.hand.1 + 5.0 - head_look.y * 10.0 + slow * 0.15,
103                s_a.hand.2 + 12.0 + head_look.y * 6.0 + slow * 0.5,
104            );
105            next.hand_r.orientation = Quaternion::rotation_x(2.25 + slow * -0.06)
106                * Quaternion::rotation_z(0.9)
107                * Quaternion::rotation_y(head_look.x * 1.5)
108                * Quaternion::rotation_x(head_look.y * 1.5);
109
110            next.lantern.position = Vec3::new(-0.5, -0.5, -2.5);
111            next.lantern.orientation = next.hand_r.orientation.inverse();
112        }
113
114        next.torso.position = Vec3::new(0.0, 0.0, 0.0);
115
116        next
117    }
118}