veloren_voxygen_anim/character/
stand.rs

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