veloren_voxygen_anim/character/
idle.rs

1use super::{
2    super::{Animation, vek::*},
3    CharacterSkeleton, SkeletonAttr,
4};
5use common::comp::item::{Hands, ToolKind};
6use std::ops::Mul;
7
8pub struct IdleAnimation;
9
10impl Animation for IdleAnimation {
11    type Dependency<'a> = (
12        Option<ToolKind>,
13        Option<ToolKind>,
14        (Option<Hands>, Option<Hands>),
15        f32,
16    );
17    type Skeleton = CharacterSkeleton;
18
19    #[cfg(feature = "use-dyn-lib")]
20    const UPDATE_FN: &'static [u8] = b"character_idle\0";
21
22    #[cfg_attr(feature = "be-dyn-lib", export_name = "character_idle")]
23    fn update_skeleton_inner(
24        skeleton: &Self::Skeleton,
25        (active_tool_kind, second_tool_kind, hands, global_time): Self::Dependency<'_>,
26        anim_time: f32,
27        _rate: &mut f32,
28        s_a: &SkeletonAttr,
29    ) -> Self::Skeleton {
30        let mut next = (*skeleton).clone();
31
32        let slow = (anim_time * 1.0).sin();
33        let head_look = Vec2::new(
34            (global_time + anim_time / 12.0).floor().mul(7331.0).sin() * 0.1,
35            (global_time + anim_time / 12.0).floor().mul(1337.0).sin() * 0.05,
36        );
37        next.head.scale = Vec3::one() * s_a.head_scale;
38        next.chest.scale = Vec3::one() * 1.01;
39        next.hand_l.scale = Vec3::one() * 1.04;
40        next.hand_r.scale = Vec3::one() * 1.04;
41        next.back.scale = Vec3::one() * 1.02;
42        next.hold.scale = Vec3::one() * 0.0;
43        next.shoulder_l.scale = Vec3::one() * 1.1;
44        next.shoulder_r.scale = Vec3::one() * 1.1;
45
46        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + slow * 0.3);
47        next.head.orientation =
48            Quaternion::rotation_z(head_look.x) * Quaternion::rotation_x(head_look.y.abs());
49
50        next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + slow * 0.3);
51        next.chest.orientation = Quaternion::rotation_z(head_look.x * 0.6);
52
53        next.belt.position = Vec3::new(0.0, s_a.belt.0, s_a.belt.1);
54        next.belt.orientation = Quaternion::rotation_z(head_look.x * -0.1);
55
56        next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
57
58        next.shorts.position = Vec3::new(0.0, s_a.shorts.0, s_a.shorts.1);
59        next.shorts.orientation = Quaternion::rotation_z(head_look.x * -0.2);
60
61        next.hand_l.position = Vec3::new(
62            -s_a.hand.0,
63            s_a.hand.1 + slow * 0.15,
64            s_a.hand.2 + slow * 0.5,
65        );
66
67        next.hand_l.orientation = Quaternion::rotation_x(slow * -0.06);
68
69        next.hand_r.position = Vec3::new(
70            s_a.hand.0,
71            s_a.hand.1 + slow * 0.15,
72            s_a.hand.2 + slow * 0.5,
73        );
74        next.hand_r.orientation = Quaternion::rotation_x(slow * -0.06);
75
76        next.foot_l.position = Vec3::new(-s_a.foot.0, s_a.foot.1, s_a.foot.2);
77
78        next.foot_r.position = Vec3::new(s_a.foot.0, s_a.foot.1, s_a.foot.2);
79
80        next.shoulder_l.position = Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
81
82        next.shoulder_r.position = Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
83
84        next.glider.position = Vec3::new(0.0, 0.0, 10.0);
85        next.glider.scale = Vec3::one() * 0.0;
86        next.hold.position = Vec3::new(0.4, -0.3, -5.8);
87
88        next.do_tools_on_back(hands, active_tool_kind, second_tool_kind);
89
90        next.do_hold_lantern(s_a, anim_time, 0.0, 0.0, 0.0, 0.0);
91
92        next.torso.position = Vec3::new(0.0, 0.0, 0.0);
93
94        next
95    }
96}