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