veloren_voxygen_anim/biped_small/
dash.rs1use super::{
2 super::{Animation, vek::*},
3 BipedSmallSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6use std::f32::consts::PI;
7
8pub struct DashAnimation;
9
10type DashAnimationDependency<'a> = (
11 Option<&'a str>,
12 Vec3<f32>,
13 Vec3<f32>,
14 Vec3<f32>,
15 f32,
16 Vec3<f32>,
17 f32,
18 Option<StageSection>,
19 f32,
20);
21
22impl Animation for DashAnimation {
23 type Dependency<'a> = DashAnimationDependency<'a>;
24 type Skeleton = BipedSmallSkeleton;
25
26 #[cfg(feature = "use-dyn-lib")]
27 const UPDATE_FN: &'static [u8] = b"biped_small_dash\0";
28
29 #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "biped_small_dash"))]
30 fn update_skeleton_inner(
31 skeleton: &Self::Skeleton,
32 (
33 ability_id,
34 velocity,
35 _orientation,
36 _last_ori,
37 _global_time,
38 _avg_vel,
39 _acc_vel,
40 stage_section,
41 _timer,
42 ): Self::Dependency<'_>,
43 anim_time: f32,
44 _rate: &mut f32,
45 s_a: &SkeletonAttr,
46 ) -> Self::Skeleton {
47 let mut next = (*skeleton).clone();
48 let speed = Vec2::<f32>::from(velocity).magnitude();
49
50 let fast = (anim_time * 10.0).sin();
51 let fastalt = (anim_time * 10.0 + PI / 2.0).sin();
52
53 let speednorm = speed / 9.4;
54 let speednormcancel = 1.0 - speednorm;
55
56 let (move1base, move2base, move3, move4) = match stage_section {
57 Some(StageSection::Buildup) => (anim_time.sqrt(), 0.0, 0.0, 0.0),
58 Some(StageSection::Charge) => (1.0, anim_time.powi(4), 0.0, 0.0),
59 Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(4), 0.0),
60 Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time),
61 _ => (0.0, 0.0, 0.0, 0.0),
62 };
63 let pullback = 1.0 - move4;
64 let move1abs = move1base * pullback;
65 let move2abs = move2base * pullback;
66
67 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
68 next.head.orientation = Quaternion::rotation_x(move1abs * 0.6)
69 * Quaternion::rotation_z(move1abs * -0.0)
70 * Quaternion::rotation_y(move1abs * 0.3);
71 next.chest.orientation = Quaternion::rotation_x(move1abs * -0.8);
72
73 next.pants.orientation = Quaternion::rotation_x(move1abs * -0.2);
74 match ability_id {
75 Some("common.abilities.vampire.bloodmoon_heiress.dash") => {
76 next.main.position = Vec3::new(0.0, 4.0, -4.0);
77 next.main.orientation = Quaternion::rotation_x(0.0);
78 next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
79 next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
80 next.hand_l.orientation = Quaternion::rotation_x(0.0);
81 next.hand_r.orientation = Quaternion::rotation_x(0.0);
82
83 next.control_l.position = Vec3::new(1.0, 2.0, -2.0);
84 next.control_r.position = Vec3::new(3.0, 2.0, -2.0);
85 next.control.position = Vec3::new(
86 -3.0,
87 s_a.grip.2 + move1abs * -5.0,
88 s_a.grip.2 / 5.0 + move1abs * 4.0,
89 );
90 next.control_l.orientation = Quaternion::rotation_x(PI / 1.5 + move1abs * -0.7)
91 * Quaternion::rotation_y(-0.3);
92 next.control_r.orientation =
93 Quaternion::rotation_x(PI / 1.5 + s_a.grip.0 * 0.2 + move1abs * -0.7)
94 * Quaternion::rotation_y(0.5 + s_a.grip.0 * 0.2);
95 },
96 Some("common.abilities.custom.ochre_legoom.dash") => {
97 next.main.position = Vec3::new(0.0, 3.0, 0.0);
98 next.main.orientation = Quaternion::rotation_x(0.0);
99
100 next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
101 next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
102
103 next.hand_l.orientation = Quaternion::rotation_x(0.0);
104 next.hand_r.orientation = Quaternion::rotation_x(0.0);
105
106 next.control_l.position = Vec3::new(1.0 - s_a.grip.0 * 2.0, 2.0, -2.0);
107 next.control_r.position = Vec3::new(-1.0 + s_a.grip.0 * 2.0, 2.0, 2.0);
108 next.control.position = Vec3::new(
109 -3.0,
110 s_a.grip.2 + move1abs * -5.0,
111 -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + move1abs * 4.0,
112 );
113 next.control_l.orientation =
114 Quaternion::rotation_x(PI / 1.5 + move1abs * -0.7 + move3 * 0.7)
115 * Quaternion::rotation_y(-0.3);
116 next.control_r.orientation = Quaternion::rotation_x(
117 PI / 1.5 + s_a.grip.0 * 0.2 + move1abs * -0.7 + move3 * 0.7,
118 ) * Quaternion::rotation_y(0.5 + s_a.grip.0 * 0.2);
119 },
120 Some("common.abilities.custom.cactid.dash") => {
121 next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
122 next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
123 next.main.position = Vec3::new(0.0, 0.0, 0.0);
124 next.main.orientation = Quaternion::rotation_x(0.0);
125 next.hand_l.orientation = Quaternion::rotation_x(0.0);
126 next.hand_r.orientation = Quaternion::rotation_x(0.0);
127 next.head.orientation = Quaternion::rotation_z(move3 * 1.0);
128 next.chest.orientation = Quaternion::rotation_x(move2abs * -1.0)
129 * Quaternion::rotation_z(move1abs * -1.2 + move2abs * 2.4);
130 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
131 next.hand_l.orientation = Quaternion::rotation_x(1.2);
132 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
133 next.hand_r.orientation = Quaternion::rotation_x(1.2);
134 },
135 _ => {
136 next.main.position = Vec3::new(0.0, 0.0, 0.0);
137 next.main.orientation = Quaternion::rotation_x(0.0);
138
139 next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
140 next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
141
142 next.hand_l.orientation = Quaternion::rotation_x(0.0);
143 next.hand_r.orientation = Quaternion::rotation_x(0.0);
144
145 next.control_l.position = Vec3::new(1.0 - s_a.grip.0 * 2.0, 2.0, -2.0);
146 next.control_r.position = Vec3::new(-1.0 + s_a.grip.0 * 2.0, 2.0, 2.0);
147 next.control.position = Vec3::new(
148 -3.0,
149 s_a.grip.2 + move1abs * -5.0,
150 -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + move1abs * 4.0,
151 );
152 next.control_l.orientation =
153 Quaternion::rotation_x(PI / 1.5 + move1abs * -0.7 + move3 * 0.7)
154 * Quaternion::rotation_y(-0.3);
155 next.control_r.orientation = Quaternion::rotation_x(
156 PI / 1.5 + s_a.grip.0 * 0.2 + move1abs * -0.7 + move3 * 0.7,
157 ) * Quaternion::rotation_y(0.5 + s_a.grip.0 * 0.2);
158 },
159 }
160
161 next.control.orientation = Quaternion::rotation_x(-1.35 + move1abs * 0.6)
162 * Quaternion::rotation_z(move1abs * 0.2)
163 * Quaternion::rotation_y(move2abs * 0.0);
164
165 next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
166 next.tail.orientation = Quaternion::rotation_x(0.05 * fastalt * speednormcancel)
167 * Quaternion::rotation_z(fast * 0.15 * speednormcancel);
168
169 next
170 }
171}