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