veloren_voxygen_anim/character/
stunned.rs1use super::{
2 super::{Animation, vek::*},
3 CharacterSkeleton, SkeletonAttr,
4};
5use common::{
6 comp::item::{Hands, ToolKind},
7 states::utils::StageSection,
8};
9use core::f32::consts::PI;
10
11pub struct StunnedAnimation;
12
13type StunnedAnimationDependency = (
14 Option<ToolKind>,
15 Option<ToolKind>,
16 (Option<Hands>, Option<Hands>),
17 f32,
18 f32,
19 Option<StageSection>,
20 f32,
21 bool,
22);
23impl Animation for StunnedAnimation {
24 type Dependency<'a> = StunnedAnimationDependency;
25 type Skeleton = CharacterSkeleton;
26
27 #[cfg(feature = "use-dyn-lib")]
28 const UPDATE_FN: &'static [u8] = b"character_stunned\0";
29
30 #[cfg_attr(feature = "be-dyn-lib", export_name = "character_stunned")]
31 fn update_skeleton_inner(
32 skeleton: &Self::Skeleton,
33 (
34 active_tool_kind,
35 _second_tool_kind,
36 hands,
37 _velocity,
38 global_time,
39 stage_section,
40 timer,
41 wield_status,
42 ): Self::Dependency<'_>,
43 anim_time: f32,
44 rate: &mut f32,
45 s_a: &SkeletonAttr,
46 ) -> Self::Skeleton {
47 *rate = 1.0;
48 let mut next = (*skeleton).clone();
49
50 let (movement1base, movement2) = match stage_section {
51 Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0),
52 Some(StageSection::Recover) => (1.0, anim_time.powf(4.0)),
53 _ => (0.0, 0.0),
54 };
55 let pullback = 1.0 - movement2;
56 let subtract = global_time - timer;
57 let check = subtract - subtract.trunc();
58 let mirror = (check - 0.5).signum();
59 let movement1 = movement1base * pullback * mirror;
60 let movement1abs = movement1base * pullback;
61
62 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
63 next.head.orientation = Quaternion::rotation_z(movement1 * -0.3);
64 next.shorts.orientation =
65 Quaternion::rotation_x(movement1abs * -0.2) * Quaternion::rotation_z(movement1 * -0.3);
66 next.belt.orientation =
67 Quaternion::rotation_x(movement1abs * -0.1) * Quaternion::rotation_z(movement1 * -0.2);
68
69 next.chest.orientation =
70 Quaternion::rotation_x(movement1abs * 0.3) * Quaternion::rotation_z(movement1 * 1.0);
71 if wield_status {
72 next.main.position = Vec3::new(0.0, 0.0, 0.0);
73 next.main.orientation = Quaternion::rotation_x(0.0);
74 next.second.position = Vec3::new(0.0, 0.0, 0.0);
75 next.second.orientation = Quaternion::rotation_z(0.0);
76 match hands {
77 (Some(Hands::Two), _) | (None, Some(Hands::Two)) => match active_tool_kind {
78 Some(ToolKind::Sword) => {
79 next.hand_l.position = Vec3::new(s_a.shl.0, s_a.shl.1, s_a.shl.2);
80 next.hand_l.orientation =
81 Quaternion::rotation_x(s_a.shl.3) * Quaternion::rotation_y(s_a.shl.4);
82 next.hand_r.position = Vec3::new(s_a.shr.0, s_a.shr.1, s_a.shr.2);
83 next.hand_r.orientation =
84 Quaternion::rotation_x(s_a.shr.3) * Quaternion::rotation_y(s_a.shr.4);
85
86 next.control.position = Vec3::new(s_a.sc.0, s_a.sc.1, s_a.sc.2);
87 next.control.orientation = Quaternion::rotation_x(s_a.sc.3);
88 },
89 Some(ToolKind::Axe) => {
90 next.hand_l.position = Vec3::new(s_a.ahl.0, s_a.ahl.1, s_a.ahl.2);
91 next.hand_l.orientation =
92 Quaternion::rotation_x(s_a.ahl.3) * Quaternion::rotation_y(s_a.ahl.4);
93 next.hand_r.position = Vec3::new(s_a.ahr.0, s_a.ahr.1, s_a.ahr.2);
94 next.hand_r.orientation =
95 Quaternion::rotation_x(s_a.ahr.3) * Quaternion::rotation_z(s_a.ahr.5);
96
97 next.control.position = Vec3::new(s_a.ac.0, s_a.ac.1, s_a.ac.2);
98 next.control.orientation = Quaternion::rotation_x(s_a.ac.3)
99 * Quaternion::rotation_y(s_a.ac.4)
100 * Quaternion::rotation_z(s_a.ac.5);
101 },
102 Some(ToolKind::Hammer | ToolKind::Pick | ToolKind::Shovel) => {
103 next.hand_l.position = Vec3::new(s_a.hhl.0, s_a.hhl.1, s_a.hhl.2);
104 next.hand_l.orientation = Quaternion::rotation_x(s_a.hhl.3)
105 * Quaternion::rotation_y(s_a.hhl.4)
106 * Quaternion::rotation_z(s_a.hhl.5);
107 next.hand_r.position = Vec3::new(s_a.hhr.0, s_a.hhr.1, s_a.hhr.2);
108 next.hand_r.orientation = Quaternion::rotation_x(s_a.hhr.3)
109 * Quaternion::rotation_y(s_a.hhr.4)
110 * Quaternion::rotation_z(s_a.hhr.5);
111
112 next.control.position = Vec3::new(s_a.hc.0, s_a.hc.1, s_a.hc.2);
113 next.control.orientation = Quaternion::rotation_x(s_a.hc.3)
114 * Quaternion::rotation_y(s_a.hc.4)
115 * Quaternion::rotation_z(s_a.hc.5);
116 },
117 Some(ToolKind::Staff) | Some(ToolKind::Sceptre) => {
118 next.hand_r.position = Vec3::new(s_a.sthr.0, s_a.sthr.1, s_a.sthr.2);
119 next.hand_r.orientation =
120 Quaternion::rotation_x(s_a.sthr.3) * Quaternion::rotation_y(s_a.sthr.4);
121
122 next.control.position = Vec3::new(s_a.stc.0, s_a.stc.1, s_a.stc.2);
123
124 next.hand_l.position = Vec3::new(s_a.sthl.0, s_a.sthl.1, s_a.sthl.2);
125 next.hand_l.orientation = Quaternion::rotation_x(s_a.sthl.3);
126
127 next.control.orientation = Quaternion::rotation_x(s_a.stc.3)
128 * Quaternion::rotation_y(s_a.stc.4)
129 * Quaternion::rotation_z(s_a.stc.5);
130 },
131 Some(ToolKind::Bow) => {
132 next.hand_l.position = Vec3::new(s_a.bhl.0, s_a.bhl.1, s_a.bhl.2);
133 next.hand_l.orientation = Quaternion::rotation_x(s_a.bhl.3);
134 next.hand_r.position = Vec3::new(s_a.bhr.0, s_a.bhr.1, s_a.bhr.2);
135 next.hand_r.orientation = Quaternion::rotation_x(s_a.bhr.3);
136
137 next.hold.position = Vec3::new(0.0, -1.0, -5.2);
138 next.hold.orientation = Quaternion::rotation_x(-PI / 2.0);
139 next.hold.scale = Vec3::one() * 1.0;
140
141 next.control.position = Vec3::new(s_a.bc.0, s_a.bc.1, s_a.bc.2);
142 next.control.orientation =
143 Quaternion::rotation_y(s_a.bc.4) * Quaternion::rotation_z(s_a.bc.5);
144 },
145 Some(ToolKind::Debug) => {
146 next.hand_l.position = Vec3::new(-7.0, 4.0, 3.0);
147 next.hand_l.orientation = Quaternion::rotation_x(1.27);
148 next.main.position = Vec3::new(-5.0, 5.0, 23.0);
149 next.main.orientation = Quaternion::rotation_x(PI);
150 },
151 Some(ToolKind::Farming) => {
152 next.hand_l.position = Vec3::new(9.0, 1.0, 1.0);
153 next.hand_l.orientation = Quaternion::rotation_x(PI / 2.0);
154 next.hand_r.position = Vec3::new(9.0, 1.0, 11.0);
155 next.hand_r.orientation = Quaternion::rotation_x(PI / 2.0);
156 next.main.position = Vec3::new(7.5, 7.5, 13.2);
157 next.main.orientation = Quaternion::rotation_y(PI);
158 next.control.position = Vec3::new(-11.0, 1.8, 4.0);
159 },
160 Some(ToolKind::Instrument) => {
161 next.hand_l.position = Vec3::new(-7.0, 4.0, 3.0);
162 next.hand_l.orientation = Quaternion::rotation_x(1.27);
163 next.main.position = Vec3::new(-5.0, 5.0, 23.0);
164 next.main.orientation = Quaternion::rotation_x(PI);
165 },
166 _ => {},
167 },
168 (_, _) => {},
169 };
170 match hands {
171 (Some(Hands::One), _) => {
172 next.control_l.position = Vec3::new(-7.0, 8.0, 2.0);
173 next.control_l.orientation = Quaternion::rotation_x(-0.3);
174 next.hand_l.position = Vec3::new(0.0, -0.5, 0.0);
175 next.hand_l.orientation = Quaternion::rotation_x(PI / 2.0)
176 },
177 (_, _) => {},
178 };
179 match hands {
180 (None | Some(Hands::One), Some(Hands::One)) => {
181 next.control_r.position = Vec3::new(7.0, 8.0, 2.0);
182 next.control_r.orientation = Quaternion::rotation_x(-0.3);
183 next.hand_r.position = Vec3::new(0.0, -0.5, 0.0);
184 next.hand_r.orientation = Quaternion::rotation_x(PI / 2.0)
185 },
186 (_, _) => {},
187 };
188 match hands {
189 (None, None) | (None, Some(Hands::One)) => {
190 next.hand_l.position = Vec3::new(-4.5, 8.0, 5.0);
191 next.hand_l.orientation =
192 Quaternion::rotation_x(1.9) * Quaternion::rotation_y(-0.5)
193 },
194 (_, _) => {},
195 };
196 match hands {
197 (None, None) | (Some(Hands::One), None) => {
198 next.hand_r.position = Vec3::new(4.5, 8.0, 5.0);
199 next.hand_r.orientation =
200 Quaternion::rotation_x(1.9) * Quaternion::rotation_y(0.5)
201 },
202 (_, _) => {},
203 }
204 } else if mirror > 0.0 {
205 next.hand_r.position = Vec3::new(
206 s_a.hand.0 + movement1abs * -4.0,
207 s_a.hand.1 + movement1 * 7.0,
208 s_a.hand.2 + movement1 * 6.0,
209 );
210 next.hand_r.orientation =
211 Quaternion::rotation_x(movement1 * 1.2) * Quaternion::rotation_y(movement1 * 1.2);
212 } else {
213 next.hand_l.position = Vec3::new(
214 -s_a.hand.0 + movement1abs * 4.0,
215 s_a.hand.1 + movement1abs * 7.0,
216 s_a.hand.2 + movement1abs * 6.0,
217 );
218 next.hand_l.orientation = Quaternion::rotation_x(movement1abs * 1.2)
219 * Quaternion::rotation_y(movement1 * 1.2);
220 };
221 next.torso.position = Vec3::new(0.0, 0.0, 0.0);
222 next.torso.orientation = Quaternion::rotation_z(0.0);
223
224 if let (None, Some(Hands::Two)) = hands {
225 next.second = next.main;
226 }
227
228 next
229 }
230}