veloren_voxygen_anim/golem/
shockwave.rs

1use super::{
2    super::{Animation, vek::*},
3    GolemSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6use std::f32::consts::PI;
7
8pub struct ShockwaveAnimation;
9
10impl Animation for ShockwaveAnimation {
11    type Dependency<'a> = (Option<StageSection>, f32, f32);
12    type Skeleton = GolemSkeleton;
13
14    #[cfg(feature = "use-dyn-lib")]
15    const UPDATE_FN: &'static [u8] = b"golem_shockwave\0";
16
17    #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "golem_shockwave"))]
18    fn update_skeleton_inner(
19        skeleton: &Self::Skeleton,
20        (stage_section, velocity, _global_time): 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, 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(2.0)),
31            _ => (0.0, 0.0, 0.0),
32        };
33
34        let pullback = 1.0 - move3;
35        let move1 = move1base * pullback;
36        let move2 = move2base * pullback;
37
38        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1) * 1.02;
39        next.head.orientation = Quaternion::rotation_z(move1 * -PI);
40
41        next.upper_torso.position =
42            Vec3::new(0.0, s_a.upper_torso.0, s_a.upper_torso.1 + move2 * -5.0);
43        next.upper_torso.orientation = Quaternion::rotation_z(move1 * -PI);
44
45        next.lower_torso.position =
46            Vec3::new(0.0, s_a.lower_torso.0, s_a.lower_torso.1 + move2 * 2.0);
47        next.lower_torso.orientation = Quaternion::rotation_z(move1 * PI);
48
49        next.shoulder_l.position = Vec3::new(
50            -s_a.shoulder.0 - 2.0,
51            s_a.shoulder.1,
52            s_a.shoulder.2 + move2 * -1.0,
53        );
54        next.shoulder_l.orientation = Quaternion::rotation_y(move1 * 1.0 + move2 * -1.2);
55
56        next.shoulder_r.position = Vec3::new(
57            s_a.shoulder.0 + 2.0,
58            s_a.shoulder.1,
59            s_a.shoulder.2 + move2 * -1.0,
60        );
61        next.shoulder_r.orientation = Quaternion::rotation_y(move1 * -1.0 + move2 * 1.2);
62
63        next.hand_l.orientation = Quaternion::rotation_y(move1 * -1.0 + move2 * 1.2);
64
65        next.hand_r.orientation =
66            Quaternion::rotation_z(0.0) * Quaternion::rotation_y(move1 * 1.0 + move2 * -1.2);
67        if velocity < 0.5 {
68            next.leg_l.position = Vec3::new(-s_a.leg.0, s_a.leg.1, s_a.leg.2 + move2 * 2.0) * 1.02;
69
70            next.leg_r.position = Vec3::new(s_a.leg.0, s_a.leg.1, s_a.leg.2 + move2 * 2.0) * 1.02;
71
72            next.foot_l.position = Vec3::new(-s_a.foot.0, s_a.foot.1, s_a.foot.2 + move2);
73
74            next.foot_r.position = Vec3::new(s_a.foot.0, s_a.foot.1, s_a.foot.2 + move2);
75        }
76        next
77    }
78}