veloren_voxygen_anim/quadruped_low/
leapshockwave.rs1use super::{
2 super::{
3 Animation,
4 util::{elastic, out_and_in},
5 vek::*,
6 },
7 QuadrupedLowSkeleton, SkeletonAttr,
8};
9use common::{comp::body::parts::HeadState, states::utils::StageSection};
10use core::f32::consts::PI;
11
12pub struct LeapShockAnimation;
13
14impl Animation for LeapShockAnimation {
15 type Dependency<'a> = (
16 Option<&'a str>,
17 Vec3<f32>,
18 f32,
19 Option<StageSection>,
20 [HeadState; 3],
21 );
22 type Skeleton = QuadrupedLowSkeleton;
23
24 #[cfg(feature = "use-dyn-lib")]
25 const UPDATE_FN: &'static [u8] = b"quadruped_low_leapshockwave\0";
26
27 #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_low_leapshockwave")]
28 fn update_skeleton_inner(
29 skeleton: &Self::Skeleton,
30 (ability_id, _velocity, _global_time, stage_section, heads): Self::Dependency<'_>,
31 anim_time: f32,
32 _rate: &mut f32,
33 s_a: &SkeletonAttr,
34 ) -> Self::Skeleton {
35 let mut next = (*skeleton).clone();
36 let (buildup, movement, action, recover) = match stage_section {
37 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0, 0.0),
38 Some(StageSection::Movement) => (1.0, anim_time, 0.0, 0.0),
39 Some(StageSection::Action) => (1.0, 1.0, anim_time, 0.0),
40 Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time),
41 _ => (0.0, 0.0, 0.0, 0.0),
42 };
43 match ability_id {
44 Some("common.abilities.custom.rocksnapper.leapshockwave") => {
45 let elastic_recover = elastic(recover);
46 next.head_c_upper.scale = Vec3::one() * (1.0 - movement + elastic_recover);
47 next.head_c_upper.position = Vec3::new(
48 0.0,
49 s_a.head_upper.0 + (-1.0 * movement + elastic_recover) * 10.0,
50 s_a.head_upper.1,
51 );
52 next.head_c_lower.scale = Vec3::one()
53 * (1.0 - movement + elastic_recover)
54 * heads[1].is_attached() as i32 as f32;
55 next.head_c_lower.position = Vec3::new(
56 0.0,
57 s_a.head_lower.0 + (-1.0 * movement + elastic_recover) * 15.0,
58 s_a.head_lower.1,
59 );
60 next.tail_front.scale = Vec3::one() * (1.0 - movement + elastic_recover);
61 next.tail_rear.position = Vec3::new(
62 0.0,
63 s_a.tail_rear.0 + (movement - elastic_recover) * 20.0,
64 s_a.tail_rear.1,
65 );
66 next.tail_rear.scale = Vec3::one() * (1.0 - movement + recover);
67 next.foot_fl.scale = Vec3::one() * (1.0 - movement + elastic_recover);
68 next.foot_fl.position = Vec3::new(
69 -s_a.feet_f.0 + (movement - elastic_recover) * 8.0,
70 s_a.feet_f.1 + (-1.0 * movement + elastic_recover) * 8.0,
71 s_a.feet_f.2 - out_and_in(buildup) * 15.0 + (movement - elastic_recover) * 8.0,
72 );
73 next.foot_fr.scale = Vec3::one() * (1.0 - movement + elastic_recover);
74 next.foot_fr.position = Vec3::new(
75 s_a.feet_f.0 - (movement - elastic_recover) * 8.0,
76 s_a.feet_f.1 - (movement - elastic_recover) * 8.0,
77 s_a.feet_f.2 - out_and_in(buildup) * 15.0 + (movement - elastic_recover) * 8.0,
78 );
79 next.foot_bl.scale = Vec3::one() * (1.0 - movement + elastic_recover);
80 next.foot_bl.position = Vec3::new(
81 -s_a.feet_b.0 + (movement - elastic_recover) * 8.0,
82 s_a.feet_b.1 + (movement - elastic_recover) * 8.0,
83 s_a.feet_b.2 - out_and_in(buildup) * 15.0 + (movement - elastic_recover) * 8.0,
84 );
85 next.foot_br.scale = Vec3::one() * (1.0 - movement + elastic_recover);
86 next.foot_br.position = Vec3::new(
87 s_a.feet_b.0 - (movement - elastic_recover) * 8.0,
88 s_a.feet_b.1 + (movement - elastic_recover) * 8.0,
89 s_a.feet_b.2 - out_and_in(buildup) * 15.0 + (movement - elastic_recover) * 8.0,
90 );
91 next.chest.position = Vec3::new(
92 0.0,
93 0.0,
94 s_a.chest.1
95 + out_and_in(buildup) * 15.0
96 + ((action - 1.0).powi(2) - 1.0) * 15.0
97 + elastic_recover * 15.0,
98 );
99 next.chest.orientation = Quaternion::rotation_z(4.0 * PI * movement);
100 },
101 _ => {
102 let (movement1base, movement2base, _movement3base, movement4) = match stage_section
103 {
104 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0, 0.0),
105 Some(StageSection::Movement) => (1.0, anim_time.powf(0.1), 0.0, 0.0),
106 Some(StageSection::Action) => (1.0, 1.0, anim_time.powf(0.1), 0.0),
107 Some(StageSection::Recover) => (0.0, 1.0, 1.0, anim_time.powi(4)),
108 _ => (0.0, 0.0, 0.0, 0.0),
109 };
110 let pullback = 1.0 - movement4;
111 let movement1abs = movement1base * pullback;
112 let movement2abs = movement2base * pullback;
113
114 next.chest.scale = Vec3::one() * s_a.scaler;
115
116 next.chest.position =
117 Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + movement1abs * -0.25);
118 next.chest.orientation = Quaternion::rotation_x(movement2abs * 0.15)
119 * Quaternion::rotation_z((movement1abs * 4.0 * PI).sin() * 0.08);
120 },
121 }
122
123 next
124 }
125}