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", export_name = "golem_shockwave")]
18
19    fn update_skeleton_inner(
20        skeleton: &Self::Skeleton,
21        (stage_section, velocity, _global_time): Self::Dependency<'_>,
22        anim_time: f32,
23        _rate: &mut f32,
24        s_a: &SkeletonAttr,
25    ) -> Self::Skeleton {
26        let mut next = (*skeleton).clone();
27
28        let (move1base, move2base, move3) = match stage_section {
29            Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
30            Some(StageSection::Action) => (1.0, anim_time, 0.0),
31            Some(StageSection::Recover) => (1.0, 1.0, anim_time.powf(2.0)),
32            _ => (0.0, 0.0, 0.0),
33        };
34
35        let pullback = 1.0 - move3;
36        let move1 = move1base * pullback;
37        let move2 = move2base * pullback;
38
39        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1) * 1.02;
40        next.head.orientation = Quaternion::rotation_z(move1 * -PI);
41
42        next.upper_torso.position =
43            Vec3::new(0.0, s_a.upper_torso.0, s_a.upper_torso.1 + move2 * -5.0);
44        next.upper_torso.orientation = Quaternion::rotation_z(move1 * -PI);
45
46        next.lower_torso.position =
47            Vec3::new(0.0, s_a.lower_torso.0, s_a.lower_torso.1 + move2 * 2.0);
48        next.lower_torso.orientation = Quaternion::rotation_z(move1 * PI);
49
50        next.shoulder_l.position = Vec3::new(
51            -s_a.shoulder.0 - 2.0,
52            s_a.shoulder.1,
53            s_a.shoulder.2 + move2 * -1.0,
54        );
55        next.shoulder_l.orientation = Quaternion::rotation_y(move1 * 1.0 + move2 * -1.2);
56
57        next.shoulder_r.position = Vec3::new(
58            s_a.shoulder.0 + 2.0,
59            s_a.shoulder.1,
60            s_a.shoulder.2 + move2 * -1.0,
61        );
62        next.shoulder_r.orientation = Quaternion::rotation_y(move1 * -1.0 + move2 * 1.2);
63
64        next.hand_l.orientation = Quaternion::rotation_y(move1 * -1.0 + move2 * 1.2);
65
66        next.hand_r.orientation =
67            Quaternion::rotation_z(0.0) * Quaternion::rotation_y(move1 * 1.0 + move2 * -1.2);
68        if velocity < 0.5 {
69            next.leg_l.position = Vec3::new(-s_a.leg.0, s_a.leg.1, s_a.leg.2 + move2 * 2.0) * 1.02;
70
71            next.leg_r.position = Vec3::new(s_a.leg.0, s_a.leg.1, s_a.leg.2 + move2 * 2.0) * 1.02;
72
73            next.foot_l.position = Vec3::new(-s_a.foot.0, s_a.foot.1, s_a.foot.2 + move2);
74
75            next.foot_r.position = Vec3::new(s_a.foot.0, s_a.foot.1, s_a.foot.2 + move2);
76        }
77        next
78    }
79}