veloren_voxygen_anim/biped_small/
stunned.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedSmallSkeleton, SkeletonAttr,
4};
5use common::{comp::item::ToolKind, states::utils::StageSection};
6use core::f32::consts::PI;
7
8pub struct StunnedAnimation;
9
10type StunnedAnimationDependency = (
11    Option<ToolKind>,
12    Vec3<f32>,
13    Vec3<f32>,
14    Vec3<f32>,
15    f32,
16    Vec3<f32>,
17    f32,
18    bool,
19    Option<StageSection>,
20    f32,
21);
22
23impl Animation for StunnedAnimation {
24    type Dependency<'a> = StunnedAnimationDependency;
25    type Skeleton = BipedSmallSkeleton;
26
27    #[cfg(feature = "use-dyn-lib")]
28    const UPDATE_FN: &'static [u8] = b"biped_small_stunned\0";
29
30    #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_small_stunned")]
31
32    fn update_skeleton_inner(
33        skeleton: &Self::Skeleton,
34        (
35            active_tool_kind,
36            velocity,
37            _orientation,
38            _last_ori,
39            global_time,
40            _avg_vel,
41            _acc_vel,
42            wield_status,
43            stage_section,
44            timer,
45        ): Self::Dependency<'_>,
46        anim_time: f32,
47        _rate: &mut f32,
48        s_a: &SkeletonAttr,
49    ) -> Self::Skeleton {
50        let mut next = (*skeleton).clone();
51        let speed = Vec2::<f32>::from(velocity).magnitude();
52
53        let speednorm = speed / 9.4;
54        if wield_status {
55            let (movement1base, movement2) = match stage_section {
56                Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0),
57                Some(StageSection::Recover) => (1.0, anim_time.powf(4.0)),
58                _ => (0.0, 0.0),
59            };
60            let pullback = 1.0 - movement2;
61            let subtract = global_time - timer;
62            let check = subtract - subtract.trunc();
63            let mirror = (check - 0.5).signum();
64            let movement1 = movement1base * pullback * mirror;
65            let movement1abs = movement1base * pullback;
66            next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
67            next.head.orientation =
68                Quaternion::rotation_x(movement1 * 0.2) * Quaternion::rotation_z(movement1 * -0.3);
69            next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + movement1abs - 3.0);
70            next.chest.orientation = Quaternion::rotation_z(movement1 * 1.2);
71
72            next.pants.position = Vec3::new(0.0, s_a.pants.0, s_a.pants.1);
73
74            next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
75            next.tail.orientation = Quaternion::rotation_x(0.0) * Quaternion::rotation_z(0.0);
76
77            next.main.position = Vec3::new(0.0, 0.0, 0.0);
78            next.main.orientation = Quaternion::rotation_x(0.0);
79
80            next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
81            next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
82
83            next.hand_l.orientation = Quaternion::rotation_x(0.0);
84            next.hand_r.orientation = Quaternion::rotation_x(0.0);
85
86            //IMPORTANT: avoid touching any value attached to grip. grip uses the size of
87            // the hand bones to correct any irrgularities beween species. Changing
88            // coefficients to grip will have different effects across species
89
90            match active_tool_kind {
91                Some(ToolKind::Spear) => {
92                    next.control_l.position = Vec3::new(1.0 - s_a.grip.0 * 2.0, 2.0, -2.0);
93                    next.control_r.position = Vec3::new(-1.0 + s_a.grip.0 * 2.0, 2.0, 2.0);
94
95                    next.control.position = Vec3::new(
96                        -3.0,
97                        s_a.grip.2,
98                        -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + speednorm * 2.0,
99                    );
100
101                    next.control_l.orientation =
102                        Quaternion::rotation_x(PI / 1.5) * Quaternion::rotation_y(-0.3);
103                    next.control_r.orientation =
104                        Quaternion::rotation_x(PI / 1.5 + s_a.grip.0 * 0.2)
105                            * Quaternion::rotation_y(0.5 + s_a.grip.0 * 0.2);
106
107                    next.control.orientation = Quaternion::rotation_x(-1.35 + 0.5 * speednorm);
108                },
109
110                Some(ToolKind::Bow) => {
111                    next.control_l.position = Vec3::new(1.0 - s_a.grip.0 * 2.0, 0.0, 0.0);
112                    next.control_r.position = Vec3::new(-1.0 + s_a.grip.0 * 2.0, 6.0, -2.0);
113
114                    next.control.position = Vec3::new(
115                        -1.0,
116                        2.0 + s_a.grip.2,
117                        3.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + speednorm * 2.0,
118                    );
119
120                    next.control_l.orientation =
121                        Quaternion::rotation_x(PI / 2.0) * Quaternion::rotation_y(-0.3);
122                    next.control_r.orientation =
123                        Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
124                            * Quaternion::rotation_y(0.5 + s_a.grip.0 * 0.2);
125
126                    next.control.orientation = Quaternion::rotation_x(-0.3 + 0.5 * speednorm)
127                        * Quaternion::rotation_y(0.5 * speednorm);
128                },
129                Some(ToolKind::Staff) => {
130                    next.control_l.position = Vec3::new(2.0 - s_a.grip.0 * 2.0, 1.0, 3.0);
131                    next.control_r.position =
132                        Vec3::new(7.0 + s_a.grip.0 * 2.0, -4.0, 3.0 + speednorm * -3.0);
133
134                    next.control.position = Vec3::new(
135                        -5.0,
136                        -1.0 + s_a.grip.2,
137                        -2.0 + -s_a.grip.2 / 2.5 + s_a.grip.0 * -2.0 + speednorm * 2.0,
138                    );
139
140                    next.control_l.orientation = Quaternion::rotation_x(PI / 2.0)
141                        * Quaternion::rotation_y(-0.3)
142                        * Quaternion::rotation_z(-0.3);
143                    next.control_r.orientation =
144                        Quaternion::rotation_x(PI / 2.0 + s_a.grip.0 * 0.2)
145                            * Quaternion::rotation_y(-0.4 + s_a.grip.0 * 0.2)
146                            * Quaternion::rotation_z(-0.0);
147
148                    next.control.orientation = Quaternion::rotation_x(-0.3 + 0.2 * speednorm)
149                        * Quaternion::rotation_y(-0.2 * speednorm)
150                        * Quaternion::rotation_z(0.5);
151                },
152                Some(ToolKind::Natural) => {
153                    next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
154                    next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
155
156                    next.hand_l.orientation =
157                        Quaternion::rotation_x(1.7) * Quaternion::rotation_y(-0.3);
158                    next.hand_r.orientation =
159                        Quaternion::rotation_x(1.7) * Quaternion::rotation_y(0.3);
160                },
161                _ => {},
162            }
163        } else {
164            next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
165
166            next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1);
167            next.pants.position = Vec3::new(0.0, s_a.pants.0, s_a.pants.1);
168            next.main.position = Vec3::new(2.0, -3.0, -3.0);
169            next.main.orientation = Quaternion::rotation_y(-0.5) * Quaternion::rotation_z(PI / 2.0);
170
171            next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
172            next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
173            next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
174            next.foot_l.position = Vec3::new(-s_a.foot.0, s_a.foot.1, s_a.foot.2);
175            next.foot_r.position = Vec3::new(s_a.foot.0, s_a.foot.1, s_a.foot.2);
176        }
177
178        next
179    }
180}