veloren_voxygen_anim/golem/
shoot.rs

1use super::{
2    super::{Animation, vek::*},
3    GolemSkeleton, SkeletonAttr,
4};
5use common::{states::utils::StageSection, util::Dir};
6use core::f32::consts::PI;
7
8pub struct ShootAnimation;
9
10impl Animation for ShootAnimation {
11    type Dependency<'a> = (Option<StageSection>, f32, f32, Dir, Option<&'a str>);
12    type Skeleton = GolemSkeleton;
13
14    #[cfg(feature = "use-dyn-lib")]
15    const UPDATE_FN: &'static [u8] = b"golem_shoot\0";
16
17    #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "golem_shoot"))]
18    fn update_skeleton_inner(
19        skeleton: &Self::Skeleton,
20        (stage_section, _global_time, _timer, look_dir, ability_id): Self::Dependency<'_>,
21        anim_time: f32,
22        _rate: &mut f32,
23        _s_a: &SkeletonAttr,
24    ) -> Self::Skeleton {
25        let mut next = (*skeleton).clone();
26
27        let (move1base, move2base, move3) = match stage_section {
28            Some(StageSection::Buildup) => (anim_time.powf(0.4), 0.0, 0.0),
29            Some(StageSection::Action) => (1.0, anim_time, 0.0),
30            Some(StageSection::Recover) => (1.0, 1.0, anim_time.powf(4.0)),
31            _ => (0.0, 0.0, 0.0),
32        };
33
34        // AncientEffigy shrink
35        if let Some("common.abilities.custom.ancienteffigy.blast") = ability_id {
36            next.upper_torso.scale = Vec3::one() * (1.0 - move1base);
37        }
38
39        let pullback = 1.0 - move3;
40
41        let move1 = move1base * pullback;
42        let move2 = move2base * pullback;
43
44        next.head.orientation = Quaternion::rotation_x(-0.2) * Quaternion::rotation_z(move1 * -0.5);
45
46        next.upper_torso.orientation =
47            Quaternion::rotation_x(0.0) * Quaternion::rotation_z(move1 * 0.5);
48
49        next.lower_torso.orientation =
50            Quaternion::rotation_z(move1 * -0.5) * Quaternion::rotation_x(0.0);
51
52        next.shoulder_l.orientation =
53            Quaternion::rotation_y(0.0) * Quaternion::rotation_z(move1 * 0.7);
54
55        next.shoulder_r.orientation = Quaternion::rotation_x(move1 * (look_dir.z * 1.2 + PI / 2.0))
56            * Quaternion::rotation_y(move1 * 0.0);
57
58        next.hand_l.orientation =
59            Quaternion::rotation_z(move1 * -0.3) * Quaternion::rotation_x(move1 * 1.3);
60
61        next.hand_r.orientation = Quaternion::rotation_y(move1 * -0.3)
62            * Quaternion::rotation_z(move1 * -0.9 + move2 * -1.6);
63
64        next.torso.position = Vec3::new(0.0, 0.0, 0.0);
65        next
66    }
67}