veloren_voxygen_anim/character/
collect.rs

1use super::{
2    super::{Animation, vek::*},
3    CharacterSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6use std::f32::consts::PI;
7
8pub struct CollectAnimation;
9
10impl Animation for CollectAnimation {
11    type Dependency<'a> = (Vec3<f32>, f32, Option<StageSection>, Vec3<f32>, bool);
12    type Skeleton = CharacterSkeleton;
13
14    #[cfg(feature = "use-dyn-lib")]
15    const UPDATE_FN: &'static [u8] = b"character_collect\0";
16
17    #[cfg_attr(feature = "be-dyn-lib", export_name = "character_collect")]
18    fn update_skeleton_inner(
19        skeleton: &Self::Skeleton,
20        (position, _global_time, stage_section, sprite_pos, is_riding): Self::Dependency<'_>,
21        anim_time: f32,
22        rate: &mut f32,
23        s_a: &SkeletonAttr,
24    ) -> Self::Skeleton {
25        *rate = 1.0;
26        let mut next = (*skeleton).clone();
27
28        let (movement1, move2, move2alt, move3) = match stage_section {
29            Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0, 0.0),
30            Some(StageSection::Action) => (
31                1.0,
32                (anim_time * 12.0).sin(),
33                (anim_time * 9.0 + PI / 2.0).sin(),
34                0.0,
35            ),
36            Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time.powi(4)),
37            _ => (0.0, 0.0, 0.0, 0.0),
38        };
39        let z_diff = (sprite_pos.z - position.z).round();
40        let z_diff = if z_diff > 0.0 { z_diff / 9.0 } else { 0.0 };
41        let squat = (1.0 - z_diff).powf(4.0);
42
43        let pullback = 1.0 - move3;
44
45        let move1 = movement1 * pullback * squat;
46        let move1_nosquat = movement1 * pullback;
47        let upshift = if squat < 0.35 {
48            move1_nosquat * 0.3
49        } else {
50            0.0
51        };
52        next.head.orientation = Quaternion::rotation_x(move1_nosquat * 0.2 + upshift * 1.3);
53
54        next.chest.position = Vec3::new(
55            0.0,
56            s_a.chest.0 + upshift * 3.0,
57            s_a.chest.1 + move2 * 0.15 + upshift * 3.0,
58        );
59        next.chest.orientation = Quaternion::rotation_x(move1 * -1.0 + move2alt * 0.015);
60
61        next.belt.position = Vec3::new(0.0, s_a.belt.0 + move1 * 1.0, s_a.belt.1 + move1 * -0.0);
62        next.belt.orientation = Quaternion::rotation_x(move1 * 0.2);
63
64        next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
65
66        next.shorts.position =
67            Vec3::new(0.0, s_a.shorts.0 + move1 * 2.0, s_a.shorts.1 + move1 * -0.0);
68        next.shorts.orientation = Quaternion::rotation_x(move1 * 0.3);
69
70        next.hand_l.position = Vec3::new(
71            -s_a.hand.0 + move1_nosquat * 4.0 - move2alt * 1.0,
72            s_a.hand.1 + move1_nosquat * 8.0 + move2 * 1.0 + upshift * -5.0,
73            s_a.hand.2 + move1_nosquat * 5.0 + upshift * 15.0,
74        );
75
76        next.hand_l.orientation = Quaternion::rotation_x(move1_nosquat * 1.9 + upshift * 2.0)
77            * Quaternion::rotation_y(move1_nosquat * -0.3 + move2alt * -0.2);
78
79        next.hand_r.position = Vec3::new(
80            s_a.hand.0 + move1_nosquat * -4.0 - move2 * 1.0,
81            s_a.hand.1 + move1_nosquat * 8.0 + move2alt * -1.0 + upshift * -5.0,
82            s_a.hand.2 + move1_nosquat * 5.0 + upshift * 15.0,
83        );
84        next.hand_r.orientation = Quaternion::rotation_x(move1_nosquat * 1.9 + upshift * 2.0)
85            * Quaternion::rotation_y(move1_nosquat * 0.3 + move2 * 0.3);
86
87        if !is_riding {
88            next.foot_l.position = Vec3::new(
89                -s_a.foot.0,
90                s_a.foot.1 + move1 * 2.0 + upshift * -3.5,
91                s_a.foot.2 + upshift * 2.0,
92            );
93            next.foot_l.orientation = Quaternion::rotation_x(move1 * -0.2 + upshift * -2.2);
94
95            next.foot_r.position = Vec3::new(
96                s_a.foot.0,
97                s_a.foot.1 + move1 * -4.0 + upshift * -0.5,
98                s_a.foot.2 + upshift * 2.0,
99            );
100            next.foot_r.orientation = Quaternion::rotation_x(move1 * -0.8 + upshift * -1.2);
101        }
102        next
103    }
104}