veloren_voxygen_anim/biped_small/
beam.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedSmallSkeleton, SkeletonAttr,
4};
5use common::{comp::item::ToolKind, states::utils::StageSection};
6use std::f32::consts::PI;
7
8pub struct BeamAnimation;
9
10type BeamAnimationDependency<'a> = (
11    Option<&'a str>,
12    Option<ToolKind>,
13    Vec3<f32>,
14    Vec3<f32>,
15    Vec3<f32>,
16    f32,
17    Vec3<f32>,
18    f32,
19    Option<StageSection>,
20    f32,
21);
22
23impl Animation for BeamAnimation {
24    type Dependency<'a> = BeamAnimationDependency<'a>;
25    type Skeleton = BipedSmallSkeleton;
26
27    #[cfg(feature = "use-dyn-lib")]
28    const UPDATE_FN: &'static [u8] = b"biped_small_beam\0";
29
30    #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "biped_small_beam"))]
31    fn update_skeleton_inner(
32        skeleton: &Self::Skeleton,
33        (
34            ability_id,
35            _active_tool_kind,
36            velocity,
37            _orientation,
38            _last_ori,
39            _global_time,
40            _avg_vel,
41            _acc_vel,
42            stage_section,
43            _timer,
44        ): Self::Dependency<'_>,
45        anim_time: f32,
46        _rate: &mut f32,
47        s_a: &SkeletonAttr,
48    ) -> Self::Skeleton {
49        let mut next = (*skeleton).clone();
50        let speed = Vec2::<f32>::from(velocity).magnitude();
51
52        let fast = (anim_time * 10.0).sin();
53        let fastalt = (anim_time * 10.0 + PI / 2.0).sin();
54
55        let speednorm = speed / 9.4;
56        let speednormcancel = 1.0 - speednorm;
57
58        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + fast * -0.1 * speednormcancel);
59        next.head.orientation = Quaternion::rotation_x(0.45 * speednorm)
60            * Quaternion::rotation_y(fast * 0.07 * speednormcancel);
61        next.chest.position = Vec3::new(
62            0.0,
63            s_a.chest.0,
64            s_a.chest.1 + fastalt * 0.4 * speednormcancel + speednormcancel * -0.5,
65        );
66
67        next.pants.position = Vec3::new(0.0, s_a.pants.0, s_a.pants.1);
68
69        next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
70        next.tail.orientation = Quaternion::rotation_x(0.05 * fastalt * speednormcancel)
71            * Quaternion::rotation_z(fast * 0.15 * speednormcancel);
72
73        next.main.position = Vec3::new(0.0, 0.0, 0.0);
74        next.main.orientation = Quaternion::rotation_x(0.0);
75
76        next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
77        next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
78
79        next.hand_l.orientation = Quaternion::rotation_x(0.0);
80        next.hand_r.orientation = Quaternion::rotation_x(0.0);
81
82        let (move1base, move2base, move3) = match stage_section {
83            Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0),
84            Some(StageSection::Action) => (1.0, (anim_time * 4.0).sin(), 0.0),
85            Some(StageSection::Recover) => (1.0, 1.0, anim_time),
86            _ => (0.0, 0.0, 0.0),
87        };
88        let pullback = 1.0 - move3;
89        let move1abs = move1base * pullback;
90
91        next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
92        next.control_r.position = Vec3::new(
93            7.0 + s_a.grip.0 * 2.0 + move1abs * -8.0,
94            -4.0 + move1abs * 0.0,
95            3.0 + move1abs * 10.0,
96        );
97        match ability_id {
98            Some("common.abilities.custom.dwarves.flamekeeper.flamethrower") => {
99                next.control.position = Vec3::new(
100                    -9.0,
101                    -1.0 + s_a.grip.2,
102                    -8.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + move1abs * 5.0,
103                );
104
105                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + move1abs * 0.8)
106                    * Quaternion::rotation_y(-0.3)
107                    * Quaternion::rotation_z(-0.3);
108                next.control_r.orientation =
109                    Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2 + move1abs * 0.8)
110                        * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2 + move1abs * 0.8)
111                        * Quaternion::rotation_z(-0.0 + move1abs * 2.0 + move2base * 0.6);
112
113                next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * -0.6)
114                    * Quaternion::rotation_y(-0.2 * speednorm + move1abs * 0.8)
115                    * Quaternion::rotation_z(0.5 + move1abs * 0.6);
116            },
117            _ => {
118                next.control.position = Vec3::new(
119                    -5.0,
120                    -1.0 + s_a.grip.2,
121                    -2.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + move1abs * 5.0,
122                );
123
124                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + move1abs * 0.8)
125                    * Quaternion::rotation_y(-0.3)
126                    * Quaternion::rotation_z(-0.3);
127                next.control_r.orientation =
128                    Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2 + move1abs * 0.8)
129                        * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2 + move1abs * 0.8)
130                        * Quaternion::rotation_z(-0.0 + move1abs * 2.0 + move2base * 0.6);
131
132                next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * -0.6)
133                    * Quaternion::rotation_y(-0.2 * speednorm + move1abs * 0.8)
134                    * Quaternion::rotation_z(0.5 + move1abs * 0.6);
135            },
136        }
137        next
138    }
139}