veloren_voxygen_anim/biped_small/
shockwave.rs1use super::{
2 super::{Animation, vek::*},
3 BipedSmallSkeleton, SkeletonAttr,
4};
5use common::{comp::item::ToolKind, states::utils::StageSection};
6use std::f32::consts::PI;
7
8pub struct ShockwaveAnimation;
9
10type ShockwaveAnimationDependency = (
11 Option<ToolKind>,
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 ShockwaveAnimation {
23 type Dependency<'a> = ShockwaveAnimationDependency;
24 type Skeleton = BipedSmallSkeleton;
25
26 #[cfg(feature = "use-dyn-lib")]
27 const UPDATE_FN: &'static [u8] = b"biped_small_shockwave\0";
28
29 #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_small_shockwave")]
30
31 fn update_skeleton_inner(
32 skeleton: &Self::Skeleton,
33 (
34 active_tool_kind,
35 _velocity,
36 _orientation,
37 _last_ori,
38 global_time,
39 _avg_vel,
40 _acc_vel,
41 stage_section,
42 timer,
43 ): Self::Dependency<'_>,
44 anim_time: f32,
45 _rate: &mut f32,
46 s_a: &SkeletonAttr,
47 ) -> Self::Skeleton {
48 let mut next = (*skeleton).clone();
49
50 let anim_time = anim_time.min(1.0);
51 let (move1base, twitch, move2base, move3) = match stage_section {
52 Some(StageSection::Buildup) => (anim_time.sqrt(), (anim_time * 13.0).sin(), 0.0, 0.0),
53 Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(4), 0.0),
54 Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time),
55 _ => (0.0, 0.0, 0.0, 0.0),
56 };
57 let pullback = 1.0 - move3;
58 let twitch = twitch * pullback;
59 let subtract = global_time - timer;
60 let check = subtract - subtract.trunc();
61 let mirror = (check - 0.5).signum();
62 let move1 = move1base * pullback * mirror;
63 let move2 = move2base * pullback * mirror;
64 let move1abs = move1base * pullback;
65 let move2abs = move2base * pullback;
66 next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
67 next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
68 next.main.position = Vec3::new(0.0, 0.0, 0.0);
69 next.main.orientation = Quaternion::rotation_x(0.0);
70 next.hand_l.orientation = Quaternion::rotation_x(0.0);
71 next.hand_r.orientation = Quaternion::rotation_x(0.0);
72 match active_tool_kind {
73 Some(ToolKind::Staff) => {
74 next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
75 next.control_r.position = Vec3::new(
76 7.0 + s_a.grip.0 * 2.0 + move1abs * -8.0,
77 -4.0 + move1abs * 5.0,
78 3.0,
79 );
80
81 next.control.position = Vec3::new(
82 -5.0 + move1abs * 5.0,
83 -1.0 + s_a.grip.2 + move1abs * 3.0 + move2abs * 5.0,
84 -2.0 + -s_a.grip.2 / 2.5
85 + s_a.grip.0 * -2.0
86 + move1abs * 12.0
87 + move2abs * -13.0,
88 );
89
90 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
91 * Quaternion::rotation_y(-0.3)
92 * Quaternion::rotation_z(-0.3);
93 next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
94 * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2)
95 * Quaternion::rotation_z(-0.0);
96
97 next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * 0.2)
98 * Quaternion::rotation_y(0.0)
99 * Quaternion::rotation_z(0.5);
100 next.chest.orientation = Quaternion::rotation_x(move1abs * 0.5 + move2abs * -1.0);
101 next.head.orientation =
102 Quaternion::rotation_x(move1abs * 0.5) * Quaternion::rotation_y(twitch * 0.5);
103 next.main.orientation = Quaternion::rotation_z(move1abs * 0.5 + move2abs * 0.9);
104 },
105 Some(ToolKind::Sword) => {
106 let rotate = move1 * 2.0 * PI + move2 * 2.0 * PI;
107 let jump = move1 + 3.0 + move2 * -3.0;
108 next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
109 next.control_r.position = Vec3::new(
110 7.0 + s_a.grip.0 * 2.0 + move1abs * -8.0,
111 -4.0 + move1abs * 5.0,
112 3.0,
113 );
114
115 next.control.position = Vec3::new(
116 -5.0 + move1abs * 5.0,
117 -1.0 + s_a.grip.2 + move1abs * 3.0 + move2abs * 5.0,
118 -2.0 + -s_a.grip.2 / 2.5
119 + s_a.grip.0 * -2.0
120 + move1abs * 12.0
121 + move2abs * -13.0,
122 );
123
124 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
125 * Quaternion::rotation_y(-0.3)
126 * Quaternion::rotation_z(-0.3);
127 next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
128 * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2)
129 * Quaternion::rotation_z(-0.0);
130
131 next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * 0.2)
132 * Quaternion::rotation_y(0.0)
133 * Quaternion::rotation_z(0.5);
134 next.chest.orientation = Quaternion::rotation_x(move1abs * 0.5 + move2abs * -1.0);
135 next.head.orientation =
136 Quaternion::rotation_x(move1abs * 0.5) * Quaternion::rotation_y(twitch * 0.5);
137 next.main.orientation = Quaternion::rotation_z(move1abs * 0.5 + move2abs * 0.9);
138 next.chest.orientation = Quaternion::rotation_z(rotate + (1.0 - move3));
139
140 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + jump);
141 },
142 _ => {
143 next.chest.orientation = Quaternion::rotation_x(move2abs * -1.0)
144 * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
145 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
146 next.hand_l.orientation = Quaternion::rotation_x(1.2);
147 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
148 next.hand_r.orientation = Quaternion::rotation_x(1.2);
149 },
150 }
151 next
152 }
153}