veloren_voxygen_anim/biped_large/
selfbuff.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedLargeSkeleton, SkeletonAttr,
4};
5use common::{
6    comp::item::tool::{AbilitySpec, ToolKind},
7    states::utils::StageSection,
8};
9use core::f32::consts::PI;
10
11pub struct SelfBuffAnimation;
12
13impl Animation for SelfBuffAnimation {
14    type Dependency<'a> = (
15        (Option<ToolKind>, Option<&'a AbilitySpec>),
16        (Option<ToolKind>, Option<&'a AbilitySpec>),
17        Vec3<f32>,
18        f32,
19        Option<StageSection>,
20        f32,
21    );
22    type Skeleton = BipedLargeSkeleton;
23
24    #[cfg(feature = "use-dyn-lib")]
25    const UPDATE_FN: &'static [u8] = b"biped_large_selfbuff\0";
26
27    #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_selfbuff")]
28    fn update_skeleton_inner(
29        skeleton: &Self::Skeleton,
30        (
31            (active_tool_kind, active_tool_spec),
32            _second_tool,
33            velocity,
34            _global_time,
35            stage_section,
36            acc_vel,
37        ): Self::Dependency<'_>,
38        anim_time: f32,
39        rate: &mut f32,
40        s_a: &SkeletonAttr,
41    ) -> Self::Skeleton {
42        *rate = 1.0;
43        let mut next = (*skeleton).clone();
44        let speed = Vec2::<f32>::from(velocity).magnitude();
45
46        let lab: f32 = 0.65 * s_a.tempo;
47        let speednorm = (speed / 12.0).powf(0.4);
48        let foothoril = (acc_vel * lab + PI * 1.45).sin() * speednorm;
49        let foothorir = (acc_vel * lab + PI * (0.45)).sin() * speednorm;
50        let footrotl = ((1.0 / (0.5 + (0.5) * ((acc_vel * lab + PI * 1.4).sin()).powi(2))).sqrt())
51            * ((acc_vel * lab + PI * 1.4).sin());
52
53        let footrotr = ((1.0 / (0.5 + (0.5) * ((acc_vel * lab + PI * 0.4).sin()).powi(2))).sqrt())
54            * ((acc_vel * lab + PI * 0.4).sin());
55        let (move1base, movement3, tensionbase, tension2base) = match stage_section {
56            Some(StageSection::Buildup) => (
57                (anim_time.powf(0.25)).min(1.0),
58                0.0,
59                (anim_time * 10.0).sin(),
60                0.0,
61            ),
62            Some(StageSection::Action) => {
63                (1.0, 0.0, (anim_time * 30.0).sin(), (anim_time * 12.0).sin())
64            },
65            Some(StageSection::Recover) => (1.0, anim_time.powi(4), 1.0, 1.0),
66            _ => (0.0, 0.0, 0.0, 0.0),
67        };
68
69        let pullback = 1.0 - movement3;
70        let move1 = move1base * pullback;
71        let tension = tensionbase * pullback;
72        let tension2 = tension2base * pullback;
73
74        next.second.position = Vec3::new(0.0, 0.0, 0.0);
75        next.second.orientation = Quaternion::rotation_x(0.0);
76        next.shoulder_l.position = Vec3::new(
77            -s_a.shoulder.0,
78            s_a.shoulder.1,
79            s_a.shoulder.2 - foothorir * 1.0,
80        );
81        next.shoulder_l.orientation =
82            Quaternion::rotation_x(move1 * 0.8 + 0.6 * speednorm + (footrotr * -0.2) * speednorm);
83
84        next.shoulder_r.position = Vec3::new(
85            s_a.shoulder.0,
86            s_a.shoulder.1,
87            s_a.shoulder.2 - foothoril * 1.0,
88        );
89        next.shoulder_r.orientation =
90            Quaternion::rotation_x(move1 * 0.8 + 0.6 * speednorm + (footrotl * -0.2) * speednorm);
91        next.torso.orientation = Quaternion::rotation_z(0.0);
92
93        next.main.position = Vec3::new(0.0, 0.0, 0.0);
94        next.main.orientation = Quaternion::rotation_x(0.0);
95
96        next.hand_l.position = Vec3::new(0.0, 0.0, s_a.grip.0);
97        next.hand_r.position = Vec3::new(0.0, 0.0, s_a.grip.0);
98
99        next.hand_l.orientation = Quaternion::rotation_x(0.0);
100        next.hand_r.orientation = Quaternion::rotation_x(0.0);
101
102        // TODO: Remove clippy allow when second species is added
103        #[expect(clippy::single_match)]
104        match active_tool_kind {
105            Some(ToolKind::Axe | ToolKind::Hammer) => {
106                next.control_l.position = Vec3::new(-1.0, 2.0, 12.0);
107                next.control_r.position = Vec3::new(1.0, 2.0, -2.0);
108
109                next.control.position = Vec3::new(
110                    4.0 + move1 * -20.0 + tension2 * 5.0,
111                    0.0 + s_a.grip.0 / 1.0 + move1 * -5.0,
112                    -s_a.grip.0 / 0.8 + move1 * 5.0,
113                );
114                next.jaw.orientation = Quaternion::rotation_x(move1 * -0.3 + tension2 * -0.15);
115                next.head.orientation =
116                    Quaternion::rotation_x(move1 * 0.3) * Quaternion::rotation_z(tension2 * 0.5);
117                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + move1 * 0.2)
118                    * Quaternion::rotation_y(move1 * -1.0);
119                next.control_r.orientation = Quaternion::rotation_x(PI / 2.0 + 0.2 + move1 * -0.2)
120                    * Quaternion::rotation_y(0.0)
121                    * Quaternion::rotation_z(0.0);
122
123                next.control.orientation = Quaternion::rotation_x(-1.0 + move1 * 1.0)
124                    * Quaternion::rotation_y(-1.8 + move1 * 1.2 + tension * 0.09)
125                    * Quaternion::rotation_z(move1 * 1.5);
126                next.shoulder_l.orientation =
127                    Quaternion::rotation_x(move1 * -0.5) * Quaternion::rotation_y(move1 * 0.5);
128                next.shoulder_r.orientation =
129                    Quaternion::rotation_x(move1 * 0.6) * Quaternion::rotation_y(move1 * 0.4);
130                next.upper_torso.orientation = Quaternion::rotation_z(tension2 * -0.08);
131                next.lower_torso.orientation = Quaternion::rotation_z(tension2 * 0.08);
132            },
133            Some(ToolKind::Natural) => {
134                if let Some(AbilitySpec::Custom(spec)) = active_tool_spec {
135                    match spec.as_str() {
136                        "Minotaur" => {
137                            next.upper_torso.orientation =
138                                Quaternion::rotation_x(move1 * -0.1 + tension2 * 0.05);
139                            next.lower_torso.orientation =
140                                Quaternion::rotation_x(move1 * 0.1 + tension2 * -0.05);
141
142                            next.head.orientation =
143                                Quaternion::rotation_x(move1 * 0.8 + tension2 * -0.1)
144                                    * Quaternion::rotation_y(tension2 * -0.1);
145
146                            next.control_l.position = Vec3::new(0.0, 4.0, 5.0);
147                            next.control_r.position = Vec3::new(0.0, 4.0, 5.0);
148                            next.weapon_l.position = Vec3::new(
149                                -12.0 + move1 * -15.0,
150                                -6.0 + move1 * 13.0,
151                                -18.0 + move1 * 16.0 + tension2 * 3.0,
152                            );
153                            next.weapon_r.position = Vec3::new(
154                                12.0 + move1 * 1.0,
155                                -6.0 + move1 * 7.0 + tension * 0.3,
156                                -18.0 + move1 * -2.0,
157                            );
158                            next.second.scale = Vec3::one() * 1.0;
159
160                            next.weapon_l.orientation = Quaternion::rotation_x(-1.67 + move1 * 1.9)
161                                * Quaternion::rotation_y(move1 * 0.25 + tension2 * 0.06)
162                                * Quaternion::rotation_z(move1 * 1.3);
163                            next.weapon_r.orientation = Quaternion::rotation_x(-1.67 + move1 * 0.8)
164                                * Quaternion::rotation_y(move1 * -0.85 + tension * 0.12)
165                                * Quaternion::rotation_z(move1 * 0.7);
166
167                            next.control_l.orientation =
168                                Quaternion::rotation_x(PI / 2.0 + move1 * 0.1)
169                                    * Quaternion::rotation_y(0.0);
170                            next.control_r.orientation =
171                                Quaternion::rotation_x(PI / 2.0 + move1 * 0.1)
172                                    * Quaternion::rotation_y(0.0);
173
174                            next.control.orientation =
175                                Quaternion::rotation_x(0.0) * Quaternion::rotation_y(0.0);
176                            next.shoulder_l.orientation =
177                                Quaternion::rotation_x(-0.3 + move1 * 2.2 + tension2 * 0.17)
178                                    * Quaternion::rotation_y(move1 * 0.95);
179
180                            next.shoulder_r.orientation =
181                                Quaternion::rotation_x(-0.3 + move1 * 0.1)
182                                    * Quaternion::rotation_y(move1 * -0.35);
183                        },
184                        _ => {},
185                    }
186                }
187            },
188            _ => {},
189        }
190
191        next
192    }
193}