veloren_voxygen_anim/quadruped_medium/
feed.rs

1use super::{
2    super::{Animation, vek::*},
3    QuadrupedMediumSkeleton, SkeletonAttr,
4};
5use std::{f32::consts::PI, ops::Mul};
6
7pub struct FeedAnimation;
8
9impl Animation for FeedAnimation {
10    type Dependency<'a> = f32;
11    type Skeleton = QuadrupedMediumSkeleton;
12
13    #[cfg(feature = "use-dyn-lib")]
14    const UPDATE_FN: &'static [u8] = b"quadruped_medium_feed\0";
15
16    #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_feed")]
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        let slower = (anim_time * 1.0 + PI).sin();
26        let slow = (anim_time * 3.5 + PI).sin();
27        let fast = (anim_time * 5.0).sin();
28        let faster = (anim_time * 14.0).sin();
29
30        let transition = ((anim_time.powf(2.0)).min(1.0)) * s_a.feed.1;
31
32        let look = Vec2::new(
33            (global_time / 2.0 + anim_time / 8.0)
34                .floor()
35                .mul(7331.0)
36                .sin()
37                * 0.5,
38            (global_time / 2.0 + anim_time / 8.0)
39                .floor()
40                .mul(1337.0)
41                .sin()
42                * 0.25,
43        );
44
45        if s_a.feed.0 {
46            next.head.position = Vec3::new(
47                0.0,
48                s_a.head.0,
49                s_a.head.1 + slower * 0.2 + transition * 1.5,
50            );
51            next.head.orientation = Quaternion::rotation_z(0.3 * look.x)
52                * Quaternion::rotation_x(fast * 0.05 + faster * 0.08 + transition * -0.5);
53
54            next.neck.position = Vec3::new(
55                0.0,
56                s_a.neck.0 + transition * 1.0,
57                s_a.neck.1 + slower * 0.1 + transition * 1.5,
58            );
59            next.neck.orientation = Quaternion::rotation_x(transition * -0.5);
60
61            next.jaw.position = Vec3::new(0.0, s_a.jaw.0 - slower * 0.12, s_a.jaw.1 + slow * 0.2);
62            next.jaw.orientation = Quaternion::rotation_x((fast * 0.18 + faster * 0.26).min(0.0));
63        } else {
64            next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + slower * 0.2);
65            next.head.orientation =
66                Quaternion::rotation_z(0.3 * look.x) * Quaternion::rotation_x(0.3 * look.y);
67
68            next.neck.position = Vec3::new(0.0, s_a.neck.0, s_a.neck.1 + slower * 0.1);
69
70            next.jaw.position =
71                Vec3::new(0.0, s_a.jaw.0 - slower * 0.12, s_a.jaw.1 + slow * 0.2 + 0.5);
72            next.jaw.orientation = Quaternion::rotation_x(slow * 0.05 * anim_time.min(1.0) - 0.08);
73        }
74
75        next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
76        next.tail.orientation = Quaternion::rotation_z(0.0 + slow * 0.2 + look.x);
77
78        next.torso_front.position = Vec3::new(
79            0.0,
80            s_a.torso_front.0,
81            s_a.torso_front.1 + slower * 0.3 + transition * -6.0,
82        );
83        next.torso_front.orientation =
84            Quaternion::rotation_x(transition * -0.7) * Quaternion::rotation_y(slow * 0.02);
85
86        next.torso_back.position =
87            Vec3::new(0.0, s_a.torso_back.0, s_a.torso_back.1 + slower * 0.2);
88        next.torso_back.orientation =
89            Quaternion::rotation_x(transition * 0.5) * Quaternion::rotation_y(-slow * 0.005);
90
91        next.ears.position = Vec3::new(0.0, s_a.ears.0, s_a.ears.1);
92        next.ears.orientation = Quaternion::rotation_x(0.0 + slower * 0.03);
93
94        next.leg_fl.position = Vec3::new(
95            -s_a.leg_f.0,
96            s_a.leg_f.1 + transition * -2.2,
97            s_a.leg_f.2 + slow * -0.15 + slower * -0.15 + transition * 2.4,
98        );
99        next.leg_fl.orientation =
100            Quaternion::rotation_x(transition * 1.0) * Quaternion::rotation_y(slow * -0.02);
101
102        next.leg_fr.position = Vec3::new(
103            s_a.leg_f.0,
104            s_a.leg_f.1 + transition * -2.2,
105            s_a.leg_f.2 + slow * 0.15 + slower * -0.15 + transition * 2.4,
106        );
107        next.leg_fr.orientation =
108            Quaternion::rotation_x(transition * 1.0) * Quaternion::rotation_y(slow * -0.02);
109
110        next.leg_bl.position = Vec3::new(
111            -s_a.leg_b.0,
112            s_a.leg_b.1,
113            s_a.leg_b.2 + slower * -0.3 + transition * -1.3,
114        );
115        next.leg_bl.orientation =
116            Quaternion::rotation_x(transition * 0.2) * Quaternion::rotation_y(slow * -0.02);
117
118        next.leg_br.position = Vec3::new(
119            s_a.leg_b.0,
120            s_a.leg_b.1,
121            s_a.leg_b.2 + slower * -0.3 + transition * -1.3,
122        );
123        next.leg_br.orientation =
124            Quaternion::rotation_x(transition * 0.2) * Quaternion::rotation_y(slow * -0.02);
125
126        next.foot_fl.position =
127            Vec3::new(-s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2 + slower * -0.2);
128        next.foot_fl.orientation = Quaternion::rotation_x(transition * -0.3);
129
130        next.foot_fr.position = Vec3::new(s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2 + slower * -0.2);
131        next.foot_fr.orientation = Quaternion::rotation_x(transition * -0.3);
132        next.foot_bl.position =
133            Vec3::new(-s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2 + slower * -0.2);
134
135        next.foot_br.position = Vec3::new(s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2 + slower * -0.2);
136
137        next
138    }
139}