veloren_voxygen_anim/bird_large/
run.rs

1use super::{
2    super::{Animation, vek::*},
3    BirdLargeSkeleton, SkeletonAttr,
4};
5use core::f32::consts::PI;
6
7pub struct RunAnimation;
8
9impl Animation for RunAnimation {
10    type Dependency<'a> = (Vec3<f32>, Vec3<f32>, Vec3<f32>, Vec3<f32>, f32);
11    type Skeleton = BirdLargeSkeleton;
12
13    #[cfg(feature = "use-dyn-lib")]
14    const UPDATE_FN: &'static [u8] = b"bird_large_run\0";
15
16    #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_large_run")]
17    fn update_skeleton_inner(
18        skeleton: &Self::Skeleton,
19        (velocity, orientation, last_ori, 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        let speednorm = (speed / 13.0).powf(0.25);
30
31        let speedmult = 0.8;
32        let lab: f32 = 0.9; //6
33
34        // acc_vel and anim_time mix to make sure phase lenght isn't starting at
35        // +infinite
36        let mixed_vel = acc_vel + anim_time * 5.0; //sets run frequency using speed, with anim_time setting a floor
37
38        let short = ((1.0
39            / (0.72
40                + 0.28 * ((mixed_vel * 1.0 * lab * speedmult + PI * -0.15 - 0.5).sin()).powi(2)))
41        .sqrt())
42            * ((mixed_vel * 1.0 * lab * speedmult + PI * -0.15 - 0.5).sin())
43            * speednorm;
44
45        //
46        let shortalt = (mixed_vel * 1.0 * lab * speedmult + PI * 3.0 / 8.0 - 0.5).sin() * speednorm;
47
48        //FL
49        let foot1a = (mixed_vel * 1.0 * lab * speedmult + 0.0 + PI).sin() * speednorm; //1.5
50        let foot1b = (mixed_vel * 1.0 * lab * speedmult + PI / 2.0 + PI).sin() * speednorm; //1.9
51        //FR
52        let foot2a = (mixed_vel * 1.0 * lab * speedmult).sin() * speednorm; //1.2
53        let foot2b = (mixed_vel * 1.0 * lab * speedmult + PI / 2.0).sin() * speednorm; //1.6
54        let ori: Vec2<f32> = Vec2::from(orientation);
55        let last_ori = Vec2::from(last_ori);
56        let tilt = if vek::Vec2::new(ori, last_ori)
57            .map(|o| o.magnitude_squared())
58            .map(|m| m > 0.001 && m.is_finite())
59            .reduce_and()
60            && ori.angle_between(last_ori).is_finite()
61        {
62            ori.angle_between(last_ori).min(0.2)
63                * last_ori.determine_side(Vec2::zero(), ori).signum()
64        } else {
65            0.0
66        } * 1.3;
67        let x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude()) * speednorm;
68
69        next.head.scale = Vec3::one() * 0.99;
70        next.neck.scale = Vec3::one() * 1.01;
71        next.leg_l.scale = Vec3::one();
72        next.leg_r.scale = Vec3::one();
73        next.foot_l.scale = Vec3::one() * 1.01;
74        next.foot_r.scale = Vec3::one() * 1.01;
75        next.chest.scale = Vec3::one() * s_a.scaler * 0.99;
76        next.tail_front.scale = Vec3::one() * 1.01;
77        next.tail_rear.scale = Vec3::one() * 0.99;
78
79        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
80        next.head.orientation = Quaternion::rotation_x(-0.1 * speednorm + short * -0.05)
81            * Quaternion::rotation_y(tilt * 0.2)
82            * Quaternion::rotation_z(shortalt * -0.05 - tilt * 1.5);
83
84        next.beak.position = Vec3::new(0.0, s_a.beak.0, s_a.beak.1);
85        next.beak.orientation = Quaternion::rotation_x(short * -0.02 - 0.02);
86
87        next.neck.position = Vec3::new(0.0, s_a.neck.0, s_a.neck.1);
88        next.neck.orientation = Quaternion::rotation_x(-0.1 * speednorm + short * -0.04)
89            * Quaternion::rotation_y(tilt * 0.1)
90            * Quaternion::rotation_z(shortalt * -0.1 - tilt * 0.5);
91
92        next.foot_l.position = Vec3::new(
93            -s_a.foot.0,
94            s_a.foot.1 + foot1b * -1.0,
95            s_a.foot.2 + (foot1a * 4.0).max(0.0),
96        );
97        next.foot_l.orientation = Quaternion::rotation_x(0.2 * speednorm + foot1b * -0.3 + 0.1)
98            * Quaternion::rotation_y(tilt * -1.0)
99            * Quaternion::rotation_z(tilt * -0.5);
100
101        next.foot_r.position = Vec3::new(
102            s_a.foot.0,
103            s_a.foot.1 + foot2b * -1.0,
104            s_a.foot.2 + (foot2a * 4.0).max(0.0),
105        );
106        next.foot_r.orientation = Quaternion::rotation_x(0.2 * speednorm + foot2b * -0.3 + 0.1)
107            * Quaternion::rotation_y(tilt * -1.0)
108            * Quaternion::rotation_z(tilt * -0.5);
109
110        if s_a.wyvern {
111            next.chest.position = Vec3::new(
112                0.0,
113                s_a.chest.0,
114                s_a.chest.1 + short * 0.5 + x_tilt * 10.0 + speednorm * -2.0,
115            ) * s_a.scaler;
116            next.chest.orientation = Quaternion::rotation_x(-0.1 + short * 0.07 + x_tilt)
117                * Quaternion::rotation_y(tilt * 0.8 - shortalt * 0.2)
118                * Quaternion::rotation_z(shortalt * 0.1);
119
120            next.neck.orientation = next.neck.orientation * Quaternion::rotation_y(shortalt * 0.2);
121
122            next.tail_front.position = Vec3::new(0.0, s_a.tail_front.0, s_a.tail_front.1);
123            next.tail_front.orientation = Quaternion::rotation_x(0.3 + short * -0.02)
124                * Quaternion::rotation_y(shortalt * 0.2)
125                * Quaternion::rotation_z(tilt * 2.0);
126
127            next.tail_rear.position = Vec3::new(0.0, s_a.tail_rear.0, s_a.tail_rear.1);
128            next.tail_rear.orientation =
129                Quaternion::rotation_x(-0.1 + short * -0.1) * Quaternion::rotation_z(tilt * 0.8);
130
131            next.wing_in_l.position = Vec3::new(
132                -s_a.wing_in.0 + 1.5,
133                s_a.wing_in.1 + foot1a * 2.0,
134                s_a.wing_in.2 + speednorm * 1.0 + foot1b * 1.0 - 3.0,
135            );
136            next.wing_in_r.position = Vec3::new(
137                s_a.wing_in.0 - 1.5,
138                s_a.wing_in.1 + foot2a * 2.0,
139                s_a.wing_in.2 + speednorm * 1.0 + foot2b * 1.0 - 3.0,
140            );
141
142            next.wing_in_l.orientation = Quaternion::rotation_x(foot2a * -0.05 + speednorm * -0.3)
143                * Quaternion::rotation_y(-0.8 + speednorm * 0.5 + foot2b * -0.2 + shortalt * 0.3)
144                * Quaternion::rotation_z(0.2 + foot2a * 0.6);
145            next.wing_in_r.orientation = Quaternion::rotation_x(foot1a * -0.05 + speednorm * -0.3)
146                * Quaternion::rotation_y(0.8 + speednorm * -0.55 + foot1b * 0.2 + shortalt * 0.3)
147                * Quaternion::rotation_z(-0.2 + foot1a * -0.6);
148
149            next.wing_mid_l.position = Vec3::new(-s_a.wing_mid.0, s_a.wing_mid.1, s_a.wing_mid.2);
150            next.wing_mid_r.position = Vec3::new(s_a.wing_mid.0, s_a.wing_mid.1, s_a.wing_mid.2);
151            next.wing_mid_l.orientation = Quaternion::rotation_x(0.1)
152                * Quaternion::rotation_y(-0.1)
153                * Quaternion::rotation_z(0.7);
154            next.wing_mid_r.orientation = Quaternion::rotation_x(0.1)
155                * Quaternion::rotation_y(0.1)
156                * Quaternion::rotation_z(-0.7);
157
158            next.wing_out_l.position = Vec3::new(-s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
159            next.wing_out_r.position = Vec3::new(s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
160            next.wing_out_l.orientation = Quaternion::rotation_y(0.2 + short * 0.05)
161                * Quaternion::rotation_z(0.3 + foot2a * 0.3);
162            next.wing_out_r.orientation = Quaternion::rotation_y(-0.2 + short * -0.05)
163                * Quaternion::rotation_z(-0.3 + foot1a * 0.3);
164
165            next.leg_l.position = Vec3::new(
166                -s_a.leg.0,
167                s_a.leg.1 + foot1b * -4.0,
168                s_a.leg.2 + foot2b * -1.5,
169            );
170            next.leg_l.orientation = Quaternion::rotation_x(-0.3 * speednorm + foot1a * 0.15)
171                * Quaternion::rotation_y(tilt * 0.5);
172
173            next.leg_r.position = Vec3::new(
174                s_a.leg.0,
175                s_a.leg.1 + foot2b * -4.0,
176                s_a.leg.2 + foot1b * -1.5,
177            );
178            next.leg_r.orientation = Quaternion::rotation_x(-0.3 * speednorm + foot2a * 0.15)
179                * Quaternion::rotation_y(tilt * 0.5);
180        } else {
181            next.chest.position = Vec3::new(
182                0.0,
183                s_a.chest.0,
184                s_a.chest.1 + short * 0.5 + x_tilt * 10.0 + 0.5 * speednorm,
185            ) * s_a.scaler;
186            next.chest.orientation =
187                Quaternion::rotation_x(short * 0.07 + x_tilt + foot1b.max(foot2b) * 0.2)
188                    * Quaternion::rotation_y(tilt * 0.8 - foot1b * 0.2)
189                    * Quaternion::rotation_z(shortalt * 0.1);
190
191            next.neck.orientation = next.neck.orientation * Quaternion::rotation_y(shortalt * -0.2);
192
193            next.tail_front.position = Vec3::new(0.0, s_a.tail_front.0, s_a.tail_front.1);
194            next.tail_front.orientation = Quaternion::rotation_x(0.6 + short * -0.02);
195
196            next.tail_rear.position = Vec3::new(0.0, s_a.tail_rear.0, s_a.tail_rear.1);
197            next.tail_rear.orientation = Quaternion::rotation_x(-0.2 + short * -0.1);
198
199            next.wing_in_l.position = Vec3::new(-s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
200            next.wing_in_r.position = Vec3::new(s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
201
202            next.wing_in_l.orientation = Quaternion::rotation_y(-0.8) * Quaternion::rotation_z(0.2);
203            next.wing_in_r.orientation = Quaternion::rotation_y(0.8) * Quaternion::rotation_z(-0.2);
204
205            next.wing_mid_l.position = Vec3::new(-s_a.wing_mid.0, s_a.wing_mid.1, s_a.wing_mid.2);
206            next.wing_mid_r.position = Vec3::new(s_a.wing_mid.0, s_a.wing_mid.1, s_a.wing_mid.2);
207            next.wing_mid_l.orientation =
208                Quaternion::rotation_y(-0.1) * Quaternion::rotation_z(0.7);
209            next.wing_mid_r.orientation =
210                Quaternion::rotation_y(0.1) * Quaternion::rotation_z(-0.7);
211
212            next.wing_out_l.position = Vec3::new(-s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
213            next.wing_out_r.position = Vec3::new(s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
214            next.wing_out_l.orientation =
215                Quaternion::rotation_y(-0.2 + short * 0.05) * Quaternion::rotation_z(0.2);
216            next.wing_out_r.orientation =
217                Quaternion::rotation_y(0.2 + short * -0.05) * Quaternion::rotation_z(-0.2);
218
219            next.leg_l.position = Vec3::new(-s_a.leg.0, s_a.leg.1 + foot1b * -5.0, s_a.leg.2);
220            next.leg_l.orientation = Quaternion::rotation_x(-0.2 * speednorm + foot1a * 0.1)
221                * Quaternion::rotation_y(tilt * 0.5 + (foot1a + 1.0) * 0.15);
222
223            next.leg_r.position = Vec3::new(s_a.leg.0, s_a.leg.1 + foot2b * -5.0, s_a.leg.2);
224            next.leg_r.orientation = Quaternion::rotation_x(-0.2 * speednorm + foot2a * 0.1)
225                * Quaternion::rotation_y(tilt * 0.5 - (foot2a + 1.0) * 0.15);
226        }
227        next
228    }
229}