veloren_voxygen_anim/golem/
beam.rs

1use super::{
2    super::{Animation, vek::*},
3    GolemSkeleton, SkeletonAttr,
4};
5use common::{states::utils::StageSection, util::Dir};
6pub struct BeamAnimation;
7
8impl Animation for BeamAnimation {
9    type Dependency<'a> = (Option<StageSection>, f32, f32, Dir, Option<&'a str>);
10    type Skeleton = GolemSkeleton;
11
12    #[cfg(feature = "use-dyn-lib")]
13    const UPDATE_FN: &'static [u8] = b"golem_beam\0";
14
15    #[cfg_attr(feature = "be-dyn-lib", export_name = "golem_beam")]
16
17    fn update_skeleton_inner(
18        skeleton: &Self::Skeleton,
19        (stage_section, _global_time, _timer, look_dir, ability_id): Self::Dependency<'_>,
20        anim_time: f32,
21        _rate: &mut f32,
22        s_a: &SkeletonAttr,
23    ) -> Self::Skeleton {
24        let mut next = (*skeleton).clone();
25
26        let (move1base, move1iso, move2base, move3) = match stage_section {
27            Some(StageSection::Buildup) => (anim_time.powf(0.25), anim_time.powf(0.25), 0.0, 0.0),
28            Some(StageSection::Action) => (1.0, 0.0, 1.0, 0.0),
29            Some(StageSection::Recover) => (1.0, 0.0, 1.0, anim_time.powf(4.0)),
30            _ => (0.0, 0.0, 0.0, 0.0),
31        };
32
33        let pullback = 1.0 - move3;
34        let move1 = move1base * pullback;
35        let move2 = move2base * pullback;
36
37        match ability_id {
38            Some("common.abilities.custom.mogwai.breathe") => {
39                next.jaw.orientation = Quaternion::rotation_x(-0.3 * move1);
40            },
41            _ => {
42                next.head.orientation =
43                    Quaternion::rotation_x(move1iso * 0.5 + move2 * (look_dir.z * 1.0));
44                next.head.position = Vec3::new(
45                    0.0,
46                    s_a.head.0,
47                    s_a.head.1 - move2 * 5.0 * (look_dir.z * 1.0).min(0.0),
48                );
49
50                next.upper_torso.orientation =
51                    Quaternion::rotation_x(move1iso * 0.3) * Quaternion::rotation_z(0.0);
52
53                next.lower_torso.orientation =
54                    Quaternion::rotation_z(0.0) * Quaternion::rotation_x(move1iso * -0.3);
55
56                next.shoulder_l.orientation =
57                    Quaternion::rotation_x(move1 * 0.8) * Quaternion::rotation_y(move1 * -0.5);
58
59                next.shoulder_r.orientation =
60                    Quaternion::rotation_x(move1 * 0.8) * Quaternion::rotation_y(move1 * 0.5);
61                next.shoulder_l.position = Vec3::new(
62                    -s_a.shoulder.0,
63                    s_a.shoulder.1 + move1 * 2.0,
64                    s_a.shoulder.2 + move1 * -2.0,
65                );
66                next.shoulder_r.position = Vec3::new(
67                    s_a.shoulder.0,
68                    s_a.shoulder.1 + move1 * 2.0,
69                    s_a.shoulder.2 + move1 * -2.0,
70                );
71
72                next.hand_l.orientation =
73                    Quaternion::rotation_z(0.0) * Quaternion::rotation_y(move1 * -1.1);
74
75                next.hand_r.orientation =
76                    Quaternion::rotation_y(0.0) * Quaternion::rotation_y(move1 * 1.1);
77
78                next.torso.position = Vec3::new(0.0, 0.0, 0.0);
79            },
80        }
81        next
82    }
83}