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(
28 feature = "be-dyn-lib",
29 unsafe(export_name = "quadruped_low_leapshockwave")
30 )]
31 fn update_skeleton_inner(
32 skeleton: &Self::Skeleton,
33 (ability_id, _velocity, _global_time, stage_section, heads): Self::Dependency<'_>,
34 anim_time: f32,
35 _rate: &mut f32,
36 s_a: &SkeletonAttr,
37 ) -> Self::Skeleton {
38 let mut next = (*skeleton).clone();
39 let (buildup, movement, action, recover) = match stage_section {
40 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0, 0.0),
41 Some(StageSection::Movement) => (1.0, anim_time, 0.0, 0.0),
42 Some(StageSection::Action) => (1.0, 1.0, anim_time, 0.0),
43 Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time),
44 _ => (0.0, 0.0, 0.0, 0.0),
45 };
46 match ability_id {
47 Some("common.abilities.custom.rocksnapper.leapshockwave") => {
48 let elastic_recover = elastic(recover);
49 next.head_c_upper.scale = Vec3::one() * (1.0 - movement + elastic_recover);
50 next.head_c_upper.position = Vec3::new(
51 0.0,
52 s_a.head_upper.0 + (-1.0 * movement + elastic_recover) * 10.0,
53 s_a.head_upper.1,
54 );
55 next.head_c_lower.scale = Vec3::one()
56 * (1.0 - movement + elastic_recover)
57 * heads[1].is_attached() as i32 as f32;
58 next.head_c_lower.position = Vec3::new(
59 0.0,
60 s_a.head_lower.0 + (-1.0 * movement + elastic_recover) * 15.0,
61 s_a.head_lower.1,
62 );
63 next.tail_front.scale = Vec3::one() * (1.0 - movement + elastic_recover);
64 next.tail_rear.position = Vec3::new(
65 0.0,
66 s_a.tail_rear.0 + (movement - elastic_recover) * 20.0,
67 s_a.tail_rear.1,
68 );
69 next.tail_rear.scale = Vec3::one() * (1.0 - movement + recover);
70 next.foot_fl.scale = Vec3::one() * (1.0 - movement + elastic_recover);
71 next.foot_fl.position = Vec3::new(
72 -s_a.feet_f.0 + (movement - elastic_recover) * 8.0,
73 s_a.feet_f.1 + (-1.0 * movement + elastic_recover) * 8.0,
74 s_a.feet_f.2 - out_and_in(buildup) * 15.0 + (movement - elastic_recover) * 8.0,
75 );
76 next.foot_fr.scale = Vec3::one() * (1.0 - movement + elastic_recover);
77 next.foot_fr.position = Vec3::new(
78 s_a.feet_f.0 - (movement - elastic_recover) * 8.0,
79 s_a.feet_f.1 - (movement - elastic_recover) * 8.0,
80 s_a.feet_f.2 - out_and_in(buildup) * 15.0 + (movement - elastic_recover) * 8.0,
81 );
82 next.foot_bl.scale = Vec3::one() * (1.0 - movement + elastic_recover);
83 next.foot_bl.position = Vec3::new(
84 -s_a.feet_b.0 + (movement - elastic_recover) * 8.0,
85 s_a.feet_b.1 + (movement - elastic_recover) * 8.0,
86 s_a.feet_b.2 - out_and_in(buildup) * 15.0 + (movement - elastic_recover) * 8.0,
87 );
88 next.foot_br.scale = Vec3::one() * (1.0 - movement + elastic_recover);
89 next.foot_br.position = Vec3::new(
90 s_a.feet_b.0 - (movement - elastic_recover) * 8.0,
91 s_a.feet_b.1 + (movement - elastic_recover) * 8.0,
92 s_a.feet_b.2 - out_and_in(buildup) * 15.0 + (movement - elastic_recover) * 8.0,
93 );
94 next.chest.position = Vec3::new(
95 0.0,
96 0.0,
97 s_a.chest.1
98 + out_and_in(buildup) * 15.0
99 + ((action - 1.0).powi(2) - 1.0) * 15.0
100 + elastic_recover * 15.0,
101 );
102 next.chest.orientation = Quaternion::rotation_z(4.0 * PI * movement);
103 },
104 _ => {
105 let (movement1base, movement2base, _movement3base, movement4) = match stage_section
106 {
107 Some(StageSection::Buildup) => (anim_time, 0.0, 0.0, 0.0),
108 Some(StageSection::Movement) => (1.0, anim_time.powf(0.1), 0.0, 0.0),
109 Some(StageSection::Action) => (1.0, 1.0, anim_time.powf(0.1), 0.0),
110 Some(StageSection::Recover) => (0.0, 1.0, 1.0, anim_time.powi(4)),
111 _ => (0.0, 0.0, 0.0, 0.0),
112 };
113 let pullback = 1.0 - movement4;
114 let movement1abs = movement1base * pullback;
115 let movement2abs = movement2base * pullback;
116
117 next.chest.scale = Vec3::one() * s_a.scaler;
118
119 next.chest.position =
120 Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + movement1abs * -0.25);
121 next.chest.orientation = Quaternion::rotation_x(movement2abs * 0.15)
122 * Quaternion::rotation_z((movement1abs * 4.0 * PI).sin() * 0.08);
123 },
124 }
125
126 next
127 }
128}