veloren_voxygen_anim/biped_small/
idle.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedSmallSkeleton, SkeletonAttr,
4};
5use core::f32::consts::PI;
6
7pub struct IdleAnimation;
8
9type IdleAnimationDependency = (Vec3<f32>, Vec3<f32>, Vec3<f32>, f32, Vec3<f32>);
10
11impl Animation for IdleAnimation {
12    type Dependency<'a> = IdleAnimationDependency;
13    type Skeleton = BipedSmallSkeleton;
14
15    #[cfg(feature = "use-dyn-lib")]
16    const UPDATE_FN: &'static [u8] = b"biped_small_idle\0";
17
18    #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "biped_small_idle"))]
19
20    fn update_skeleton_inner(
21        skeleton: &Self::Skeleton,
22        (_velocity, _orientation, _last_ori, _global_time, _avg_vel): Self::Dependency<'_>,
23        anim_time: f32,
24        _rate: &mut f32,
25        s_a: &SkeletonAttr,
26    ) -> Self::Skeleton {
27        let mut next = (*skeleton).clone();
28        let slow = (anim_time * 4.0).sin();
29        let medium = (anim_time * 10.0).sin();
30
31        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + slow * -0.1);
32
33        next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + slow * 0.3);
34        next.pants.position = Vec3::new(0.0, s_a.pants.0, s_a.pants.1);
35        next.main.position = Vec3::new(4.0, -4.0, -3.0);
36        next.main.orientation = Quaternion::rotation_y(-0.5) * Quaternion::rotation_z(PI / 2.0);
37        next.second.position = Vec3::new(-4.0, -4.0, -3.0);
38        next.second.orientation = Quaternion::rotation_y(0.5) * Quaternion::rotation_z(-PI / 2.0);
39
40        next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
41        next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2 + slow * -0.1);
42        next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2 + slow * -0.1);
43
44        if s_a.wing_for_foot {
45            next.foot_l.position = Vec3::new(-s_a.foot.0, s_a.foot.1, s_a.foot.2);
46            next.foot_l.orientation =
47                Quaternion::rotation_x(-0.6 - medium * 0.6) * Quaternion::rotation_z(medium * 0.4);
48
49            next.foot_r.position = Vec3::new(s_a.foot.0, s_a.foot.1, s_a.foot.2);
50            next.foot_r.orientation =
51                Quaternion::rotation_x(-0.6 - medium * 0.6) * Quaternion::rotation_z(medium * -0.4);
52        } else {
53            next.foot_l.position = Vec3::new(-s_a.foot.0, s_a.foot.1, s_a.foot.2);
54            next.foot_r.position = Vec3::new(s_a.foot.0, s_a.foot.1, s_a.foot.2);
55        }
56
57        next
58    }
59}