veloren_voxygen_anim/biped_large/
rapidmelee.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedLargeSkeleton, SkeletonAttr,
4};
5use common::{comp::item::ToolKind, states::utils::StageSection};
6use core::f32::consts::{PI, TAU};
7
8pub struct RapidMeleeAnimation;
9
10impl Animation for RapidMeleeAnimation {
11    type Dependency<'a> = (
12        Option<ToolKind>,
13        Option<ToolKind>,
14        Vec3<f32>,
15        f32,
16        Option<StageSection>,
17        f32,
18        Option<&'a str>,
19    );
20    type Skeleton = BipedLargeSkeleton;
21
22    #[cfg(feature = "use-dyn-lib")]
23    const UPDATE_FN: &'static [u8] = b"biped_large_rapidmelee\0";
24
25    #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "biped_large_rapidmelee"))]
26    fn update_skeleton_inner(
27        skeleton: &Self::Skeleton,
28        (
29            active_tool_kind,
30            _second_tool_kind,
31            velocity,
32            _global_time,
33            stage_section,
34            acc_vel,
35            _ability_id,
36        ): Self::Dependency<'_>,
37        anim_time: f32,
38        rate: &mut f32,
39        s_a: &SkeletonAttr,
40    ) -> Self::Skeleton {
41        *rate = 1.0;
42        let mut next = (*skeleton).clone();
43
44        let speed = Vec2::<f32>::from(velocity).magnitude();
45
46        let lab: f32 = 0.65 * s_a.tempo;
47        let speednorm = (speed / 12.0).powf(0.4);
48        let foothoril = (acc_vel * lab + PI * 1.45).sin() * speednorm;
49        let foothorir = (acc_vel * lab + PI * (0.45)).sin() * speednorm;
50        let footrotl = ((1.0 / (0.5 + (0.5) * ((acc_vel * lab + PI * 1.4).sin()).powi(2))).sqrt())
51            * ((acc_vel * lab + PI * 1.4).sin());
52
53        let footrotr = ((1.0 / (0.5 + (0.5) * ((acc_vel * lab + PI * 0.4).sin()).powi(2))).sqrt())
54            * ((acc_vel * lab + PI * 0.4).sin());
55
56        let (move1base, move2, move3) = match stage_section {
57            Some(StageSection::Buildup) => ((anim_time.powf(0.25)), 0.0, 0.0),
58            Some(StageSection::Action) => (1.0, (anim_time * 0.05).sin() - 0.05, 0.0),
59            Some(StageSection::Recover) => (1.0, 0.0, anim_time),
60            _ => (0.0, 0.0, 0.0),
61        };
62        let pullback = 1.0 - move3;
63        let move1 = move1base * pullback;
64
65        next.shoulder_l.position = Vec3::new(
66            -s_a.shoulder.0,
67            s_a.shoulder.1,
68            s_a.shoulder.2 - foothorir * 1.0,
69        );
70        next.shoulder_l.orientation =
71            Quaternion::rotation_x(move1 * 0.8 + 0.6 * speednorm + (footrotr * -0.2) * speednorm);
72
73        next.shoulder_r.position = Vec3::new(
74            s_a.shoulder.0,
75            s_a.shoulder.1,
76            s_a.shoulder.2 - foothoril * 1.0,
77        );
78        next.shoulder_r.orientation =
79            Quaternion::rotation_x(move1 * 0.8 + 0.6 * speednorm + (footrotl * -0.2) * speednorm);
80        next.torso.orientation = Quaternion::rotation_z(0.0);
81
82        next.main.position = Vec3::new(0.0, 0.0, 0.0);
83        next.main.orientation = Quaternion::rotation_x(0.0);
84
85        next.hand_l.position = Vec3::new(s_a.grip.1, 0.0, s_a.grip.0);
86        next.hand_r.position = Vec3::new(-s_a.grip.1, 0.0, s_a.grip.0);
87
88        next.hand_l.orientation = Quaternion::rotation_x(0.0);
89        next.hand_r.orientation = Quaternion::rotation_x(0.0);
90
91        match active_tool_kind {
92            Some(ToolKind::Staff) => {
93                next.head.orientation = Quaternion::rotation_x(move1 * -0.3 + move2 * 0.5);
94                next.control_l.position = Vec3::new(
95                    -1.0 + move1 * -10.0 + move2 * -10.0,
96                    3.0,
97                    12.0 + move1 * 7.0,
98                );
99                next.control_r.position = Vec3::new(
100                    1.0 + move1 * 10.0 + move2 * -10.0,
101                    2.0 + move1 * -0.0,
102                    2.0 + move1 * 15.0,
103                );
104
105                next.control.position = Vec3::new(
106                    -3.0 + move1 * 3.0,
107                    3.0 + s_a.grip.0 / 1.2 + move1 * 18.0,
108                    -11.0 + -s_a.grip.0 / 2.0 + move1 * 8.0,
109                );
110
111                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 - move1 * 0.2)
112                    * Quaternion::rotation_y(-0.5 + move1 * 0.3)
113                    * Quaternion::rotation_z(move1 * 0.0);
114                next.control_r.orientation = Quaternion::rotation_x(PI / 2.5 + move1 * 0.0)
115                    * Quaternion::rotation_y(0.5 + move1 * -0.3)
116                    * Quaternion::rotation_z(move2 * 1.0);
117
118                next.control.orientation = Quaternion::rotation_x(-0.2 + move1 * 0.8)
119                    * Quaternion::rotation_y(-0.1 + move1 * 0.1 + move2 * 1.0);
120
121                next.upper_torso.orientation = Quaternion::rotation_x(move1 * -0.5);
122
123                next.lower_torso.orientation = Quaternion::rotation_x(move1 * 0.8);
124                next.torso.position = Vec3::new(0.0, 0.0, move1 * 6.4);
125            },
126            Some(ToolKind::Axe) => {
127                let (move1base, move2, move3) = match stage_section {
128                    Some(StageSection::Buildup) => ((anim_time.powf(0.25)), 0.0, 0.0),
129                    Some(StageSection::Action) => (1.0, (anim_time), 0.0),
130                    Some(StageSection::Recover) => (1.0, 1.0, anim_time),
131                    _ => (0.0, 0.0, 0.0),
132                };
133                let pullback = 1.0 - move3;
134                let move1 = move1base * pullback;
135                let move2ret = move2 * pullback;
136
137                next.shoulder_r.orientation =
138                    Quaternion::rotation_y(move1 * 0.5) * Quaternion::rotation_x(move1 * 0.5);
139                next.head.orientation = Quaternion::rotation_x(move2ret * 0.7)
140                    * Quaternion::rotation_y(move1 * 0.3)
141                    * Quaternion::rotation_z(move1 * -0.2 - move2ret * 0.5);
142
143                next.main.position = Vec3::new(0.0, 0.0, 0.0);
144                next.main.orientation = Quaternion::rotation_x(0.0);
145
146                next.hand_l.position = Vec3::new(s_a.grip.1, 0.0, s_a.grip.0);
147                next.hand_r.position = Vec3::new(-s_a.grip.1, 0.0, s_a.grip.0);
148
149                next.hand_l.orientation = Quaternion::rotation_x(0.0);
150                next.hand_r.orientation = Quaternion::rotation_x(0.0);
151
152                next.control_l.position = Vec3::new(-1.0, 2.0, 12.0);
153                next.control_r.position = Vec3::new(1.0, 2.0, -2.0);
154
155                next.control.position = Vec3::new(
156                    4.0 + move1 * -25.0,
157                    0.0 + s_a.grip.0 / 1.0 + move1 * -TAU,
158                    -s_a.grip.0 / 0.8 + move1 * 10.0,
159                );
160
161                next.control_l.orientation =
162                    Quaternion::rotation_x(PI / 2.0 + move1 * 0.3) * Quaternion::rotation_y(-0.0);
163                next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + 0.2)
164                    * Quaternion::rotation_y(0.0)
165                    * Quaternion::rotation_z(0.0);
166                next.control.orientation = Quaternion::rotation_x(-1.0 + move1 * -1.2)
167                    * Quaternion::rotation_y(-1.8 + move1 * -1.0)
168                    * Quaternion::rotation_z(0.0 + move1 * -1.5);
169                next.upper_torso.orientation = Quaternion::rotation_y(move1 * -0.4);
170
171                next.lower_torso.orientation = Quaternion::rotation_y(move1 * 0.5);
172                next.torso.position = Vec3::new(move1 * -2.0, 0.0, 0.0);
173
174                next.leg_l.orientation = Quaternion::rotation_x(0.0);
175                next.leg_r.orientation = Quaternion::rotation_x(move1 * -0.5);
176                next.foot_r.orientation =
177                    Quaternion::rotation_x(move1 * -0.5) * Quaternion::rotation_y(move1 * -0.2);
178                next.foot_r.position = Vec3::new(s_a.foot.0, s_a.foot.1 + move1 * -3.0, s_a.foot.2);
179                next.torso.orientation = Quaternion::rotation_z(move2 * -TAU);
180            },
181            _ => {},
182        }
183
184        next
185    }
186}