veloren_voxygen_anim/biped_large/
spin.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedLargeSkeleton, SkeletonAttr,
4};
5use common::{comp::item::ToolKind, states::utils::StageSection};
6use core::f32::consts::PI;
7
8pub struct SpinAnimation;
9
10impl Animation for SpinAnimation {
11    type Dependency<'a> = (
12        Option<ToolKind>,
13        Option<ToolKind>,
14        f32,
15        Option<StageSection>,
16    );
17    type Skeleton = BipedLargeSkeleton;
18
19    #[cfg(feature = "use-dyn-lib")]
20    const UPDATE_FN: &'static [u8] = b"biped_large_spin\0";
21
22    #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_spin")]
23    fn update_skeleton_inner(
24        skeleton: &Self::Skeleton,
25        (active_tool_kind, _second_tool_kind, _global_time, stage_section): Self::Dependency<'_>,
26        anim_time: f32,
27        rate: &mut f32,
28        s_a: &SkeletonAttr,
29    ) -> Self::Skeleton {
30        *rate = 1.0;
31        let mut next = (*skeleton).clone();
32
33        let lab: f32 = 1.0;
34
35        let (movement1, movement2, movement3) = match stage_section {
36            Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0),
37            Some(StageSection::Action) => (1.0, anim_time.powf(1.8), 0.0),
38            Some(StageSection::Recover) => (1.0, 1.0, anim_time.powi(4)),
39            _ => (0.0, 0.0, 0.0),
40        };
41
42        let foot = ((5.0 / (1.1 + 3.9 * ((anim_time * lab * 10.32).sin()).powi(2))).sqrt())
43            * ((anim_time * lab * 10.32).sin());
44
45        let decel = (anim_time * 16.0 * lab).min(PI / 2.0).sin();
46
47        let spin = (anim_time * 2.8 * lab).sin();
48        let spinhalf = (anim_time * 1.4 * lab).sin();
49
50        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
51
52        if let Some(ToolKind::Sword) = active_tool_kind {
53            next.main.position = Vec3::new(0.0, 0.0, 0.0);
54            next.main.orientation = Quaternion::rotation_x(0.0);
55
56            next.hand_l.position = Vec3::new(s_a.shl.0, s_a.shl.1, s_a.shl.2);
57            next.hand_l.orientation =
58                Quaternion::rotation_x(s_a.shl.3) * Quaternion::rotation_y(s_a.shl.4);
59            next.hand_r.position = Vec3::new(s_a.shr.0, s_a.shr.1, s_a.shr.2);
60            next.hand_r.orientation =
61                Quaternion::rotation_x(s_a.shr.3) * Quaternion::rotation_y(s_a.shr.4);
62
63            next.control.position = Vec3::new(
64                s_a.sc.0 + movement1 * 2.0 + movement2 * -4.0 + movement3 * -7.0,
65                s_a.sc.1 + 0.0 + movement1 * 0.6 + movement3 * -10.0,
66                s_a.sc.2 + 5.0 + movement1 * 0.6 + movement2 * 1.5 + movement3 * -4.0,
67            );
68            next.control.orientation = Quaternion::rotation_x(-0.5 + s_a.sc.3 + movement1 * -1.2)
69                * Quaternion::rotation_y(s_a.sc.4 - 0.6 + movement1 * 1.0)
70                * Quaternion::rotation_z(s_a.sc.5 + 0.1 + movement1 * PI / 2.0);
71            next.head.position = Vec3::new(
72                0.0 + 2.0 + movement2 * -2.0,
73                2.0 + movement2 * -2.0 + s_a.head.0,
74                s_a.head.1,
75            );
76            next.head.orientation = Quaternion::rotation_z(movement2 * -0.4);
77
78            next.upper_torso.orientation = Quaternion::rotation_x(movement2 * 0.15)
79                * Quaternion::rotation_y(movement1 * -0.1 + movement2 * 0.3 + movement3 * -0.1)
80                * Quaternion::rotation_z(
81                    -1.0 + movement1 * -0.6 + movement2 * 1.5 + movement3 * 0.5,
82                );
83
84            next.lower_torso.orientation = Quaternion::rotation_x(movement1 * 0.1)
85                * Quaternion::rotation_z(movement2.sin() * 1.5);
86
87            next.head.orientation = Quaternion::rotation_y(movement1 * 0.1 - movement2 * -0.1)
88                * Quaternion::rotation_z(1.07 + movement1 * 0.4 + movement2 * -1.5);
89
90            next.torso.orientation = Quaternion::rotation_z(movement2 * std::f32::consts::TAU);
91        }
92
93        if let Some(ToolKind::Axe | ToolKind::Hammer | ToolKind::Dagger) = active_tool_kind {
94            next.hand_l.position = Vec3::new(-0.75, -1.0, -2.5);
95            next.hand_l.orientation = Quaternion::rotation_x(1.27);
96            next.hand_r.position = Vec3::new(0.75, -1.5, -5.5);
97            next.hand_r.orientation = Quaternion::rotation_x(1.27);
98            next.main.position = Vec3::new(0.0, 6.0, -1.0);
99            next.main.orientation = Quaternion::rotation_x(-0.3)
100                * Quaternion::rotation_y(0.0)
101                * Quaternion::rotation_z(0.0);
102
103            next.control.position = Vec3::new(-4.5 + spinhalf * 4.0, 11.0, 8.0);
104            next.control.orientation = Quaternion::rotation_x(-1.7)
105                * Quaternion::rotation_y(0.2 + spin * -2.0)
106                * Quaternion::rotation_z(1.4 + spin * 0.1);
107            next.head.position = Vec3::new(0.0, -1.0 + s_a.head.0 + spin * -0.8, s_a.head.1);
108            next.head.orientation = Quaternion::rotation_z(spin * -0.25)
109                * Quaternion::rotation_x(0.0 + spin * -0.1)
110                * Quaternion::rotation_y(spin * -0.2);
111            next.upper_torso.position = Vec3::new(0.0, s_a.upper_torso.0, s_a.upper_torso.1);
112            next.upper_torso.orientation = Quaternion::rotation_z(spin * 0.1)
113                * Quaternion::rotation_x(0.0 + spin * 0.1)
114                * Quaternion::rotation_y(decel * -0.2);
115
116            next.lower_torso.position = Vec3::new(0.0, 0.0, -5.0);
117            next.torso.orientation = Quaternion::rotation_z((spin * 7.0).max(0.3));
118
119            next.foot_l.position = Vec3::new(-s_a.foot.0, foot * 1.0, s_a.foot.2);
120            next.foot_l.orientation = Quaternion::rotation_x(foot * -1.2);
121
122            next.foot_r.position = Vec3::new(s_a.foot.0, foot * -1.0, s_a.foot.2);
123            next.foot_r.orientation = Quaternion::rotation_x(foot * 1.2);
124        }
125
126        next
127    }
128}