veloren_voxygen_anim/biped_small/
stunned.rs1use super::{
2 super::{Animation, vek::*},
3 BipedSmallSkeleton, SkeletonAttr,
4};
5use common::{comp::item::ToolKind, states::utils::StageSection};
6use core::f32::consts::PI;
7
8pub struct StunnedAnimation;
9
10type StunnedAnimationDependency = (
11 Option<ToolKind>,
12 Vec3<f32>,
13 Vec3<f32>,
14 Vec3<f32>,
15 f32,
16 Vec3<f32>,
17 f32,
18 bool,
19 Option<StageSection>,
20 f32,
21);
22
23impl Animation for StunnedAnimation {
24 type Dependency<'a> = StunnedAnimationDependency;
25 type Skeleton = BipedSmallSkeleton;
26
27 #[cfg(feature = "use-dyn-lib")]
28 const UPDATE_FN: &'static [u8] = b"biped_small_stunned\0";
29
30 #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "biped_small_stunned"))]
31 fn update_skeleton_inner(
32 skeleton: &Self::Skeleton,
33 (
34 active_tool_kind,
35 velocity,
36 _orientation,
37 _last_ori,
38 global_time,
39 _avg_vel,
40 _acc_vel,
41 wield_status,
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 speednorm = speed / 9.4;
53 if wield_status {
54 let (movement1base, movement2) = match stage_section {
55 Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0),
56 Some(StageSection::Recover) => (1.0, anim_time.powf(4.0)),
57 _ => (0.0, 0.0),
58 };
59 let pullback = 1.0 - movement2;
60 let subtract = global_time - timer;
61 let check = subtract - subtract.trunc();
62 let mirror = (check - 0.5).signum();
63 let movement1 = movement1base * pullback * mirror;
64 let movement1abs = movement1base * pullback;
65 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
66 next.head.orientation =
67 Quaternion::rotation_x(movement1 * 0.2) * Quaternion::rotation_z(movement1 * -0.3);
68 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + movement1abs - 3.0);
69 next.chest.orientation = Quaternion::rotation_z(movement1 * 1.2);
70
71 next.pants.position = Vec3::new(0.0, s_a.pants.0, s_a.pants.1);
72
73 next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
74 next.tail.orientation = Quaternion::rotation_x(0.0) * Quaternion::rotation_z(0.0);
75
76 next.main.position = Vec3::new(0.0, 0.0, 0.0);
77 next.main.orientation = Quaternion::rotation_x(0.0);
78
79 next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
80 next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
81
82 next.hand_l.orientation = Quaternion::rotation_x(0.0);
83 next.hand_r.orientation = Quaternion::rotation_x(0.0);
84
85 match active_tool_kind {
90 Some(ToolKind::Spear) => {
91 next.control_l.position = Vec3::new(1.0 - s_a.grip.0 * 2.0, 2.0, -2.0);
92 next.control_r.position = Vec3::new(-1.0 + s_a.grip.0 * 2.0, 2.0, 2.0);
93
94 next.control.position = Vec3::new(
95 -3.0,
96 s_a.grip.2,
97 -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + speednorm * 2.0,
98 );
99
100 next.control_l.orientation =
101 Quaternion::rotation_x(PI / 1.5) * Quaternion::rotation_y(-0.3);
102 next.control_r.orientation =
103 Quaternion::rotation_x(PI / 1.5 + s_a.grip.0 * 0.2)
104 * Quaternion::rotation_y(0.5 + s_a.grip.0 * 0.2);
105
106 next.control.orientation = Quaternion::rotation_x(-1.35 + 0.5 * speednorm);
107 },
108
109 Some(ToolKind::Bow) => {
110 next.control_l.position = Vec3::new(1.0 - s_a.grip.0 * 2.0, 0.0, 0.0);
111 next.control_r.position = Vec3::new(-1.0 + s_a.grip.0 * 2.0, 6.0, -2.0);
112
113 next.control.position = Vec3::new(
114 -1.0,
115 2.0 + s_a.grip.2,
116 3.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + speednorm * 2.0,
117 );
118
119 next.control_l.orientation =
120 Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_y(-0.3);
121 next.control_r.orientation =
122 Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
123 * Quaternion::rotation_y(0.5 + s_a.grip.0 * 0.2);
124
125 next.control.orientation = Quaternion::rotation_x(-0.3 + 0.5 * speednorm)
126 * Quaternion::rotation_y(0.5 * speednorm);
127 },
128 Some(ToolKind::Staff) => {
129 next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
130 next.control_r.position =
131 Vec3::new(7.0 + s_a.grip.0 * 2.0, -4.0, 3.0 + speednorm * -3.0);
132
133 next.control.position = Vec3::new(
134 -5.0,
135 -1.0 + s_a.grip.2,
136 -2.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + speednorm * 2.0,
137 );
138
139 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
140 * Quaternion::rotation_y(-0.3)
141 * Quaternion::rotation_z(-0.3);
142 next.control_r.orientation =
143 Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
144 * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2)
145 * Quaternion::rotation_z(-0.0);
146
147 next.control.orientation = Quaternion::rotation_x(-0.3 + 0.2 * speednorm)
148 * Quaternion::rotation_y(-0.2 * speednorm)
149 * Quaternion::rotation_z(0.5);
150 },
151 Some(ToolKind::Natural) => {
152 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
153 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
154
155 next.hand_l.orientation =
156 Quaternion::rotation_x(1.7) * Quaternion::rotation_y(-0.3);
157 next.hand_r.orientation =
158 Quaternion::rotation_x(1.7) * Quaternion::rotation_y(0.3);
159 },
160 _ => {},
161 }
162 } else {
163 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
164
165 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1);
166 next.pants.position = Vec3::new(0.0, s_a.pants.0, s_a.pants.1);
167 next.main.position = Vec3::new(2.0, -3.0, -3.0);
168 next.main.orientation = Quaternion::rotation_y(-0.5) * Quaternion::rotation_z(PI / 2.0);
169
170 next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
171 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
172 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
173 next.foot_l.position = Vec3::new(-s_a.foot.0, s_a.foot.1, s_a.foot.2);
174 next.foot_r.position = Vec3::new(s_a.foot.0, s_a.foot.1, s_a.foot.2);
175 }
176
177 next
178 }
179}