veloren_voxygen_anim/bird_large/
dash.rs1use super::{
2 super::{Animation, vek::*},
3 BirdLargeSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6use std::f32::consts::PI;
7
8pub struct DashAnimation;
9type DashAnimationDependency<'a> = (
10 Vec3<f32>,
11 Vec3<f32>,
12 Vec3<f32>,
13 f32,
14 Option<StageSection>,
15 f32,
16 f32,
17);
18
19impl Animation for DashAnimation {
20 type Dependency<'a> = DashAnimationDependency<'a>;
21 type Skeleton = BirdLargeSkeleton;
22
23 #[cfg(feature = "use-dyn-lib")]
24 const UPDATE_FN: &'static [u8] = b"bird_large_dash\0";
25
26 #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_large_dash")]
27 fn update_skeleton_inner(
28 skeleton: &Self::Skeleton,
29 (velocity, orientation, last_ori, acc_vel, stage_section, global_time, timer): Self::Dependency<'_>,
30 anim_time: f32,
31 rate: &mut f32,
32 s_a: &SkeletonAttr,
33 ) -> Self::Skeleton {
34 let mut next = (*skeleton).clone();
35 let speed = (Vec2::<f32>::from(velocity).magnitude()).min(22.0);
36 *rate = 1.0;
37
38 let (movement1base, chargemovementbase, movement2base, movement3, legtell) =
39 match stage_section {
40 Some(StageSection::Buildup) => (anim_time.sqrt(), 0.0, 0.0, 0.0, anim_time),
41 Some(StageSection::Charge) => (1.0, 1.0, 0.0, 0.0, 0.0),
42 Some(StageSection::Action) => (1.0, 0.0, anim_time.powi(4), 0.0, 1.0),
43 Some(StageSection::Recover) => (1.0, 0.0, 1.0, anim_time, 1.0),
44 _ => (0.0, 0.0, 0.0, 0.0, 0.0),
45 };
46 let pullback = 1.0 - movement3;
47 let subtract = global_time - timer;
48 let check = subtract - subtract.trunc();
49 let mirror = (check - 0.5).signum();
50 let movement1abs = movement1base * pullback;
51 let movement2abs = movement2base * pullback;
52 let legtwitch = (legtell * 6.0).sin() * pullback;
53 let legswing = legtell * pullback;
54 let chargeanim = (chargemovementbase * anim_time * 15.0).sin();
55
56 let speednorm = (speed / 13.0).powf(0.25);
58
59 let speedmult = 0.8;
60 let lab: f32 = 0.6; let mixed_vel = acc_vel + anim_time * 5.0; let short = ((1.0
67 / (0.72
68 + 0.28 * ((mixed_vel * 1.0 * lab * speedmult + PI * -0.15 - 0.5).sin()).powi(2)))
69 .sqrt())
70 * ((mixed_vel * 1.0 * lab * speedmult + PI * -0.15 - 0.5).sin())
71 * speednorm;
72
73 let shortalt = (mixed_vel * 1.0 * lab * speedmult + PI * 3.0 / 8.0 - 0.5).sin() * speednorm;
75
76 let ori: Vec2<f32> = Vec2::from(orientation);
77 let last_ori = Vec2::from(last_ori);
78 let tilt = if vek::Vec2::new(ori, last_ori)
79 .map(|o| o.magnitude_squared())
80 .map(|m| m > 0.001 && m.is_finite())
81 .reduce_and()
82 && ori.angle_between(last_ori).is_finite()
83 {
84 ori.angle_between(last_ori).min(0.2)
85 * last_ori.determine_side(Vec2::zero(), ori).signum()
86 } else {
87 0.0
88 } * 1.3;
89
90 next.head.scale = Vec3::one() * 0.98;
91 next.neck.scale = Vec3::one() * 1.02;
92 next.leg_l.scale = Vec3::one() * 0.98;
93 next.leg_r.scale = Vec3::one() * 0.98;
94 next.foot_l.scale = Vec3::one() * 1.02;
95 next.foot_r.scale = Vec3::one() * 1.02;
96
97 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
98 next.head.orientation = Quaternion::rotation_x(
99 -0.1 * speednorm + short * -0.05 + movement1abs * -0.8 + movement2abs * 0.2,
100 ) * Quaternion::rotation_y(tilt * 0.2)
101 * Quaternion::rotation_z(shortalt * -0.05 - tilt * 1.5);
102
103 next.beak.position = Vec3::new(0.0, s_a.beak.0, s_a.beak.1);
104 next.beak.orientation =
105 Quaternion::rotation_x(short * -0.02 - 0.02 + movement1abs * -0.4 + movement2abs * 0.4);
106
107 next.neck.position = Vec3::new(0.0, s_a.neck.0, s_a.neck.1);
108 next.neck.orientation = Quaternion::rotation_x(-0.1 * speednorm + short * -0.04)
109 * Quaternion::rotation_y(tilt * 0.1)
110 * Quaternion::rotation_z(shortalt * -0.1 - tilt * 0.5);
111
112 next.chest.position = Vec3::new(
113 0.0,
114 s_a.chest.0,
115 s_a.chest.1 + short * 0.5 + 0.5 * speednorm,
116 );
117 next.chest.orientation =
118 Quaternion::rotation_x(short * 0.07 + movement1abs * 0.8 + movement2abs * -1.2)
119 * Quaternion::rotation_y(tilt * 0.8)
120 * Quaternion::rotation_z(shortalt * 0.10);
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 =
124 Quaternion::rotation_x(0.6 + short * -0.02 + movement1abs * -0.8 + movement2abs * 0.8);
125
126 next.tail_rear.position = Vec3::new(0.0, s_a.tail_rear.0, s_a.tail_rear.1);
127 next.tail_rear.orientation = Quaternion::rotation_x(-0.2 + short * -0.1);
128
129 next.wing_in_l.position = Vec3::new(-s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
130 next.wing_in_r.position = Vec3::new(s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
131
132 next.wing_in_l.orientation =
133 Quaternion::rotation_y(
134 -0.8 + movement1abs * 1.0 + chargeanim * 0.2 - movement2abs * 0.6,
135 ) * Quaternion::rotation_z(0.2 - movement1abs * 0.6 - movement2abs * 0.6);
136 next.wing_in_r.orientation =
137 Quaternion::rotation_y(
138 0.8 - movement1abs * 1.0 - chargeanim * 0.2 + movement2abs * 0.6,
139 ) * Quaternion::rotation_z(-0.2 + movement1abs * 0.6 + movement2abs * 0.6);
140
141 next.wing_mid_l.position = Vec3::new(-s_a.wing_mid.0, s_a.wing_mid.1, s_a.wing_mid.2);
142 next.wing_mid_r.position = Vec3::new(s_a.wing_mid.0, s_a.wing_mid.1, s_a.wing_mid.2);
143 next.wing_mid_l.orientation = Quaternion::rotation_y(-0.1) * Quaternion::rotation_z(0.7);
144 next.wing_mid_r.orientation = Quaternion::rotation_y(0.1) * Quaternion::rotation_z(-0.7);
145
146 next.wing_out_l.position = Vec3::new(-s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
147 next.wing_out_r.position = Vec3::new(s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
148 next.wing_out_l.orientation =
149 Quaternion::rotation_y(-0.2 + short * 0.05) * Quaternion::rotation_z(0.2);
150 next.wing_out_r.orientation =
151 Quaternion::rotation_y(0.2 + short * -0.05) * Quaternion::rotation_z(-0.2);
152
153 if legtell > 0.0 {
154 if mirror.is_sign_positive() {
155 next.leg_l.orientation = Quaternion::rotation_x(legswing * 1.1);
156
157 next.foot_l.orientation = Quaternion::rotation_x(legswing * -1.1 + legtwitch * 0.5);
158
159 next.leg_r.orientation = Quaternion::rotation_x(0.0);
160
161 next.foot_r.orientation = Quaternion::rotation_x(0.0);
162 } else {
163 next.leg_l.orientation = Quaternion::rotation_x(0.0);
164
165 next.foot_l.orientation = Quaternion::rotation_x(0.0);
166
167 next.leg_r.orientation = Quaternion::rotation_x(legswing * 1.1);
168
169 next.foot_r.orientation = Quaternion::rotation_x(legswing * -1.1 + legtwitch * 0.5);
170 }
171 }
172
173 next
174 }
175}