veloren_voxygen_anim/biped_small/
buff.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedSmallSkeleton, SkeletonAttr,
4};
5use common::{comp::tool::ToolKind, states::utils::StageSection};
6use core::f32::consts::PI;
7
8pub struct BuffAnimation;
9
10impl Animation for BuffAnimation {
11    type Dependency<'a> = (Option<ToolKind>, Option<ToolKind>, Option<StageSection>);
12    type Skeleton = BipedSmallSkeleton;
13
14    #[cfg(feature = "use-dyn-lib")]
15    const UPDATE_FN: &'static [u8] = b"biped_small_selfbuff\0";
16
17    #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "biped_small_selfbuff"))]
18    fn update_skeleton_inner(
19        skeleton: &Self::Skeleton,
20        (active_tool_kind, second_tool_kind, stage_section): Self::Dependency<'_>,
21        anim_time: f32,
22        rate: &mut f32,
23        s_a: &SkeletonAttr,
24    ) -> Self::Skeleton {
25        *rate = 1.0;
26        let mut next = (*skeleton).clone();
27
28        let (move1base, movement3, tensionbase, tension2base) = match stage_section {
29            Some(StageSection::Buildup) => (
30                (anim_time.powf(0.25)).min(1.0),
31                0.0,
32                (anim_time * 10.0).sin(),
33                0.0,
34            ),
35            Some(StageSection::Action) => {
36                (1.0, 0.0, (anim_time * 30.0).sin(), (anim_time * 12.0).sin())
37            },
38            Some(StageSection::Recover) => (1.0, anim_time.powi(4), 1.0, 1.0),
39            _ => (0.0, 0.0, 0.0, 0.0),
40        };
41
42        let pullback = 1.0 - movement3;
43        let move1 = move1base * pullback;
44        let tension = tensionbase * pullback;
45        let tension2 = tension2base * pullback;
46        let slow = (anim_time * 3.0).sin();
47
48        match (active_tool_kind, second_tool_kind) {
49            (Some(ToolKind::Axe), Some(ToolKind::Axe)) => {
50                next.main.position = Vec3::new(-8.0, 2.0, 0.0);
51                next.main.orientation = Quaternion::rotation_x(0.0);
52                next.second.position = Vec3::new(8.0, 2.0, 0.0);
53                next.second.orientation = Quaternion::rotation_x(0.0);
54
55                next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, 2.0);
56                next.hand_l.orientation = Quaternion::rotation_x(PI / 2.0);
57                next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, 2.0);
58                next.hand_r.orientation = Quaternion::rotation_x(PI / 2.0);
59
60                next.head.position += Vec3::new(0.0, -2.0, 0.0) * move1;
61                next.head.orientation.rotate_x(PI / 8.0 * move1);
62                next.chest.position += Vec3::new(0.0, -2.0, 0.0) * move1;
63                next.chest.orientation.rotate_x(PI / 16.0 * move1);
64                next.control_l.position += Vec3::new(0.0, 0.0, 4.0) * move1;
65                next.control_l.orientation.rotate_y(PI / 5.0 * move1);
66                next.main.position += Vec3::new(2.0, 0.0, 9.0) * move1;
67                next.main.orientation.rotate_y(PI / 5.0 * move1);
68                next.control_r.position += Vec3::new(0.0, 0.0, 4.0) * move1;
69                next.control_r.orientation.rotate_y(-PI / 5.0 * move1);
70
71                next.control_l.position += Vec3::new(0.0, 0.0, 4.0 * slow);
72                next.main.position += Vec3::new(0.0, 0.0, 4.0 * slow);
73                next.control_r.position += Vec3::new(0.0, 0.0, 4.0 * slow);
74            },
75            _ => {
76                next.main.position = Vec3::new(0.0, 0.0, 0.0);
77                next.main.orientation = Quaternion::rotation_x(0.0);
78                next.second.position = Vec3::new(0.0, 0.0, 0.0);
79                next.second.orientation = Quaternion::rotation_x(0.0);
80
81                next.hand_l.position = Vec3::new(0.0, 0.0, s_a.grip.0);
82                next.hand_r.position = Vec3::new(0.0, 0.0, s_a.grip.0);
83
84                next.hand_l.orientation = Quaternion::rotation_x(0.0);
85                next.hand_r.orientation = Quaternion::rotation_x(0.0);
86
87                next.control_l.position = Vec3::new(-1.0, -2.0, 12.0);
88                next.control_r.position = Vec3::new(1.0, -2.0, -2.0);
89
90                next.head.orientation =
91                    Quaternion::rotation_x(move1 * 0.3) * Quaternion::rotation_z(tension2 * 0.2);
92                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + move1 * 0.2)
93                    * Quaternion::rotation_y(move1 * -1.0);
94                next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + 0.2 + move1 * -0.2)
95                    * Quaternion::rotation_y(0.0)
96                    * Quaternion::rotation_z(0.0);
97
98                next.control.orientation = Quaternion::rotation_x(-1.0 + move1 * 1.0)
99                    * Quaternion::rotation_y(-1.8 + move1 * 1.2 + tension * 0.09)
100                    * Quaternion::rotation_z(move1 * 1.5);
101                next.chest.orientation = Quaternion::rotation_z(tension2 * -0.08);
102                next.pants.orientation = Quaternion::rotation_z(tension2 * 0.08);
103
104                next.control.orientation.rotate_z(move1 * -2.0);
105                next.control.orientation.rotate_x(move1 * 0.5);
106                next.control.position += Vec3::new(move1 * -4.0, move1 * 10.0, move1 * 5.0);
107
108                next.chest.orientation.rotate_x(move1 * 0.4);
109                next.pants.position += Vec3::new(0.0, -2.0, 0.0) * move1;
110                next.pants.orientation.rotate_x(-move1 * 0.4);
111            },
112        }
113
114        next
115    }
116}