veloren_voxygen_anim/quadruped_medium/
hoof.rs1use super::{
2 super::{Animation, vek::*},
3 QuadrupedMediumSkeleton, SkeletonAttr,
4};
5use common::states::utils::StageSection;
6use std::f32::consts::PI;
7
8pub struct HoofAnimation;
9
10impl Animation for HoofAnimation {
11 type Dependency<'a> = (f32, f32, Option<StageSection>, f32);
12 type Skeleton = QuadrupedMediumSkeleton;
13
14 #[cfg(feature = "use-dyn-lib")]
15 const UPDATE_FN: &'static [u8] = b"quadruped_medium_hoof\0";
16
17 #[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_hoof")]
18 fn update_skeleton_inner(
19 skeleton: &Self::Skeleton,
20 (velocity, global_time, stage_section, timer): Self::Dependency<'_>,
21 anim_time: f32,
22 _rate: &mut f32,
23 s_a: &SkeletonAttr,
24 ) -> Self::Skeleton {
25 let mut next = (*skeleton).clone();
26 let speed = (Vec2::<f32>::from(velocity).magnitude()).min(24.0);
27
28 let (movement1base, movement2base, movement3, twitch) = match stage_section {
29 Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0, 0.0),
30 Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0, anim_time),
31 Some(StageSection::Recover) => (1.0, 1.0, anim_time.powi(4), 1.0),
32 _ => (0.0, 0.0, 0.0, 0.0),
33 };
34 let pullback = 1.0 - movement3;
35 let subtract = global_time - timer;
36 let check = subtract - subtract.trunc();
37 let mirror = (check - 0.5).signum();
38 let movement1 = movement1base * mirror * pullback;
39 let movement2 = movement2base * mirror * pullback;
40 let movement1abs = movement1base * pullback;
41 let movement2abs = movement2base * pullback;
42 let twitchleft = (twitch * 16.0).sin() * pullback * mirror;
43 let twitchright = (twitch * 8.0 + PI / 2.0).sin() * pullback * mirror;
44
45 next.head.orientation = Quaternion::rotation_x(movement1abs * -0.6 + movement2abs * 0.6)
46 * Quaternion::rotation_y(movement1 * 0.35 + movement2 * -0.15)
47 * Quaternion::rotation_z(movement1 * 0.15 + movement2 * -0.5);
48
49 next.neck.orientation = Quaternion::rotation_x(movement1abs * -0.8 + movement2abs * -0.2)
50 * Quaternion::rotation_y(movement1 * 0.0)
51 * Quaternion::rotation_z(movement1 * 0.10 + movement1 * -0.15);
52
53 next.jaw.orientation = Quaternion::rotation_x(movement1abs * -0.7 + movement2abs * 0.7);
54
55 next.tail.orientation = Quaternion::rotation_x(movement1 * 0.5 + movement2 * -0.8);
56 next.torso_front.position = Vec3::new(
57 0.0,
58 s_a.torso_front.0 + movement1abs * -6.0,
59 s_a.torso_front.1 + movement1abs * 9.0,
60 );
61 next.torso_front.orientation = Quaternion::rotation_x(movement1abs * 1.2);
62
63 next.torso_back.orientation = Quaternion::rotation_x(movement1abs * -0.8);
64
65 next.ears.orientation = Quaternion::rotation_x(0.0);
66 next.leg_fl.orientation = Quaternion::rotation_x(movement1abs * 0.8 + twitchleft * 0.5)
67 * Quaternion::rotation_y(movement1 * -0.3 + movement2 * 0.3)
68 * Quaternion::rotation_z(movement1 * -0.35 + movement2 * 0.45);
69
70 next.leg_fr.orientation = Quaternion::rotation_x(movement1abs * 0.8 + twitchright * 0.5)
71 * Quaternion::rotation_y(movement1 * -0.3 + movement2 * 0.3)
72 * Quaternion::rotation_z(movement1 * -0.35 + movement2 * 0.45);
73
74 next.foot_fl.orientation =
75 Quaternion::rotation_x(movement1abs * -0.9 + twitchleft * 0.5 + movement2abs * 0.6);
76
77 next.foot_fr.orientation =
78 Quaternion::rotation_x(movement1abs * -0.9 + twitchright * 0.5 + movement2abs * 0.6);
79 if speed < 0.5 {
80 next.leg_bl.orientation = Quaternion::rotation_x(movement1abs * -0.2);
81
82 next.leg_br.orientation = Quaternion::rotation_x(movement1abs * -0.2);
83
84 next.foot_bl.orientation = Quaternion::rotation_x(movement1abs * -0.2);
85
86 next.foot_br.orientation = Quaternion::rotation_x(movement1abs * -0.2);
87 };
88 next
89 }
90}