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(
29        feature = "be-dyn-lib",
30        unsafe(export_name = "biped_small_spritesummon")
31    )]
32    fn update_skeleton_inner(
33        skeleton: &Self::Skeleton,
34        (
35            active_tool_kind,
36            _velocity,
37            _orientation,
38            _last_ori,
39            global_time,
40            _avg_vel,
41            _acc_vel,
42            stage_section,
43            timer,
44        ): Self::Dependency<'_>,
45        anim_time: f32,
46        _rate: &mut f32,
47        s_a: &SkeletonAttr,
48    ) -> Self::Skeleton {
49        let mut next = (*skeleton).clone();
50
51        let anim_time = anim_time.min(1.0);
52        let (move1base, twitch, move2base, move3) = match stage_section {
53            Some(StageSection::Buildup) => (anim_time.sqrt(), (anim_time * 13.0).sin(), 0.0, 0.0),
54            Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(4), 0.0),
55            Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time),
56            _ => (0.0, 0.0, 0.0, 0.0),
57        };
58        let pullback = 1.0 - move3;
59        let twitch = twitch * pullback;
60        let subtract = global_time - timer;
61        let check = subtract - subtract.trunc();
62        let mirror = (check - 0.5).signum();
63        let move1 = move1base * pullback * mirror;
64        let move2 = move2base * pullback * mirror;
65        let move1abs = move1base * pullback;
66        let move2abs = move2base * pullback;
67        next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
68        next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
69        next.main.orientation = Quaternion::rotation_x(0.0);
70        next.hand_l.orientation = Quaternion::rotation_x(0.0);
71        next.hand_r.orientation = Quaternion::rotation_x(0.0);
72        match active_tool_kind {
73            Some(ToolKind::Natural) => {
74                next.head.orientation =
75                    Quaternion::rotation_x(move1abs * 0.5) * Quaternion::rotation_y(twitch * 0.5);
76                next.chest.orientation = Quaternion::rotation_x(move1abs * 0.5 + move2abs * -1.0)
77                    * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
78                next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
79                next.hand_l.orientation = Quaternion::rotation_x(1.2);
80                next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
81                next.hand_r.orientation = Quaternion::rotation_x(1.2);
82                next.main.position = Vec3::new(0.0, 10.0 + 5.0 * move1abs, 4.0 + 4.0 * move1abs);
83            },
84            _ => {},
85        }
86        next
87    }
88}