veloren_voxygen_anim/quadruped_small/
idle.rs1use super::{
2 super::{Animation, vek::*},
3 QuadrupedSmallSkeleton, SkeletonAttr,
4};
5use std::{f32::consts::PI, ops::Mul};
6
7pub struct IdleAnimation;
8
9impl Animation for IdleAnimation {
10 type Dependency<'a> = f32;
11 type Skeleton = QuadrupedSmallSkeleton;
12
13 #[cfg(feature = "use-dyn-lib")]
14 const UPDATE_FN: &'static [u8] = b"quadruped_small_idle\0";
15
16 #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_small_idle")]
17 fn update_skeleton_inner(
18 skeleton: &Self::Skeleton,
19 global_time: Self::Dependency<'_>,
20 anim_time: f32,
21 _rate: &mut f32,
22 s_a: &SkeletonAttr,
23 ) -> Self::Skeleton {
24 let mut next = (*skeleton).clone();
25
26 let slow = (anim_time * 3.5).sin();
27
28 let slow_alt = (anim_time * 3.5 + PI / 2.0).sin();
29
30 let head_look = Vec2::new(
31 (global_time / 2.0 + anim_time / 8.0)
32 .floor()
33 .mul(7331.0)
34 .sin()
35 * 0.5,
36 (global_time / 2.0 + anim_time / 8.0)
37 .floor()
38 .mul(1337.0)
39 .sin()
40 * 0.25,
41 );
42
43 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + slow * 0.2);
44 next.head.orientation = Quaternion::rotation_z(head_look.x)
45 * Quaternion::rotation_x(head_look.y + slow_alt * 0.03);
46
47 next.chest.position = Vec3::new(slow * 0.05, s_a.chest.0, s_a.chest.1);
48 next.chest.orientation = Quaternion::rotation_y(slow * 0.05);
49
50 next.leg_fl.position = Vec3::new(-s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2 + slow * -0.2);
51 next.leg_fl.orientation =
52 Quaternion::rotation_x(slow * 0.03) * Quaternion::rotation_y(slow * -0.05);
53
54 next.leg_fr.position = Vec3::new(s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2 + slow * 0.2);
55 next.leg_fr.orientation =
56 Quaternion::rotation_x(slow_alt * 0.03) * Quaternion::rotation_y(slow * -0.05);
57
58 next.leg_bl.position = Vec3::new(-s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2 + slow * -0.2);
59 next.leg_bl.orientation =
60 Quaternion::rotation_x(slow_alt * 0.03) * Quaternion::rotation_y(slow * -0.05);
61
62 next.leg_br.position = Vec3::new(s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2 + slow * 0.2);
63 next.leg_br.orientation =
64 Quaternion::rotation_x(slow * 0.03) * Quaternion::rotation_y(slow * -0.05);
65
66 next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
67 next.tail.orientation = Quaternion::rotation_z(slow * 0.4);
68
69 next
70 }
71}