veloren_voxygen_anim/quadruped_low/
tailwhip.rs1use std::f32::consts::PI;
2
3use super::{
4 super::{Animation, vek::*},
5 QuadrupedLowSkeleton, SkeletonAttr,
6};
7use common::states::utils::StageSection;
8
9pub struct TailwhipAnimation;
10
11impl Animation for TailwhipAnimation {
12 type Dependency<'a> = (Option<&'a str>, f32, f32, Option<StageSection>, f32);
13 type Skeleton = QuadrupedLowSkeleton;
14
15 #[cfg(feature = "use-dyn-lib")]
16 const UPDATE_FN: &'static [u8] = b"quadruped_low_tailwhip\0";
17
18 #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_low_tailwhip")]
19 fn update_skeleton_inner(
20 skeleton: &Self::Skeleton,
21 (ability_id, _velocity, global_time, stage_section, timer): 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 let subtract = global_time - timer;
29 let check = subtract - subtract.trunc();
30 let mirror = (check - 0.5).signum();
31 match ability_id {
32 Some("common.abilities.custom.hydra.tail_swipe") => match stage_section {
33 Some(StageSection::Charge) => {
34 let rotate_t = mirror * anim_time * 2.0 / (1.0 + anim_time * 2.0);
35 let shake = (anim_time * 15.0).sin() * 0.05;
36
37 next.chest.orientation = Quaternion::rotation_z(0.2 * rotate_t + shake * 0.1);
38
39 next.tail_front.orientation = Quaternion::rotation_z(0.7 * rotate_t + shake);
40
41 next.tail_rear.orientation = Quaternion::rotation_z(0.8 * rotate_t + shake);
42
43 next.foot_fl.orientation = Quaternion::rotation_x(-0.15 * rotate_t);
44 next.foot_bl.orientation = Quaternion::rotation_x(-0.25 * rotate_t);
45 next.foot_fr.orientation = Quaternion::rotation_x(0.15 * rotate_t);
46 next.foot_br.orientation = Quaternion::rotation_x(0.25 * rotate_t);
47 },
48 Some(StageSection::Action) => {
49 let rotate_t = mirror * -anim_time * 30.0 / (4.0 + anim_time * 30.0) * PI * 2.3;
50
51 next.chest.orientation = Quaternion::rotation_z(rotate_t);
52 },
53 Some(StageSection::Recover) => {},
54 _ => {},
55 },
56 _ => {
57 let (movement1base, movement2base, movement3, twitch1, twitch2) =
58 match stage_section {
59 Some(StageSection::Charge) => {
60 (anim_time.min(1.2), 0.0, 0.0, (anim_time * 15.0).sin(), 0.0)
61 },
62 Some(StageSection::Action) => (1.0, anim_time.powi(4), 0.0, 1.0, 0.0),
63 Some(StageSection::Recover) => {
64 (1.0, 1.0, anim_time.powi(6), 1.0, (anim_time * 7.0).sin())
65 },
66 _ => (0.0, 0.0, 0.0, 0.0, 0.0),
67 };
68 let pullback = 1.0 - movement3;
69 let movement1 = mirror * movement1base * pullback;
70 let movement2 = mirror * movement2base * pullback;
71 let movement1abs = movement1base * pullback;
72 let movement1nopull = mirror * movement1base;
73 let movement2nopull = mirror * movement2base;
74
75 next.head_c_upper.orientation =
77 Quaternion::rotation_z(movement1 * 0.6 + movement2 * -1.2);
78
79 next.head_c_lower.orientation =
80 Quaternion::rotation_z(movement1 * 0.7 + movement2 * -1.6);
81
82 next.jaw_c.orientation = Quaternion::rotation_x(movement1 * -0.1 + movement2 * 0.1);
83
84 next.head_l_upper.orientation =
86 Quaternion::rotation_z(movement1 * 0.6 + movement2 * -1.2);
87
88 next.head_l_lower.orientation =
89 Quaternion::rotation_z(movement1 * 0.7 + movement2 * -1.6);
90
91 next.jaw_l.orientation = Quaternion::rotation_x(movement1 * -0.1 + movement2 * 0.1);
92
93 next.head_r_upper.orientation =
95 Quaternion::rotation_z(movement1 * 0.6 + movement2 * -1.2);
96
97 next.head_r_lower.orientation =
98 Quaternion::rotation_z(movement1 * 0.7 + movement2 * -1.6);
99
100 next.jaw_r.orientation = Quaternion::rotation_x(movement1 * -0.1 + movement2 * 0.1);
101
102 next.chest.orientation = Quaternion::rotation_z(
103 (mirror * twitch1 * 0.02 + movement1nopull * -0.4 + movement2nopull * 3.0)
104 + (movement3 * 4.0 * mirror)
105 + twitch2 * 0.1 * mirror,
106 );
107
108 next.tail_front.orientation = Quaternion::rotation_x(0.15 + (movement1abs * -0.4))
109 * Quaternion::rotation_z(
110 mirror * twitch1 * 0.15
111 + movement1 * -0.6
112 + movement2 * 0.9
113 + twitch2 * 0.3 * mirror,
114 );
115 next.tail_rear.position = Vec3::new(0.0, s_a.tail_rear.0, s_a.tail_rear.1);
116
117 next.tail_rear.orientation = Quaternion::rotation_x(-0.12 + (movement1abs * -0.45))
118 * Quaternion::rotation_z(
119 mirror * twitch1 * 0.2
120 + movement1 * -0.6
121 + movement2 * 0.7
122 + twitch2 * 0.3 * mirror,
123 );
124 },
125 }
126
127 next
128 }
129}