veloren_voxygen_anim/golem/
alpha.rs1use super::{
2 super::{Animation, vek::*},
3 GolemSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6use core::f32::consts::PI;
7
8pub struct AlphaAnimation;
9
10impl Animation for AlphaAnimation {
11 type Dependency<'a> = (Option<StageSection>, f32, f32, Option<&'a str>);
12 type Skeleton = GolemSkeleton;
13
14 #[cfg(feature = "use-dyn-lib")]
15 const UPDATE_FN: &'static [u8] = b"golem_alpha\0";
16
17 #[cfg_attr(feature = "be-dyn-lib", export_name = "golem_alpha")]
18
19 fn update_skeleton_inner(
20 skeleton: &Self::Skeleton,
21 (stage_section, global_time, timer, ability_id): Self::Dependency<'_>,
22 anim_time: f32,
23 _rate: &mut f32,
24 s_a: &SkeletonAttr,
25 ) -> Self::Skeleton {
26 let mut next = (*skeleton).clone();
27
28 match ability_id {
29 Some(
30 "common.abilities.custom.stonegolemfist.spin"
31 | "common.abilities.custom.woodgolem.spin"
32 | "common.abilities.custom.coralgolem.spin"
33 | "common.abilities.custom.irongolemfist.spin",
34 ) => {
35 let (movement1, movement2, movement3) = match stage_section {
36 Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0),
37 Some(StageSection::Action) => (1.0, anim_time, 0.0),
38 Some(StageSection::Recover) => (1.0, 1.0, anim_time.powf(4.0)),
39 _ => (0.0, 0.0, 0.0),
40 };
41
42 let pullback = 1.0 - movement3;
43
44 next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1) * 1.02;
45 next.head.orientation =
46 Quaternion::rotation_z(movement1 * 0.5 * PI + movement2 * -2.5 * PI)
47 * Quaternion::rotation_x(-0.2);
48
49 next.upper_torso.position =
50 Vec3::new(0.0, s_a.upper_torso.0, s_a.upper_torso.1 + movement1 * -6.0);
51 next.upper_torso.orientation =
52 Quaternion::rotation_z(movement1 * -0.5 * PI + movement2 * 2.5 * PI);
53
54 next.lower_torso.position = Vec3::new(0.0, s_a.lower_torso.0, s_a.lower_torso.1);
55 next.lower_torso.orientation =
56 Quaternion::rotation_z(movement1 * 0.5 * PI + movement2 * -2.5 * PI);
57
58 next.shoulder_l.position =
59 Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
60 next.shoulder_l.orientation = Quaternion::rotation_x(0.0)
61 * Quaternion::rotation_x(movement1 * 1.2 * pullback);
62
63 next.shoulder_r.position =
64 Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
65 next.shoulder_r.orientation = Quaternion::rotation_x(0.0)
66 * Quaternion::rotation_x(movement1 * -1.2 * pullback);
67
68 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
69 next.hand_l.orientation = Quaternion::rotation_x(movement1 * -0.2 * pullback);
70
71 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
72 next.hand_r.orientation = Quaternion::rotation_x(movement1 * 0.2 * pullback);
73
74 next.leg_l.position =
75 Vec3::new(-s_a.leg.0, s_a.leg.1, s_a.leg.2 + movement1 * 2.0) * 1.02;
76 next.leg_l.orientation = Quaternion::rotation_x(0.0);
77
78 next.leg_r.position =
79 Vec3::new(s_a.leg.0, s_a.leg.1, s_a.leg.2 + movement1 * 2.0) * 1.02;
80 next.leg_r.orientation = Quaternion::rotation_x(0.0);
81
82 next.foot_l.position =
83 Vec3::new(-s_a.foot.0, s_a.foot.1, s_a.foot.2 + movement1 * 4.0);
84 next.foot_l.orientation = Quaternion::rotation_x(0.0);
85
86 next.foot_r.position =
87 Vec3::new(s_a.foot.0, s_a.foot.1, s_a.foot.2 + movement1 * 4.0);
88 next.foot_r.orientation = Quaternion::rotation_x(0.0);
89
90 next.torso.position = Vec3::new(0.0, 0.0, 0.0);
91 next.torso.orientation = Quaternion::rotation_z(0.0);
92 },
93 _ => {
94 let (move1base, move2base, move3) = match stage_section {
95 Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0),
96 Some(StageSection::Action) => (1.0, anim_time, 0.0),
97 Some(StageSection::Recover) => (1.0, 1.0, anim_time.powf(4.0)),
98 _ => (0.0, 0.0, 0.0),
99 };
100
101 let pullback = 1.0 - move3;
102 let subtract = global_time - timer;
103 let check = subtract - subtract.trunc();
104 let mirror = (check - 0.5).signum();
105
106 let move1 = move1base * pullback;
107 let move2 = move2base * pullback;
108 if mirror > 0.0 {
109 next.head.orientation = Quaternion::rotation_x(-0.2)
110 * Quaternion::rotation_z(move1 * -1.2 + move2 * 2.0);
111
112 next.upper_torso.orientation = Quaternion::rotation_x(move1 * -0.6)
113 * Quaternion::rotation_z(move1 * 1.2 + move2 * -3.2);
114
115 next.lower_torso.orientation =
116 Quaternion::rotation_z(move1 * -1.2 + move2 * 3.2)
117 * Quaternion::rotation_x(move1 * 0.6);
118
119 next.shoulder_l.orientation = Quaternion::rotation_y(move1 * 0.8)
120 * Quaternion::rotation_x(move1 * -1.0 + move2 * 1.6);
121
122 next.shoulder_r.orientation = Quaternion::rotation_x(move1 * 0.4);
123
124 next.hand_l.orientation = Quaternion::rotation_z(0.0)
125 * Quaternion::rotation_x(move1 * -1.0 + move2 * 1.8);
126
127 next.hand_r.orientation =
128 Quaternion::rotation_y(move1 * 0.5) * Quaternion::rotation_x(move1 * 0.4);
129 } else {
130 next.head.orientation = Quaternion::rotation_x(-0.2)
131 * Quaternion::rotation_z(move1 * 1.2 + move2 * -2.0);
132
133 next.upper_torso.orientation = Quaternion::rotation_x(move1 * -0.6)
134 * Quaternion::rotation_z(move1 * -1.2 + move2 * 3.2);
135
136 next.lower_torso.orientation =
137 Quaternion::rotation_z(move1 * 1.2 + move2 * -3.2)
138 * Quaternion::rotation_x(move1 * 0.6);
139
140 next.shoulder_l.orientation = Quaternion::rotation_x(move1 * 0.4);
141
142 next.shoulder_r.orientation = Quaternion::rotation_y(move1 * -0.8)
143 * Quaternion::rotation_x(move1 * -1.0 + move2 * 1.6);
144
145 next.hand_l.orientation =
146 Quaternion::rotation_y(move1 * -0.5) * Quaternion::rotation_x(move1 * 0.4);
147
148 next.hand_r.orientation = Quaternion::rotation_y(0.0)
149 * Quaternion::rotation_x(move1 * -1.0 + move2 * 1.8);
150 };
151 next.torso.position = Vec3::new(0.0, move1 * 3.7, move1 * -1.6);
152 },
153 }
154
155 next
156 }
157}