veloren_voxygen_anim/character/
stand.rs

1use super::{
2    super::{Animation, vek::*},
3    CharacterSkeleton, SkeletonAttr,
4};
5use common::{
6    comp::item::{Hands, ToolKind},
7    util::Dir,
8};
9use std::ops::Mul;
10
11pub struct StandAnimation;
12
13impl Animation for StandAnimation {
14    type Dependency<'a> = (
15        Option<ToolKind>,
16        Option<ToolKind>,
17        (Option<Hands>, Option<Hands>),
18        Vec3<f32>,
19        Vec3<f32>,
20        Dir,
21        f32,
22        Vec3<f32>,
23    );
24    type Skeleton = CharacterSkeleton;
25
26    #[cfg(feature = "use-dyn-lib")]
27    const UPDATE_FN: &'static [u8] = b"character_stand\0";
28
29    #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "character_stand"))]
30    fn update_skeleton_inner(
31        skeleton: &Self::Skeleton,
32        (
33            active_tool_kind,
34            second_tool_kind,
35            hands,
36            orientation,
37            last_ori,
38            look_dir,
39            global_time,
40            avg_vel,
41        ): Self::Dependency<'_>,
42        anim_time: f32,
43        _rate: &mut f32,
44        s_a: &SkeletonAttr,
45    ) -> Self::Skeleton {
46        let mut next = (*skeleton).clone();
47
48        let slow = (anim_time * 1.0).sin();
49        let impact = (avg_vel.z).max(-15.0);
50        let ori: Vec2<f32> = Vec2::from(orientation);
51        let tilt = if vek::Vec2::new(ori, last_ori.xy())
52            .map(|o| o.magnitude_squared())
53            .map(|m| m > 0.001 && m.is_finite())
54            .reduce_and()
55            && ori.angle_between(last_ori.xy()).is_finite()
56        {
57            ori.angle_between(last_ori.xy()).min(0.2)
58                * last_ori.xy().determine_side(Vec2::zero(), ori).signum()
59        } else {
60            0.0
61        } * 1.3;
62        let head_look = Vec2::new(
63            ((global_time + anim_time) / 10.0).floor().mul(7331.0).sin() * 0.15,
64            ((global_time + anim_time) / 10.0).floor().mul(1337.0).sin() * 0.07,
65        );
66        next.head.scale = Vec3::one() * s_a.head_scale;
67        next.chest.scale = Vec3::one() * 1.01;
68        next.hand_l.scale = Vec3::one() * 1.04;
69        next.hand_r.scale = Vec3::one() * 1.04;
70        next.back.scale = Vec3::one() * 1.02;
71        next.hold.scale = Vec3::one() * 0.0;
72        next.lantern.scale = Vec3::one() * 0.65;
73        next.shoulder_l.scale = Vec3::one() * 1.1;
74        next.shoulder_r.scale = Vec3::one() * 1.1;
75
76        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + slow * 0.3);
77        next.head.orientation = Quaternion::rotation_z(head_look.x)
78            * Quaternion::rotation_x(impact * -0.02 + head_look.y.abs());
79
80        next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + slow * 0.3 + impact * 0.2);
81        next.chest.orientation =
82            Quaternion::rotation_z(head_look.x * 0.6) * Quaternion::rotation_x(impact * 0.04);
83
84        next.belt.position = Vec3::new(0.0, s_a.belt.0 + impact * 0.005, s_a.belt.1);
85        next.belt.orientation =
86            Quaternion::rotation_z(head_look.x * -0.1) * Quaternion::rotation_x(impact * -0.03);
87
88        next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
89
90        next.shorts.position = Vec3::new(0.0, s_a.shorts.0 + impact * -0.2, s_a.shorts.1);
91        next.shorts.orientation =
92            Quaternion::rotation_z(head_look.x * -0.2) * Quaternion::rotation_x(impact * -0.04);
93
94        next.hand_l.position = Vec3::new(
95            -s_a.hand.0,
96            s_a.hand.1 + slow * 0.15 - impact * 0.2,
97            s_a.hand.2 + slow * 0.5 + impact * -0.1,
98        );
99
100        next.hand_l.orientation = Quaternion::rotation_x(slow * -0.06 + impact * -0.1);
101
102        next.hand_r.position = Vec3::new(
103            s_a.hand.0,
104            s_a.hand.1 + slow * 0.15 - impact * 0.2,
105            s_a.hand.2 + slow * 0.5 + impact * -0.1,
106        );
107        next.hand_r.orientation = Quaternion::rotation_x(slow * -0.06 + impact * -0.1);
108
109        next.foot_l.position = Vec3::new(-s_a.foot.0, s_a.foot.1 - impact * 0.15, s_a.foot.2);
110        next.foot_l.orientation = Quaternion::rotation_x(impact * 0.02);
111
112        next.foot_r.position = Vec3::new(s_a.foot.0, s_a.foot.1 + impact * 0.15, s_a.foot.2);
113        next.foot_r.orientation = Quaternion::rotation_x(impact * -0.02);
114
115        next.shoulder_l.position = Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
116
117        next.shoulder_r.position = Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
118
119        next.glider.position = Vec3::new(0.0, 0.0, 10.0);
120        next.glider.scale = Vec3::one() * 0.0;
121        next.hold.position = Vec3::new(0.4, -0.3, -5.8);
122
123        next.do_tools_on_back(hands, active_tool_kind, second_tool_kind);
124
125        next.do_hold_lantern(
126            s_a,
127            anim_time,
128            0.0,
129            0.0,
130            impact,
131            tilt,
132            Some(last_ori),
133            Some(*look_dir),
134        );
135
136        next.torso.position = Vec3::new(0.0, 0.0, 0.0);
137
138        if let (None, Some(Hands::Two)) = hands {
139            next.second = next.main;
140        }
141
142        next
143    }
144}