veloren_voxygen_anim/biped_small/
wield.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedSmallSkeleton, SkeletonAttr, biped_small_wield_bow, biped_small_wield_spear,
4    biped_small_wield_sword,
5};
6use common::comp::item::tool::{AbilitySpec, ToolKind};
7use std::f32::consts::PI;
8
9pub struct WieldAnimation;
10
11type WieldAnimationDependency<'a> = (
12    (Option<ToolKind>, Option<&'a AbilitySpec>),
13    Vec3<f32>,
14    Vec3<f32>,
15    Vec3<f32>,
16    f32,
17    Vec3<f32>,
18    f32,
19);
20
21impl Animation for WieldAnimation {
22    type Dependency<'a> = WieldAnimationDependency<'a>;
23    type Skeleton = BipedSmallSkeleton;
24
25    #[cfg(feature = "use-dyn-lib")]
26    const UPDATE_FN: &'static [u8] = b"biped_small_wield\0";
27
28    #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_small_wield")]
29
30    fn update_skeleton_inner(
31        skeleton: &Self::Skeleton,
32        (
33            (active_tool_kind, active_tool_spec),
34            velocity,
35            _orientation,
36            _last_ori,
37            _global_time,
38            _avg_vel,
39            acc_vel,
40        ): Self::Dependency<'_>,
41        anim_time: f32,
42        _rate: &mut f32,
43        s_a: &SkeletonAttr,
44    ) -> Self::Skeleton {
45        let mut next = (*skeleton).clone();
46        let speed = Vec2::<f32>::from(velocity).magnitude();
47
48        let fastacc = (acc_vel * 2.0).sin();
49        let fast = (anim_time * 10.0).sin();
50        let fastalt = (anim_time * 10.0 + PI / 2.0).sin();
51        let slow = (anim_time * 2.0).sin();
52
53        let speednorm = speed / 9.4;
54        let speednormcancel = 1.0 - speednorm;
55
56        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + fast * -0.1 * speednormcancel);
57        next.head.orientation = Quaternion::rotation_x(0.45 * speednorm)
58            * Quaternion::rotation_y(fast * 0.07 * speednormcancel);
59        next.chest.position = Vec3::new(
60            0.0,
61            s_a.chest.0,
62            s_a.chest.1 + fastalt * 0.4 * speednormcancel + speednormcancel * -0.5,
63        );
64
65        next.pants.position = Vec3::new(0.0, s_a.pants.0, s_a.pants.1);
66
67        next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
68        next.tail.orientation = Quaternion::rotation_x(0.05 * fastalt * speednormcancel)
69            * Quaternion::rotation_z(fast * 0.15 * speednormcancel);
70
71        next.main.position = Vec3::new(0.0, 0.0, 0.0);
72        next.main.orientation = Quaternion::rotation_z(0.0);
73
74        next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
75        next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
76
77        next.hand_l.orientation = Quaternion::rotation_x(0.0);
78        next.hand_r.orientation = Quaternion::rotation_x(0.0);
79
80        //IMPORTANT: avoid touching any value attached to grip. grip uses the size of
81        // the hand bones to correct any irrgularities beween species. Changing
82        // coefficients to grip will have different effects across species
83
84        match active_tool_kind {
85            Some(ToolKind::Spear) => {
86                biped_small_wield_spear(&mut next, s_a, anim_time, speed, fastacc);
87            },
88            Some(ToolKind::Blowgun) => {
89                next.control_l.position = Vec3::new(1.0 - s_a.grip.0 * 2.0, 0.0, 3.0);
90                next.control_r.position = Vec3::new(-1.0 + s_a.grip.0 * 2.0, 0.0, 4.0);
91
92                next.control.position = Vec3::new(
93                    0.0,
94                    s_a.grip.2,
95                    4.0 - s_a.grip.2 / 2.5
96                        + s_a.grip.0 * -2.0
97                        + fastacc * 0.5
98                        + fastalt * 0.1 * speednormcancel
99                        + speednorm * 4.0,
100                );
101
102                next.control_l.orientation =
103                    Quaternion::rotation_x(3.8 + slow * 0.1) * Quaternion::rotation_y(-0.3);
104                next.control_r.orientation =
105                    Quaternion::rotation_x(3.5 + slow * 0.1 + s_a.grip.0 * 0.2)
106                        * Quaternion::rotation_y(0.5 + slow * 0.0 + s_a.grip.0 * 0.2);
107
108                next.control.orientation = Quaternion::rotation_x(-2.2 + 0.5 * speednorm);
109            },
110            Some(ToolKind::Bow) => {
111                biped_small_wield_bow(&mut next, s_a, anim_time, speed, fastacc);
112            },
113            Some(ToolKind::Staff) => {
114                next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
115                next.control_r.position =
116                    Vec3::new(7.0 + s_a.grip.0 * 2.0, -4.0, 3.0 + speednorm * -3.0);
117
118                next.control.position = Vec3::new(
119                    -5.0,
120                    -1.0 + s_a.grip.2,
121                    -2.0 + -s_a.grip.2 / 2.5
122                        + s_a.grip.0 * -2.0
123                        + fastacc * 1.5
124                        + fastalt * 0.5 * speednormcancel
125                        + speednorm * 2.0,
126                );
127
128                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + slow * 0.1)
129                    * Quaternion::rotation_y(-0.3)
130                    * Quaternion::rotation_z(-0.3);
131                next.control_r.orientation =
132                    Quaternion::rotation_x(PI / 2.0 + slow * 0.1 + s_a.grip.0 * 0.2)
133                        * Quaternion::rotation_y(-0.4 + slow * 0.0 + s_a.grip.0 * 0.2)
134                        * Quaternion::rotation_z(-0.0);
135
136                next.control.orientation = Quaternion::rotation_x(-0.3 + 0.2 * speednorm)
137                    * Quaternion::rotation_y(-0.2 * speednorm)
138                    * Quaternion::rotation_z(0.5);
139            },
140            Some(ToolKind::Axe | ToolKind::Hammer | ToolKind::Pick) => {
141                next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
142                next.control_r.position =
143                    Vec3::new(9.0 + s_a.grip.0 * 2.0, -1.0, -2.0 + speednorm * -3.0);
144
145                next.control.position = Vec3::new(
146                    -5.0,
147                    -1.0 + s_a.grip.2,
148                    -1.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + speednorm * 2.0,
149                );
150
151                next.control_l.orientation = Quaternion::rotation_x(PI / 2.0 + slow * 0.1)
152                    * Quaternion::rotation_y(-0.0)
153                    * Quaternion::rotation_z(-0.0);
154                next.control_r.orientation =
155                    Quaternion::rotation_x(0.5 + slow * 0.1 + s_a.grip.0 * 0.2)
156                        * Quaternion::rotation_y(0.2 + slow * 0.0 + s_a.grip.0 * 0.2)
157                        * Quaternion::rotation_z(-0.0);
158
159                next.control.orientation = Quaternion::rotation_x(-0.3 + 0.2 * speednorm)
160                    * Quaternion::rotation_y(-0.2 * speednorm)
161                    * Quaternion::rotation_z(-0.3);
162            },
163            Some(ToolKind::Dagger | ToolKind::Sword) => {
164                biped_small_wield_sword(&mut next, s_a, speednorm, slow);
165            },
166            Some(ToolKind::Natural) => {
167                if let Some(AbilitySpec::Custom(spec)) = active_tool_spec {
168                    match spec.as_str() {
169                        "ShamanicSpirit" => {
170                            next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
171                            next.hand_l.orientation = Quaternion::rotation_x(1.2);
172                            next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
173                            next.hand_r.orientation = Quaternion::rotation_x(1.2);
174                            next.main.position = Vec3::new(0.0, 12.0, 5.0);
175                        },
176                        _ => {
177                            next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
178                            next.hand_l.orientation = Quaternion::rotation_x(1.2);
179                            next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
180                            next.hand_r.orientation = Quaternion::rotation_x(1.2);
181                        },
182                    }
183                }
184            },
185            _ => {
186                next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
187                next.hand_l.orientation = Quaternion::rotation_x(1.2);
188                next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
189                next.hand_r.orientation = Quaternion::rotation_x(1.2);
190            },
191        }
192
193        next
194    }
195}