veloren_voxygen_anim/crustacean/
run.rs1use super::{
2 super::{Animation, vek::*},
3 CrustaceanSkeleton, SkeletonAttr,
4};
5use std::f32::consts::PI;
6
7pub struct RunAnimation;
8
9impl Animation for RunAnimation {
10 type Dependency<'a> = (Vec3<f32>, Vec3<f32>, Vec3<f32>, f32, Vec3<f32>, f32);
11 type Skeleton = CrustaceanSkeleton;
12
13 #[cfg(feature = "use-dyn-lib")]
14 const UPDATE_FN: &'static [u8] = b"crustacean_run\0";
15
16 #[cfg_attr(feature = "be-dyn-lib", export_name = "crustacean_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(22.0);
26 *rate = 1.0;
27
28 let speednorm = speed / 13.0;
29
30 let direction = velocity.y * 0.098 * orientation.y + velocity.x * 0.098 * orientation.x;
31
32 let side =
33 (velocity.x * -0.098 * orientation.y + velocity.y * 0.098 * orientation.x) * -1.0;
34 let sideabs = side.abs();
35
36 let mixed_vel = (acc_vel + anim_time * 6.0) * 0.8; let ratio = 0.1;
41 let wave1 = (mixed_vel).sin();
42 let wave2 = (mixed_vel - PI / 2.0).sin();
43 let wave3 = (mixed_vel + PI / 2.0).sin();
44 let wave4 = (mixed_vel + PI).sin();
45 let slow_wave = (mixed_vel / 20.0).sin();
46 let foot1 = wave1.abs().powf(ratio) * wave1.signum();
47 let foot2 = wave2.abs().powf(ratio) * wave2.signum();
48 let foot3 = wave3.abs().powf(ratio) * wave3.signum();
49 let foot4 = wave4.abs().powf(ratio) * wave4.signum();
50 let turn = slow_wave.abs().powf(ratio) * slow_wave.signum();
51
52 let x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude()) * speednorm;
53
54 next.chest.scale = Vec3::one() * s_a.scaler;
55
56 let up_rot = 0.3;
57 let sideways = (PI / 2.0) * turn;
58
59 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + x_tilt);
60
61 if s_a.move_sideways {
62 next.chest.orientation =
63 Quaternion::rotation_x((mixed_vel).sin().max(0.0) * 0.06 + x_tilt)
64 * Quaternion::rotation_z(sideways + ((mixed_vel + PI / 2.0).sin() * 0.06));
65
66 next.arm_l.orientation = Quaternion::rotation_x(1.0)
67 * Quaternion::rotation_y(foot4.max(sideabs * -0.5) * up_rot)
68 * Quaternion::rotation_z(0.3 - foot2 * 0.1 * direction);
69 next.arm_r.orientation = Quaternion::rotation_x(1.0)
70 * Quaternion::rotation_y(-foot1.max(sideabs * -0.5) * up_rot)
71 * Quaternion::rotation_z(-0.2 - foot3 * 0.1 * direction);
72 } else {
73 next.chest.orientation =
74 Quaternion::rotation_x((mixed_vel).sin().max(0.0) * 0.06 + x_tilt);
75 next.arm_l.orientation = Quaternion::rotation_z(0.3 - foot2 * 0.2 * direction);
76 next.arm_r.orientation = Quaternion::rotation_z(-0.2 + foot3 * 0.2 * direction);
77
78 next.pincer_l0.orientation = Quaternion::rotation_x((mixed_vel).sin().max(0.0) * 0.2);
79 next.pincer_l1.position = Vec3::new(0.0, -4.0, 1.0);
80 next.pincer_l1.orientation = Quaternion::rotation_x((mixed_vel).sin().max(0.0) * -0.4);
81
82 next.pincer_r0.orientation = Quaternion::rotation_x((mixed_vel).sin().max(0.0) * 0.2);
83 next.pincer_r1.position = Vec3::new(0.0, -4.0, 3.0);
84 next.pincer_r1.orientation = Quaternion::rotation_x((mixed_vel).sin().max(0.0) * -0.4);
85 }
86
87 next.arm_l.position = Vec3::new(0.0, s_a.arm.1, 0.0);
88 next.arm_r.position = Vec3::new(0.0, s_a.arm.1, 0.0);
89
90 next.leg_fl.position = Vec3::new(-s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
91 next.leg_fr.position = Vec3::new(s_a.leg_f.0, s_a.leg_f.1, s_a.leg_f.2);
92 next.leg_fl.orientation = Quaternion::rotation_y(foot4.max(sideabs * -0.5) * up_rot)
93 * Quaternion::rotation_z(s_a.leg_ori.0 + foot2 * 0.1 * direction);
94 next.leg_fr.orientation = Quaternion::rotation_y(-foot1.max(sideabs * -0.5) * up_rot)
95 * Quaternion::rotation_z(-s_a.leg_ori.0 - foot3 * 0.1 * direction);
96
97 next.leg_cl.position = Vec3::new(-s_a.leg_c.0, s_a.leg_c.1, s_a.leg_c.2);
98 next.leg_cr.position = Vec3::new(s_a.leg_c.0, s_a.leg_c.1, s_a.leg_c.2);
99 next.leg_cl.orientation = Quaternion::rotation_x(foot4 * 0.1 * direction)
100 * Quaternion::rotation_y(foot1.max(sideabs * -0.5) * up_rot)
101 * Quaternion::rotation_z(s_a.leg_ori.1 + foot3 * 0.2 * direction);
102 next.leg_cr.orientation = Quaternion::rotation_x(foot1 * 0.1 * direction)
103 * Quaternion::rotation_y(foot1.min(sideabs * -0.5) * up_rot)
104 * Quaternion::rotation_z(-s_a.leg_ori.1 - foot2 * 0.2 * direction);
105
106 next.leg_bl.position = Vec3::new(-s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
107 next.leg_br.position = Vec3::new(s_a.leg_b.0, s_a.leg_b.1, s_a.leg_b.2);
108 next.leg_bl.orientation = Quaternion::rotation_x(foot4 * 0.2)
109 * Quaternion::rotation_y(foot4.max(sideabs * -0.5) * up_rot)
110 * Quaternion::rotation_z(s_a.leg_ori.2 + foot3 * 0.2 * -direction);
111 next.leg_br.orientation = Quaternion::rotation_x(foot1 * 0.2 * direction)
112 * Quaternion::rotation_y(foot4.min(sideabs * -0.5) * up_rot)
113 * Quaternion::rotation_z(-s_a.leg_ori.2 - foot2 * 0.2 * -direction);
114
115 next
116 }
117}