veloren_voxygen_anim/biped_small/
shockwave.rs1use 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 ShockwaveAnimation;
9
10type ShockwaveAnimationDependency = (
11 Option<ToolKind>,
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 ShockwaveAnimation {
24 type Dependency<'a> = ShockwaveAnimationDependency;
25 type Skeleton = BipedSmallSkeleton;
26
27 #[cfg(feature = "use-dyn-lib")]
28 const UPDATE_FN: &'static [u8] = b"biped_small_shockwave\0";
29
30 #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "biped_small_shockwave"))]
31
32 fn update_skeleton_inner(
33 skeleton: &Self::Skeleton,
34 (
35 active_tool_kind,
36 second_tool_kind,
37 _velocity,
38 _orientation,
39 _last_ori,
40 global_time,
41 _avg_vel,
42 _acc_vel,
43 stage_section,
44 timer,
45 ): Self::Dependency<'_>,
46 anim_time: f32,
47 _rate: &mut f32,
48 s_a: &SkeletonAttr,
49 ) -> Self::Skeleton {
50 let mut next = (*skeleton).clone();
51
52 let anim_time = anim_time.min(1.0);
53 let (move1base, twitch, move2base, move3) = match stage_section {
54 Some(StageSection::Buildup) => (anim_time.sqrt(), (anim_time * 13.0).sin(), 0.0, 0.0),
55 Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(4), 0.0),
56 Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time),
57 _ => (0.0, 0.0, 0.0, 0.0),
58 };
59 let pullback = 1.0 - move3;
60 let twitch = twitch * pullback;
61 let subtract = global_time - timer;
62 let check = subtract - subtract.trunc();
63 let mirror = (check - 0.5).signum();
64 let move1 = move1base * pullback * mirror;
65 let move2 = move2base * pullback * mirror;
66 let move1abs = move1base * pullback;
67 let move2abs = move2base * pullback;
68 next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
69 next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
70 next.main.position = Vec3::new(0.0, 0.0, 0.0);
71 next.main.orientation = Quaternion::rotation_x(0.0);
72 next.second.position = Vec3::new(0.0, 0.0, 0.0);
73 next.second.orientation = Quaternion::rotation_x(0.0);
74 next.hand_l.orientation = Quaternion::rotation_x(0.0);
75 next.hand_r.orientation = Quaternion::rotation_x(0.0);
76 match (active_tool_kind, second_tool_kind) {
77 (Some(ToolKind::Staff), None) => {
78 next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
79 next.control_r.position = Vec3::new(
80 7.0 + s_a.grip.0 * 2.0 + move1abs * -8.0,
81 -4.0 + move1abs * 5.0,
82 3.0,
83 );
84
85 next.control.position = Vec3::new(
86 -5.0 + move1abs * 5.0,
87 -1.0 + s_a.grip.2 + move1abs * 3.0 + move2abs * 5.0,
88 -2.0 + -s_a.grip.2 / 2.5
89 + s_a.grip.0 * -2.0
90 + move1abs * 12.0
91 + move2abs * -13.0,
92 );
93
94 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
95 * Quaternion::rotation_y(-0.3)
96 * Quaternion::rotation_z(-0.3);
97 next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
98 * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2)
99 * Quaternion::rotation_z(-0.0);
100
101 next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * 0.2)
102 * Quaternion::rotation_y(0.0)
103 * Quaternion::rotation_z(0.5);
104 next.chest.orientation = Quaternion::rotation_x(move1abs * 0.5 + move2abs * -1.0);
105 next.head.orientation =
106 Quaternion::rotation_x(move1abs * 0.5) * Quaternion::rotation_y(twitch * 0.5);
107 next.main.orientation = Quaternion::rotation_z(move1abs * 0.5 + move2abs * 0.9);
108 },
109 (Some(ToolKind::Sword), None) => {
110 let rotate = move1 * 2.0 * PI + move2 * 2.0 * PI;
111 let jump = move1 + 3.0 + move2 * -3.0;
112 next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
113 next.control_r.position = Vec3::new(
114 7.0 + s_a.grip.0 * 2.0 + move1abs * -8.0,
115 -4.0 + move1abs * 5.0,
116 3.0,
117 );
118
119 next.control.position = Vec3::new(
120 -5.0 + move1abs * 5.0,
121 -1.0 + s_a.grip.2 + move1abs * 3.0 + move2abs * 5.0,
122 -2.0 + -s_a.grip.2 / 2.5
123 + s_a.grip.0 * -2.0
124 + move1abs * 12.0
125 + move2abs * -13.0,
126 );
127
128 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
129 * Quaternion::rotation_y(-0.3)
130 * Quaternion::rotation_z(-0.3);
131 next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
132 * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2)
133 * Quaternion::rotation_z(-0.0);
134
135 next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * 0.2)
136 * Quaternion::rotation_y(0.0)
137 * Quaternion::rotation_z(0.5);
138 next.chest.orientation = Quaternion::rotation_x(move1abs * 0.5 + move2abs * -1.0);
139 next.head.orientation =
140 Quaternion::rotation_x(move1abs * 0.5) * Quaternion::rotation_y(twitch * 0.5);
141 next.main.orientation = Quaternion::rotation_z(move1abs * 0.5 + move2abs * 0.9);
142 next.chest.orientation = Quaternion::rotation_z(rotate + (1.0 - move3));
143
144 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + jump);
145 },
146 (Some(ToolKind::Axe), Some(ToolKind::Axe)) => {
147 next.main.position =
148 Vec3::new(-s_a.hand.0 - 4.0, s_a.hand.1 + 2.0, s_a.hand.2 - 4.0);
149 next.main.orientation = Quaternion::rotation_x(-0.2);
150 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
151 next.hand_l.orientation = Quaternion::rotation_x(1.2);
152 next.second.position =
153 Vec3::new(s_a.hand.0 + 4.0, s_a.hand.1 + 2.0, s_a.hand.2 - 4.0);
154 next.second.orientation = Quaternion::rotation_x(-0.2);
155 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
156 next.hand_r.orientation = Quaternion::rotation_x(1.2);
157
158 next.chest.orientation = Quaternion::rotation_x(move2abs * -1.0)
159 * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
160
161 if mirror > 0.0 {
162 next.control_r.position += Vec3::new(-5.0, 0.0, 5.0) * move1abs;
163 next.control_r.orientation.rotate_x(PI / 10.0 * move1abs);
164 next.control_l.position += Vec3::new(3.0, 0.0, 10.0) * move1abs;
165 next.main.position += Vec3::new(3.0, 0.0, 10.0) * move1abs;
166 next.control_l.orientation.rotate_x(PI / 4.0 * move1abs);
167 next.main.orientation.rotate_x(PI / 4.0 * move1abs);
168
169 next.control_r.position += Vec3::new(0.0, 0.0, -5.0) * move2abs;
170 next.control_r.orientation.rotate_x(-PI / 4.0 * move2abs);
171 next.control_l.position += Vec3::new(0.0, 0.0, -10.0) * move2abs;
172 next.main.position += Vec3::new(0.0, 0.0, -10.0) * move2abs;
173 next.control_l.orientation.rotate_x(-PI / 4.0 * move2abs);
174 next.main.orientation.rotate_x(-PI / 4.0 * move2abs);
175 } else {
176 next.control_l.position += Vec3::new(5.0, 0.0, 5.0) * move1abs;
177 next.main.position += Vec3::new(3.0, 0.0, 5.0) * move1abs;
178 next.control_l.orientation.rotate_x(PI / 10.0 * move1abs);
179 next.main.orientation.rotate_x(PI / 10.0 * move1abs);
180 next.control_r.position += Vec3::new(-3.0, 0.0, 10.0) * move1abs;
181 next.control_r.orientation.rotate_x(PI / 4.0 * move1abs);
182
183 next.control_l.position += Vec3::new(0.0, 0.0, -5.0) * move2abs;
184 next.main.position += Vec3::new(0.0, 0.0, -5.0) * move2abs;
185 next.control_l.orientation.rotate_x(-PI / 4.0 * move2abs);
186 next.main.orientation.rotate_x(-PI / 4.0 * move2abs);
187 next.control_r.position += Vec3::new(0.0, 0.0, -10.0) * move2abs;
188 next.control_r.orientation.rotate_x(-PI / 4.0 * move2abs);
189 }
190 },
191 _ => {
192 next.chest.orientation = Quaternion::rotation_x(move2abs * -1.0)
193 * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
194 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
195 next.hand_l.orientation = Quaternion::rotation_x(1.2);
196 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
197 next.hand_r.orientation = Quaternion::rotation_x(1.2);
198 },
199 }
200 next
201 }
202}