veloren_voxygen_anim/quadruped_medium/
run.rs1use super::{
2 super::{Animation, vek::*},
3 QuadrupedMediumSkeleton, SkeletonAttr,
4};
5use core::{f32::consts::PI, ops::Mul};
6
7pub struct RunAnimation;
8
9impl Animation for RunAnimation {
10 type Dependency<'a> = (f32, Vec3<f32>, Vec3<f32>, f32, Vec3<f32>, f32);
11 type Skeleton = QuadrupedMediumSkeleton;
12
13 #[cfg(feature = "use-dyn-lib")]
14 const UPDATE_FN: &'static [u8] = b"quadruped_medium_run\0";
15
16 #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_run")]
17 fn update_skeleton_inner(
18 skeleton: &Self::Skeleton,
19 (velocity, orientation, last_ori, global_time, avg_vel, acc_vel): Self::Dependency<'_>,
20 anim_time: f32,
21 rate: &mut f32,
22 s_a: &SkeletonAttr,
23 ) -> Self::Skeleton {
24 let mut next = (*skeleton).clone();
25 let speed = (Vec2::<f32>::from(velocity).magnitude()).min(24.0);
26 *rate = 1.0;
27 let lab: f32 = 0.72;
28 let amplitude = (speed / 24.0).powf(0.6);
29 let amplitude2 = (speed / 24.0).powf(0.6);
30 let amplitude3 = (speed / 24.0).powf(0.6);
31 let speedmult = s_a.tempo;
32 let canceler = (speed / 24.0).powf(0.6);
33 let mixed_vel = acc_vel + anim_time * 2.5; let short = ((1.0
36 / (0.72
37 + 0.28
38 * ((mixed_vel * (1.0) * lab * speedmult + PI * -0.15 - 0.5).sin()).powi(2)))
39 .sqrt())
40 * ((mixed_vel * (1.0) * lab * speedmult + PI * -0.15 - 0.5).sin());
41
42 let shortalt = (mixed_vel * (1.0) * lab * speedmult + PI * 3.0 / 8.0 - 0.5).sin();
44 let look = Vec2::new(
45 (global_time / 2.0 + anim_time / 2.0)
46 .floor()
47 .mul(7331.0)
48 .sin()
49 * 0.5,
50 (global_time / 2.0 + anim_time / 2.0)
51 .floor()
52 .mul(1337.0)
53 .sin()
54 * 0.25,
55 );
56
57 let speedadjust = if speed < 5.0 { 0.0 } else { speed / 24.0 };
58 let shift1 = speedadjust - PI / 2.0 - speedadjust * PI * 3.0 / 4.0;
59 let shift2 = speedadjust + PI / 2.0 + speedadjust * PI / 2.0;
60 let shift3 = speedadjust + PI / 4.0 - speedadjust * PI / 4.0;
61 let shift4 = speedadjust - PI * 3.0 / 4.0 + speedadjust * PI / 2.0;
62
63 let foot1a = (mixed_vel * (1.0) * lab * speedmult + 0.0 + canceler * 0.05 + shift1).sin(); let foot1b = (mixed_vel * (1.0) * lab * speedmult + 1.1 + canceler * 0.05 + shift1).sin(); let foot2a = (mixed_vel * (1.0) * lab * speedmult + shift2).sin(); let foot2b = (mixed_vel * (1.0) * lab * speedmult + 1.1 + shift2).sin(); let foot3a = (mixed_vel * (1.0) * lab * speedmult + shift3).sin(); let foot3b = (mixed_vel * (1.0) * lab * speedmult + PI / 2.0 + shift3).sin(); let foot4a = (mixed_vel * (1.0) * lab * speedmult + 0.0 + canceler * 0.05 + shift4).sin(); let foot4b =
75 (mixed_vel * (1.0) * lab * speedmult + PI / 2.0 + canceler * 0.05 + shift4).sin(); let ori: Vec2<f32> = Vec2::from(orientation);
78 let last_ori = Vec2::from(last_ori);
79 let tilt = if vek::Vec2::new(ori, last_ori)
80 .map(|o| o.magnitude_squared())
81 .map(|m| m > 0.001 && m.is_finite())
82 .reduce_and()
83 && ori.angle_between(last_ori).is_finite()
84 {
85 ori.angle_between(last_ori).min(0.2)
86 * last_ori.determine_side(Vec2::zero(), ori).signum()
87 } else {
88 0.0
89 } * 1.3;
90 let x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude()) * canceler;
91
92 next.neck.scale = Vec3::one() * 1.02;
93 next.jaw.scale = Vec3::one() * 1.02;
94 next.leg_fl.scale = Vec3::one() * 1.02;
95 next.leg_fr.scale = Vec3::one() * 1.02;
96 next.leg_bl.scale = Vec3::one() * 1.02;
97 next.leg_br.scale = Vec3::one() * 1.02;
98 next.foot_fl.scale = Vec3::one() * 0.96;
99 next.foot_fr.scale = Vec3::one() * 0.96;
100 next.foot_bl.scale = Vec3::one() * 0.96;
101 next.foot_br.scale = Vec3::one() * 0.96;
102 next.ears.scale = Vec3::one() * 1.02;
103
104 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + shortalt * -0.2);
106 next.head.orientation = Quaternion::rotation_x(
107 look.y * 0.3 / ((canceler).max(0.5)) + amplitude * short * 0.2 - 0.1,
108 ) * Quaternion::rotation_z(
109 look.x * 0.3 / ((canceler).max(0.5)) + tilt * -2.0,
110 ) * Quaternion::rotation_y(tilt * 0.8);
111
112 next.neck.position = Vec3::new(0.0, s_a.neck.0, s_a.neck.1 + shortalt * -0.8);
113 next.neck.orientation = Quaternion::rotation_z(tilt * -0.8)
114 * Quaternion::rotation_x(amplitude * short * 0.05)
115 * Quaternion::rotation_y(tilt * 0.3);
116
117 next.jaw.position = Vec3::new(0.0, s_a.jaw.0, s_a.jaw.1);
118 next.jaw.orientation = Quaternion::rotation_x(0.0);
119
120 next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
121 next.tail.orientation = Quaternion::rotation_x(amplitude * shortalt * -0.3)
122 * Quaternion::rotation_z(tilt * 1.5);
123
124 next.torso_front.position = Vec3::new(
125 0.0,
126 s_a.torso_front.0,
127 s_a.torso_front.1
128 + canceler * 1.0
129 + canceler * shortalt * 2.5 * s_a.spring
130 + x_tilt * 10.0 * canceler,
131 );
132 next.torso_front.orientation = Quaternion::rotation_x(
133 ((amplitude * (short * -0.13).max(-0.2)) * s_a.spring).min(0.1)
134 + x_tilt * (canceler * 6.0).min(1.0),
135 ) * Quaternion::rotation_y(tilt * 0.8)
136 * Quaternion::rotation_z(tilt * -1.5);
137
138 next.torso_back.position = Vec3::new(
139 0.0,
140 s_a.torso_back.0,
141 s_a.torso_back.1 + amplitude * shortalt * 0.2 - 0.2,
142 );
143 next.torso_back.orientation = Quaternion::rotation_x(amplitude * short * -0.07)
144 * Quaternion::rotation_z(tilt * 1.8)
145 * Quaternion::rotation_y(tilt * 0.6);
146
147 next.ears.position = Vec3::new(0.0, s_a.ears.0, s_a.ears.1);
148 next.ears.orientation = Quaternion::rotation_x(amplitude * shortalt * 0.2 + 0.2);
149
150 next.leg_fl.position = Vec3::new(
151 -s_a.leg_f.0,
152 s_a.leg_f.1 + amplitude3 * foot1b * -1.6,
153 s_a.leg_f.2 + amplitude3 * foot1a * 2.3,
154 );
155 next.leg_fl.orientation = Quaternion::rotation_x(0.2 * canceler + amplitude3 * foot1a)
156 * Quaternion::rotation_z(tilt * -0.5)
157 * Quaternion::rotation_y(tilt * 1.5);
158
159 next.leg_fr.position = Vec3::new(
160 s_a.leg_f.0,
161 s_a.leg_f.1 + amplitude3 * foot2b * -1.6,
162 s_a.leg_f.2 + amplitude3 * foot2a * 2.3,
163 );
164 next.leg_fr.orientation = Quaternion::rotation_x(0.2 * canceler + amplitude3 * foot2a)
165 * Quaternion::rotation_z(tilt * -0.5)
166 * Quaternion::rotation_y(tilt * 1.5);
167
168 next.leg_bl.position = Vec3::new(
169 -s_a.leg_b.0,
170 s_a.leg_b.1 + amplitude3 * foot3a * -4.5,
171 s_a.leg_b.2 + amplitude3 * foot3b * -2.2,
172 );
173 next.leg_bl.orientation =
174 Quaternion::rotation_x(canceler * -0.1 + amplitude3 * foot3a * -1.2)
175 * Quaternion::rotation_y(tilt * 1.5)
176 * Quaternion::rotation_z(tilt * -1.5);
177
178 next.leg_br.position = Vec3::new(
179 s_a.leg_b.0,
180 s_a.leg_b.1 + amplitude3 * foot4a * -4.5,
181 s_a.leg_b.2 + amplitude3 * foot4b * -2.2,
182 );
183 next.leg_br.orientation =
184 Quaternion::rotation_x(canceler * -0.1 + amplitude3 * foot4a * -1.2)
185 * Quaternion::rotation_y(tilt * 1.5)
186 * Quaternion::rotation_z(tilt * -1.5);
187
188 next.foot_fl.position = Vec3::new(
189 -s_a.feet_f.0,
190 s_a.feet_f.1,
191 s_a.feet_f.2 + (foot1a * 2.0).max(-1.0) * amplitude2 + 1.0 * canceler,
192 );
193 next.foot_fl.orientation =
194 Quaternion::rotation_x(s_a.startangle * canceler + amplitude2 * foot1b * -0.85)
195 * Quaternion::rotation_y(tilt * -1.0);
196
197 next.foot_fr.position = Vec3::new(
198 s_a.feet_f.0,
199 s_a.feet_f.1,
200 s_a.feet_f.2 + (foot2a * 2.0).max(-1.0) * amplitude2 + 1.0 * canceler,
201 );
202 next.foot_fr.orientation =
203 Quaternion::rotation_x(s_a.startangle * canceler + amplitude2 * foot2b * -0.85)
204 * Quaternion::rotation_y(tilt * -1.0);
205
206 next.foot_bl.position = Vec3::new(
207 -s_a.feet_b.0,
208 s_a.feet_b.1,
209 s_a.feet_b.2 + (foot3a * 0.8).max(0.0) * amplitude2 + 1.0 * canceler,
210 );
211 next.foot_bl.orientation =
212 Quaternion::rotation_x(amplitude2 * foot3b * -0.7 - 0.2 * canceler)
213 * Quaternion::rotation_y(tilt * -1.0);
214
215 next.foot_br.position = Vec3::new(
216 s_a.feet_b.0,
217 s_a.feet_b.1,
218 s_a.feet_b.2 + (foot4a * 0.8).max(0.0) * amplitude2 + 1.0 * canceler,
219 );
220 next.foot_br.orientation =
221 Quaternion::rotation_x(amplitude2 * foot4b * -0.7 - 0.2 * canceler)
222 * Quaternion::rotation_y(tilt * -1.0);
223 next
224 }
225}