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", unsafe(export_name = "golem_beam"))]
16    fn update_skeleton_inner(
17        skeleton: &Self::Skeleton,
18        (stage_section, _global_time, _timer, look_dir, ability_id): Self::Dependency<'_>,
19        anim_time: f32,
20        _rate: &mut f32,
21        s_a: &SkeletonAttr,
22    ) -> Self::Skeleton {
23        let mut next = (*skeleton).clone();
24
25        let (move1base, move1iso, move2base, move3) = match stage_section {
26            Some(StageSection::Buildup) => (anim_time.powf(0.25), anim_time.powf(0.25), 0.0, 0.0),
27            Some(StageSection::Action) => (1.0, 0.0, 1.0, 0.0),
28            Some(StageSection::Recover) => (1.0, 0.0, 1.0, anim_time.powf(4.0)),
29            _ => (0.0, 0.0, 0.0, 0.0),
30        };
31
32        let pullback = 1.0 - move3;
33        let move1 = move1base * pullback;
34        let move2 = move2base * pullback;
35
36        match ability_id {
37            Some("common.abilities.custom.mogwai.breathe") => {
38                next.jaw.orientation = Quaternion::rotation_x(-0.3 * move1);
39            },
40            _ => {
41                next.head.orientation =
42                    Quaternion::rotation_x(move1iso * 0.5 + move2 * (look_dir.z * 1.0));
43                next.head.position = Vec3::new(
44                    0.0,
45                    s_a.head.0,
46                    s_a.head.1 - move2 * 5.0 * (look_dir.z * 1.0).min(0.0),
47                );
48
49                next.upper_torso.orientation =
50                    Quaternion::rotation_x(move1iso * 0.3) * Quaternion::rotation_z(0.0);
51
52                next.lower_torso.orientation =
53                    Quaternion::rotation_z(0.0) * Quaternion::rotation_x(move1iso * -0.3);
54
55                next.shoulder_l.orientation =
56                    Quaternion::rotation_x(move1 * 0.8) * Quaternion::rotation_y(move1 * -0.5);
57
58                next.shoulder_r.orientation =
59                    Quaternion::rotation_x(move1 * 0.8) * Quaternion::rotation_y(move1 * 0.5);
60                next.shoulder_l.position = Vec3::new(
61                    -s_a.shoulder.0,
62                    s_a.shoulder.1 + move1 * 2.0,
63                    s_a.shoulder.2 + move1 * -2.0,
64                );
65                next.shoulder_r.position = Vec3::new(
66                    s_a.shoulder.0,
67                    s_a.shoulder.1 + move1 * 2.0,
68                    s_a.shoulder.2 + move1 * -2.0,
69                );
70
71                next.hand_l.orientation =
72                    Quaternion::rotation_z(0.0) * Quaternion::rotation_y(move1 * -1.1);
73
74                next.hand_r.orientation =
75                    Quaternion::rotation_y(0.0) * Quaternion::rotation_y(move1 * 1.1);
76
77                next.torso.position = Vec3::new(0.0, 0.0, 0.0);
78            },
79        }
80        next
81    }
82}