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