veloren_voxygen_anim/biped_small/
spritesummon.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedSmallSkeleton, SkeletonAttr,
4};
5use common::{comp::item::ToolKind, states::utils::StageSection};
6
7pub struct SpriteSummonAnimation;
8
9type SpriteSummonAnimationDependency = (
10    Option<ToolKind>,
11    Vec3<f32>,
12    Vec3<f32>,
13    Vec3<f32>,
14    f32,
15    Vec3<f32>,
16    f32,
17    Option<StageSection>,
18    f32,
19);
20
21impl Animation for SpriteSummonAnimation {
22    type Dependency<'a> = SpriteSummonAnimationDependency;
23    type Skeleton = BipedSmallSkeleton;
24
25    #[cfg(feature = "use-dyn-lib")]
26    const UPDATE_FN: &'static [u8] = b"biped_small_spritesummon\0";
27
28    #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_small_spritesummon")]
29
30    fn update_skeleton_inner(
31        skeleton: &Self::Skeleton,
32        (
33            active_tool_kind,
34            _velocity,
35            _orientation,
36            _last_ori,
37            global_time,
38            _avg_vel,
39            _acc_vel,
40            stage_section,
41            timer,
42        ): Self::Dependency<'_>,
43        anim_time: f32,
44        _rate: &mut f32,
45        s_a: &SkeletonAttr,
46    ) -> Self::Skeleton {
47        let mut next = (*skeleton).clone();
48
49        let anim_time = anim_time.min(1.0);
50        let (move1base, twitch, move2base, move3) = match stage_section {
51            Some(StageSection::Buildup) => (anim_time.sqrt(), (anim_time * 13.0).sin(), 0.0, 0.0),
52            Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(4), 0.0),
53            Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time),
54            _ => (0.0, 0.0, 0.0, 0.0),
55        };
56        let pullback = 1.0 - move3;
57        let twitch = twitch * pullback;
58        let subtract = global_time - timer;
59        let check = subtract - subtract.trunc();
60        let mirror = (check - 0.5).signum();
61        let move1 = move1base * pullback * mirror;
62        let move2 = move2base * pullback * mirror;
63        let move1abs = move1base * pullback;
64        let move2abs = move2base * pullback;
65        next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
66        next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
67        next.main.orientation = Quaternion::rotation_x(0.0);
68        next.hand_l.orientation = Quaternion::rotation_x(0.0);
69        next.hand_r.orientation = Quaternion::rotation_x(0.0);
70        match active_tool_kind {
71            Some(ToolKind::Natural) => {
72                next.head.orientation =
73                    Quaternion::rotation_x(move1abs * 0.5) * Quaternion::rotation_y(twitch * 0.5);
74                next.chest.orientation = Quaternion::rotation_x(move1abs * 0.5 + move2abs * -1.0)
75                    * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
76                next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
77                next.hand_l.orientation = Quaternion::rotation_x(1.2);
78                next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
79                next.hand_r.orientation = Quaternion::rotation_x(1.2);
80                next.main.position = Vec3::new(0.0, 10.0 + 5.0 * move1abs, 4.0 + 4.0 * move1abs);
81            },
82            _ => {},
83        }
84        next
85    }
86}