veloren_voxygen_anim/quadruped_medium/
shockwave.rs1use super::{
2 super::{Animation, vek::*},
3 QuadrupedMediumSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6use std::f32::consts::PI;
8
9pub struct ShockwaveAnimation;
10
11impl Animation for ShockwaveAnimation {
12 type Dependency<'a> = (Option<&'a str>, f32, f32, Option<StageSection>, f32);
13 type Skeleton = QuadrupedMediumSkeleton;
14
15 #[cfg(feature = "use-dyn-lib")]
16 const UPDATE_FN: &'static [u8] = b"quadruped_medium_shockwave\0";
17
18 #[cfg_attr(
19 feature = "be-dyn-lib",
20 unsafe(export_name = "quadruped_medium_shockwave")
21 )]
22 fn update_skeleton_inner(
23 skeleton: &Self::Skeleton,
24 (ability_id, _velocity, global_time, stage_section, timer): Self::Dependency<'_>,
25 anim_time: f32,
26 _rate: &mut f32,
27 _s_a: &SkeletonAttr,
28 ) -> Self::Skeleton {
29 let mut next = (*skeleton).clone();
30
31 let (buildup_base, charge_base, action_base, recover_base, legtell) = match stage_section {
32 Some(StageSection::Buildup) => (anim_time.sqrt(), 0.0, 0.0, 0.0, anim_time),
33 Some(StageSection::Charge) => (1.0, 1.0, 0.0, 0.0, 0.0),
34 Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(4), 0.0, 0.2),
35 Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time, 0.0),
36 _ => (0.0, 0.0, 0.0, 0.0, 0.0),
37 };
38
39 match ability_id {
40 Some("common.abilities.custom.elephant.stomp") => {
41 let buildup = buildup_base;
42 let action = action_base;
43 let action_inv = 1.0 - action_base;
44 let recover_inv = 1.0 - recover_base;
45
46 next.foot_br
47 .orientation
48 .rotate_x(-PI / 8.0 * buildup * action_inv);
49 next.foot_bl
50 .orientation
51 .rotate_x(-PI / 8.0 * buildup * action_inv);
52 next.leg_fr
53 .orientation
54 .rotate_x(PI / 8.0 * buildup * recover_inv);
55 next.leg_fr
56 .orientation
57 .rotate_y(-PI / 12.0 * buildup * action_inv);
58 next.foot_fr
59 .orientation
60 .rotate_x(PI / 4.0 * buildup * action_inv);
61 next.leg_fl
62 .orientation
63 .rotate_x(PI / 8.0 * buildup * recover_inv);
64 next.leg_fl
65 .orientation
66 .rotate_y(PI / 12.0 * buildup * action_inv);
67 next.foot_fl
68 .orientation
69 .rotate_x(PI / 4.0 * buildup * action_inv);
70 next.torso_back
71 .orientation
72 .rotate_x(-PI / 8.0 * buildup * action_inv + PI / 8.0 * action * recover_inv);
73 next.torso_front.position += Vec3::new(0.0, -9.0, 11.0) * buildup * action_inv
74 + Vec3::new(0.0, 0.0, -4.0) * action * recover_inv;
75 next.torso_front
76 .orientation
77 .rotate_x(PI / 4.0 * buildup * action_inv - PI / 8.0 * action * recover_inv);
78 next.head
79 .orientation
80 .rotate_x(PI / 8.0 * buildup * action_inv - PI / 8.0 * action * recover_inv);
81 next.jaw
82 .orientation
83 .rotate_x(PI / 6.0 * buildup * action_inv);
84 next.ears.position += Vec3::new(0.0, -5.0, -2.0) * buildup * action_inv;
85 next.ears
86 .orientation
87 .rotate_x(PI / 4.0 * buildup * recover_inv);
88 },
89 _ => {
90 let pullback = 1.0 - recover_base;
91 let subtract = global_time - timer;
92 let check = subtract - subtract.trunc();
93 let mirror = (check - 0.5).signum();
94 let twitch1 = (mirror * buildup_base * 3.5).sin();
95 let twitch1fast = (mirror * buildup_base * 45.0).sin();
96 let movement1abs = buildup_base * pullback;
100 let movement2abs = action_base * pullback;
101 let legswing = legtell * pullback;
103 let short = ((1.0
104 / (0.72 + 0.28 * ((anim_time * 16.0_f32 + PI * 0.25).sin()).powi(2)))
105 .sqrt())
106 * ((anim_time * 16.0_f32 + PI * 0.25).sin())
107 * charge_base
108 * pullback;
109 let shortalt = (anim_time * 16.0_f32 + PI * 0.25).sin() * charge_base * pullback;
110
111 next.head.orientation =
112 Quaternion::rotation_x(movement1abs * -0.2 + movement2abs * 0.8)
113 * Quaternion::rotation_z(short * -0.06 + twitch1 * 0.2);
114
115 next.neck.orientation =
116 Quaternion::rotation_x(movement1abs * -0.2 + movement2abs * 0.5)
117 * Quaternion::rotation_z(short * 0.15 + twitch1 * 0.2);
118
119 next.jaw.orientation = Quaternion::rotation_x(
120 twitch1fast * 0.2
121 + movement1abs * -0.3
122 + movement2abs * 1.2
123 + charge_base * -0.5,
124 );
125 next.torso_front.orientation = Quaternion::rotation_z(twitch1 * 0.06)
126 * Quaternion::rotation_y(short * 0.06)
127 * Quaternion::rotation_x(legswing * 0.06);
128
129 next.tail.orientation = Quaternion::rotation_x(
130 0.15 + movement1abs * -0.4 + movement2abs * 0.2 + charge_base * 0.2,
131 ) * Quaternion::rotation_z(shortalt * 0.15);
132 next.leg_fl.orientation = Quaternion::rotation_x(legswing * 1.4);
133
134 next.foot_fl.orientation = Quaternion::rotation_x(legswing * -0.5);
135 next.leg_bl.orientation = Quaternion::rotation_x(legswing * 0.3);
136
137 next.foot_bl.orientation = Quaternion::rotation_x(legswing * -0.3);
138
139 next.leg_fr.orientation = Quaternion::rotation_x(legswing * 1.4);
140
141 next.foot_fr.orientation = Quaternion::rotation_x(legswing * -0.5);
142
143 next.leg_br.orientation = Quaternion::rotation_x(legswing * 0.3);
144
145 next.foot_br.orientation = Quaternion::rotation_x(legswing * -0.3);
146 },
147 }
148 next
149 }
150}