veloren_voxygen_anim/biped_small/
beam.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 BeamAnimation;
9
10type BeamAnimationDependency<'a> = (
11 Option<&'a str>,
12 Option<ToolKind>,
13 Vec3<f32>,
14 Vec3<f32>,
15 Vec3<f32>,
16 f32,
17 Vec3<f32>,
18 f32,
19 Option<StageSection>,
20 f32,
21);
22
23impl Animation for BeamAnimation {
24 type Dependency<'a> = BeamAnimationDependency<'a>;
25 type Skeleton = BipedSmallSkeleton;
26
27 #[cfg(feature = "use-dyn-lib")]
28 const UPDATE_FN: &'static [u8] = b"biped_small_beam\0";
29
30 #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_small_beam")]
31
32 fn update_skeleton_inner(
33 skeleton: &Self::Skeleton,
34 (
35 ability_id,
36 _active_tool_kind,
37 velocity,
38 _orientation,
39 _last_ori,
40 _global_time,
41 _avg_vel,
42 _acc_vel,
43 stage_section,
44 _timer,
45 ): Self::Dependency<'_>,
46 anim_time: f32,
47 _rate: &mut f32,
48 s_a: &SkeletonAttr,
49 ) -> Self::Skeleton {
50 let mut next = (*skeleton).clone();
51 let speed = Vec2::<f32>::from(velocity).magnitude();
52
53 let fast = (anim_time * 10.0).sin();
54 let fastalt = (anim_time * 10.0 + PI / 2.0).sin();
55
56 let speednorm = speed / 9.4;
57 let speednormcancel = 1.0 - speednorm;
58
59 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + fast * -0.1 * speednormcancel);
60 next.head.orientation = Quaternion::rotation_x(0.45 * speednorm)
61 * Quaternion::rotation_y(fast * 0.07 * speednormcancel);
62 next.chest.position = Vec3::new(
63 0.0,
64 s_a.chest.0,
65 s_a.chest.1 + fastalt * 0.4 * speednormcancel + speednormcancel * -0.5,
66 );
67
68 next.pants.position = Vec3::new(0.0, s_a.pants.0, s_a.pants.1);
69
70 next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
71 next.tail.orientation = Quaternion::rotation_x(0.05 * fastalt * speednormcancel)
72 * Quaternion::rotation_z(fast * 0.15 * speednormcancel);
73
74 next.main.position = Vec3::new(0.0, 0.0, 0.0);
75 next.main.orientation = Quaternion::rotation_x(0.0);
76
77 next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
78 next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
79
80 next.hand_l.orientation = Quaternion::rotation_x(0.0);
81 next.hand_r.orientation = Quaternion::rotation_x(0.0);
82
83 let (move1base, move2base, move3) = match stage_section {
84 Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0),
85 Some(StageSection::Action) => (1.0, (anim_time * 4.0).sin(), 0.0),
86 Some(StageSection::Recover) => (1.0, 1.0, anim_time),
87 _ => (0.0, 0.0, 0.0),
88 };
89 let pullback = 1.0 - move3;
90 let move1abs = move1base * pullback;
91
92 next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
93 next.control_r.position = Vec3::new(
94 7.0 + s_a.grip.0 * 2.0 + move1abs * -8.0,
95 -4.0 + move1abs * 0.0,
96 3.0 + move1abs * 10.0,
97 );
98 match ability_id {
99 Some("common.abilities.custom.dwarves.flamekeeper.flamethrower") => {
100 next.control.position = Vec3::new(
101 -9.0,
102 -1.0 + s_a.grip.2,
103 -8.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + move1abs * 5.0,
104 );
105
106 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + move1abs * 0.8)
107 * Quaternion::rotation_y(-0.3)
108 * Quaternion::rotation_z(-0.3);
109 next.control_r.orientation =
110 Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2 + move1abs * 0.8)
111 * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2 + move1abs * 0.8)
112 * Quaternion::rotation_z(-0.0 + move1abs * 2.0 + move2base * 0.6);
113
114 next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * -0.6)
115 * Quaternion::rotation_y(-0.2 * speednorm + move1abs * 0.8)
116 * Quaternion::rotation_z(0.5 + move1abs * 0.6);
117 },
118 _ => {
119 next.control.position = Vec3::new(
120 -5.0,
121 -1.0 + s_a.grip.2,
122 -2.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + move1abs * 5.0,
123 );
124
125 next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + move1abs * 0.8)
126 * Quaternion::rotation_y(-0.3)
127 * Quaternion::rotation_z(-0.3);
128 next.control_r.orientation =
129 Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2 + move1abs * 0.8)
130 * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2 + move1abs * 0.8)
131 * Quaternion::rotation_z(-0.0 + move1abs * 2.0 + move2base * 0.6);
132
133 next.control.orientation = Quaternion::rotation_x(-0.3 + move1abs * -0.6)
134 * Quaternion::rotation_y(-0.2 * speednorm + move1abs * 0.8)
135 * Quaternion::rotation_z(0.5 + move1abs * 0.6);
136 },
137 }
138 next
139 }
140}