veloren_voxygen_anim/biped_small/
block.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedSmallSkeleton, SkeletonAttr, biped_small_wield_sword, init_biped_small_alpha,
4};
5use common::states::utils::StageSection;
6
7pub struct BlockAnimation;
8
9type BlockAnimationDependency<'a> = (Option<&'a str>, StageSection);
10
11impl Animation for BlockAnimation {
12    type Dependency<'a> = BlockAnimationDependency<'a>;
13    type Skeleton = BipedSmallSkeleton;
14
15    #[cfg(feature = "use-dyn-lib")]
16    const UPDATE_FN: &'static [u8] = b"biped_small_block\0";
17
18    #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_small_block")]
19    fn update_skeleton_inner(
20        skeleton: &Self::Skeleton,
21        (ability_id, stage_section): Self::Dependency<'_>,
22        anim_time: f32,
23        rate: &mut f32,
24        s_a: &SkeletonAttr,
25    ) -> Self::Skeleton {
26        *rate = 1.0;
27        let mut next = (*skeleton).clone();
28
29        init_biped_small_alpha(&mut next, s_a);
30
31        match ability_id {
32            Some("common.abilities.haniwa.soldier.guard") => {
33                let slow = (anim_time * 2.0).sin();
34                biped_small_wield_sword(&mut next, s_a, 0.0, slow);
35
36                let (move1, move2, move3) = match stage_section {
37                    StageSection::Buildup => (anim_time, 0.0, 0.0),
38                    StageSection::Action => (1.0, anim_time, 0.0),
39                    StageSection::Recover => (1.0, 1.0, anim_time),
40                    _ => (0.0, 0.0, 0.0),
41                };
42                let pullback = 1.0 - move3;
43                let move1 = move1 * pullback;
44                let _move2 = move2 * pullback;
45
46                next.detach_right = true;
47                // For some reason there's a discontinuity when using detach_right, two offsets
48                // below seem to help
49                next.control_r.position += next.control.position
50                    + Vec3::new(0.0, -2.0, 1.0)
51                    + Vec3::new(2.0 * move3, -1.0 * move3, 2.0 * move3);
52                next.control_r.orientation = next.control.orientation * next.control_r.orientation;
53
54                next.control.orientation.rotate_x(move1 * -0.7);
55                next.control.orientation.rotate_z(move1 * -1.4);
56                next.control_r.orientation.rotate_x(move1 * 1.2);
57                next.control_r.position += Vec3::new(0.0, 5.0 * move1, 6.0 * move1);
58            },
59            _ => {},
60        }
61
62        next
63    }
64}