veloren_voxygen_anim/character/
dance.rs

1use super::{
2    super::{Animation, vek::*},
3    CharacterSkeleton, SkeletonAttr,
4};
5use common::comp::item::ToolKind;
6use std::{f32::consts::PI, ops::Mul};
7
8pub struct DanceAnimation;
9
10impl Animation for DanceAnimation {
11    type Dependency<'a> = (Option<ToolKind>, Option<ToolKind>, f32);
12    type Skeleton = CharacterSkeleton;
13
14    #[cfg(feature = "use-dyn-lib")]
15    const UPDATE_FN: &'static [u8] = b"character_dance\0";
16
17    #[cfg_attr(feature = "be-dyn-lib", export_name = "character_dance")]
18    fn update_skeleton_inner(
19        skeleton: &Self::Skeleton,
20        (_active_tool_kind, _second_tool_kind, global_time): Self::Dependency<'_>,
21        anim_time: f32,
22        rate: &mut f32,
23        s_a: &SkeletonAttr,
24    ) -> Self::Skeleton {
25        let mut next = (*skeleton).clone();
26
27        *rate = 1.0;
28
29        let lab: f32 = 1.0;
30        let short = ((5.0 / (3.0 + 2.0 * ((anim_time * lab * 6.0).sin()).powi(2))).sqrt())
31            * ((anim_time * lab * 6.0).sin());
32        let noisea = (anim_time * 11.0 + PI / 6.0).sin();
33        let noiseb = (anim_time * 19.0 + PI / 4.0).sin();
34
35        let shorte = (anim_time * lab * 6.0).sin();
36
37        let shortealt = (anim_time * lab * 6.0 + PI / 2.0).sin();
38
39        let foot = ((5.0 / (1.0 + (4.0) * ((anim_time * lab * 8.0).sin()).powi(2))).sqrt())
40            * ((anim_time * lab * 8.0).sin());
41
42        let head_look = Vec2::new(
43            (global_time + anim_time / 6.0).floor().mul(7331.0).sin() * 0.3,
44            (global_time + anim_time / 6.0).floor().mul(1337.0).sin() * 0.15,
45        );
46
47        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
48        next.head.orientation = Quaternion::rotation_z(short * -0.6)
49            * Quaternion::rotation_x(0.2 + head_look.y.max(0.0) + shorte.abs() * -0.2);
50
51        next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + shortealt * 1.5);
52        next.chest.orientation = Quaternion::rotation_z(short * 0.35)
53            * Quaternion::rotation_y(shorte * 0.08)
54            * Quaternion::rotation_x(foot * 0.07);
55
56        next.belt.position = Vec3::new(0.0, s_a.belt.0, s_a.belt.1);
57        next.belt.orientation = Quaternion::rotation_z(shorte * 0.25);
58
59        next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
60        next.back.orientation =
61            Quaternion::rotation_x(-0.25 + shorte * 0.1 + noisea * 0.1 + noiseb * 0.1);
62
63        next.shorts.position = Vec3::new(0.0, s_a.shorts.0, s_a.shorts.1);
64        next.shorts.orientation = Quaternion::rotation_z(foot * 0.35);
65
66        next.hand_l.position = Vec3::new(
67            1.0 - s_a.hand.0,
68            2.0 + s_a.hand.1 + shortealt * -3.0,
69            s_a.hand.2 + shortealt * -0.75,
70        );
71        next.hand_l.orientation =
72            Quaternion::rotation_x(1.4 + foot * 0.15) * Quaternion::rotation_y(0.2);
73
74        next.hand_r.position = Vec3::new(
75            -1.0 + s_a.hand.0,
76            2.0 + s_a.hand.1 + shortealt * 3.0,
77            s_a.hand.2 + shortealt * 0.75,
78        );
79        next.hand_r.orientation =
80            Quaternion::rotation_x(1.4 + foot * -0.15) * Quaternion::rotation_y(-0.2);
81
82        next.foot_l.position = Vec3::new(
83            -s_a.foot.0 + foot * 0.8,
84            1.5 + -s_a.foot.1 + foot * -4.0,
85            s_a.foot.2 + 2.0,
86        );
87        next.foot_l.orientation =
88            Quaternion::rotation_x(foot * -0.3) * Quaternion::rotation_z(short * -0.15);
89
90        next.foot_r.position = Vec3::new(
91            s_a.foot.0 + foot * 0.8,
92            1.5 + -s_a.foot.1 + foot * 4.0,
93            s_a.foot.2 + 2.0,
94        );
95        next.foot_r.orientation =
96            Quaternion::rotation_x(foot * 0.3) * Quaternion::rotation_z(short * 0.15);
97
98        next.shoulder_l.position = Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
99        next.shoulder_l.orientation = Quaternion::rotation_x(shorte * 0.15);
100
101        next.shoulder_r.position = Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
102        next.shoulder_r.orientation = Quaternion::rotation_x(shorte * -0.15);
103
104        next.lantern.orientation =
105            Quaternion::rotation_x(shorte * 0.7 + 0.4) * Quaternion::rotation_y(shorte * 0.4);
106
107        next.torso.position = Vec3::new(0.0, -3.3, 0.0);
108        next.torso.orientation = Quaternion::rotation_z(short * -0.2);
109
110        next
111    }
112}