veloren_voxygen_anim/quadruped_low/
dash.rs1use super::{
2 super::{
3 Animation,
4 util::{bounce, elastic},
5 vek::*,
6 },
7 QuadrupedLowSkeleton, SkeletonAttr,
8};
9use common::{comp::body::parts::HeadState, states::utils::StageSection};
10use std::f32::consts::PI;
12
13pub struct DashAnimation;
14
15impl Animation for DashAnimation {
16 type Dependency<'a> = (
17 Option<&'a str>,
18 f32,
19 f32,
20 Option<StageSection>,
21 f32,
22 [HeadState; 3],
23 );
24 type Skeleton = QuadrupedLowSkeleton;
25
26 #[cfg(feature = "use-dyn-lib")]
27 const UPDATE_FN: &'static [u8] = b"quadruped_low_dash\0";
28
29 #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_low_dash")]
30 fn update_skeleton_inner(
31 skeleton: &Self::Skeleton,
32 (ability_id, _velocity, global_time, stage_section, timer, heads): Self::Dependency<'_>,
33 anim_time: f32,
34 _rate: &mut f32,
35 s_a: &SkeletonAttr,
36 ) -> Self::Skeleton {
37 let mut next = (*skeleton).clone();
38
39 match ability_id {
40 Some("common.abilities.custom.rocksnapper.dash") => {
41 let (buildup, charge, _action, recover) = match stage_section {
42 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0, 0.0),
43 Some(StageSection::Charge) => (1.0, anim_time, 0.0, 0.0),
44 Some(StageSection::Action) => (1.0, 1.0, anim_time, 0.0),
45 Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time),
46 _ => (0.0, 0.0, 0.0, 0.0),
47 };
48 let quick_buildup = buildup.powf(0.2);
49 let elastic_recover = elastic(recover);
50 next.head_c_upper.position = Vec3::new(
51 0.0,
52 s_a.head_upper.0 + (-1.0 * quick_buildup + elastic_recover) * 10.0,
53 s_a.head_upper.1,
54 );
55 next.head_c_upper.scale = Vec3::one() * (1.0 - buildup + elastic_recover);
56 next.head_c_lower.position = Vec3::new(
57 0.0,
58 s_a.head_lower.0 + (-1.0 * quick_buildup + elastic_recover) * 10.0,
59 s_a.head_lower.1,
60 );
61 next.head_c_lower.scale = Vec3::one()
62 * (1.0 - buildup + elastic_recover)
63 * heads[1].is_attached() as i32 as f32;
64 next.foot_fl.position = Vec3::new(
65 -s_a.feet_f.0 + (quick_buildup - elastic_recover) * 8.0,
66 s_a.feet_f.1 + (-1.0 * quick_buildup + elastic_recover) * 8.0,
67 s_a.feet_f.2 + (quick_buildup - elastic_recover) * 8.0,
68 );
69 next.foot_fl.scale = Vec3::one() * (1.0 - buildup + elastic_recover);
70 next.foot_fr.position = Vec3::new(
71 s_a.feet_f.0 - (quick_buildup - elastic_recover) * 8.0,
72 s_a.feet_f.1 + (-1.0 * quick_buildup + elastic_recover) * 8.0,
73 s_a.feet_f.2 + (quick_buildup - elastic_recover) * 8.0,
74 );
75 next.foot_fr.scale = Vec3::one() * (1.0 - buildup + elastic_recover);
76 next.foot_bl.position = Vec3::new(
77 -s_a.feet_b.0 + (quick_buildup - elastic_recover) * 8.0,
78 s_a.feet_b.1 + (quick_buildup - elastic_recover) * 8.0,
79 s_a.feet_b.2 + (quick_buildup - elastic_recover) * 8.0,
80 );
81 next.foot_bl.scale = Vec3::one() * (1.0 - buildup + elastic_recover);
82 next.foot_br.position = Vec3::new(
83 s_a.feet_b.0 - (quick_buildup - elastic_recover) * 8.0,
84 s_a.feet_b.1 + (quick_buildup - elastic_recover) * 8.0,
85 s_a.feet_b.2 + (quick_buildup - elastic_recover) * 8.0,
86 );
87 next.foot_br.scale = Vec3::one() * (1.0 - buildup + elastic_recover);
88 next.tail_front.position = Vec3::new(
89 0.0,
90 s_a.tail_front.0 + (quick_buildup - elastic_recover) * 20.0,
91 s_a.tail_front.1,
92 );
93 next.tail_front.scale = Vec3::one() * (1.0 - buildup + elastic_recover);
94 next.tail_rear.position = Vec3::new(
95 0.0,
96 s_a.tail_rear.0 + (quick_buildup - elastic_recover) * 20.0,
97 s_a.tail_rear.1,
98 );
99 next.tail_rear.scale = Vec3::one() * (1.0 - buildup + recover);
100
101 next.chest.position = Vec3::new(
102 0.0,
103 0.0,
104 s_a.chest.1 - bounce(buildup) * 5.0 + elastic(recover) * 5.0,
105 );
106 next.chest.orientation =
107 Quaternion::rotation_z(2.0 * PI * buildup + 4.0 * PI * charge);
108 },
109 _ => {
110 let (buildup, chargemovementbase, action, recover) = match stage_section {
111 Some(StageSection::Buildup) => (anim_time.sqrt(), 0.0, 0.0, 0.0),
112 Some(StageSection::Charge) => (1.0, 1.0, 0.0, 0.0),
113 Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(4), 0.0),
114 Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time),
115 _ => (0.0, 0.0, 0.0, 0.0),
116 };
117 let pullback = 1.0 - recover;
118 let subtract = global_time - timer;
119 let check = subtract - subtract.trunc();
120 let mirror = (check - 0.5).signum();
121 let twitch1 = (mirror * buildup * 9.5).sin();
122 let twitch1fast = (mirror * buildup * 25.0).sin();
123 let buildup_abs = buildup * pullback;
124 let action_abs = action * pullback;
125 let short = ((1.0
126 / (0.72 + 0.28 * ((anim_time * 16.0_f32 + PI * 0.25).sin()).powi(2)))
127 .sqrt())
128 * ((anim_time * 16.0_f32 + PI * 0.25).sin())
129 * chargemovementbase
130 * pullback;
131 let shortalt =
132 (anim_time * 16.0_f32 + PI * 0.25).sin() * chargemovementbase * pullback;
133
134 next.head_c_upper.orientation =
136 Quaternion::rotation_x(buildup_abs * 0.4 + action_abs * 0.3)
137 * Quaternion::rotation_z(short * -0.06 + twitch1 * -0.3);
138
139 next.head_c_lower.orientation =
140 Quaternion::rotation_x(buildup_abs * -0.4 + action_abs * -0.5)
141 * Quaternion::rotation_z(short * 0.15 + twitch1 * 0.3);
142
143 next.jaw_c.orientation = Quaternion::rotation_x(
144 twitch1fast * 0.2
145 + buildup_abs * -0.3
146 + action_abs * 1.2
147 + chargemovementbase * -0.5,
148 );
149
150 next.head_l_upper.orientation =
152 Quaternion::rotation_x(buildup_abs * 0.4 + action_abs * 0.3)
153 * Quaternion::rotation_z(short * -0.06 + twitch1 * -0.3);
154
155 next.head_l_lower.orientation =
156 Quaternion::rotation_x(buildup_abs * -0.4 + action_abs * -0.5)
157 * Quaternion::rotation_z(short * 0.15 + twitch1 * 0.3);
158
159 next.jaw_l.orientation = Quaternion::rotation_x(
160 twitch1fast * 0.2
161 + buildup_abs * -0.3
162 + action_abs * 1.2
163 + chargemovementbase * -0.5,
164 );
165
166 next.head_r_upper.orientation =
168 Quaternion::rotation_x(buildup_abs * 0.4 + action_abs * 0.3)
169 * Quaternion::rotation_z(short * -0.06 + twitch1 * -0.3);
170
171 next.head_r_lower.orientation =
172 Quaternion::rotation_x(buildup_abs * -0.4 + action_abs * -0.5)
173 * Quaternion::rotation_z(short * 0.15 + twitch1 * 0.3);
174
175 next.jaw_r.orientation = Quaternion::rotation_x(
176 twitch1fast * 0.2
177 + buildup_abs * -0.3
178 + action_abs * 1.2
179 + chargemovementbase * -0.5,
180 );
181
182 next.chest.orientation =
183 Quaternion::rotation_z(twitch1 * 0.06) * Quaternion::rotation_y(short * 0.06);
184
185 next.tail_front.orientation = Quaternion::rotation_x(
186 0.15 + buildup_abs * -0.4 + action_abs * 0.2 + chargemovementbase * 0.2,
187 ) * Quaternion::rotation_z(shortalt * 0.15);
188
189 next.tail_rear.orientation =
190 Quaternion::rotation_x(
191 -0.12 + buildup_abs * -0.4 + action_abs * 0.2 + chargemovementbase * 0.2,
192 ) * Quaternion::rotation_z(shortalt * 0.15 + twitch1fast * 0.3);
193 },
194 }
195 next
196 }
197}