veloren_voxygen_anim/character/
consume.rs

1use super::{
2    super::{Animation, vek::*},
3    CharacterSkeleton, SkeletonAttr,
4};
5use common::{
6    comp::item::ConsumableKind,
7    states::{use_item::ItemUseKind, utils::StageSection},
8};
9
10pub struct ConsumeAnimation;
11
12impl Animation for ConsumeAnimation {
13    type Dependency<'a> = (f32, Option<StageSection>, Option<ItemUseKind>);
14    type Skeleton = CharacterSkeleton;
15
16    #[cfg(feature = "use-dyn-lib")]
17    const UPDATE_FN: &'static [u8] = b"character_consume\0";
18
19    #[cfg_attr(feature = "be-dyn-lib", export_name = "character_consume")]
20    fn update_skeleton_inner(
21        skeleton: &Self::Skeleton,
22        (_global_time, stage_section, item_kind): Self::Dependency<'_>,
23        anim_time: f32,
24        _rate: &mut f32,
25        s_a: &SkeletonAttr,
26    ) -> Self::Skeleton {
27        let mut next = (*skeleton).clone();
28
29        match item_kind {
30            Some(ItemUseKind::Consumable(ConsumableKind::Drink)) => {
31                let (move1, move2, move3) = match stage_section {
32                    Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
33                    Some(StageSection::Action) => (1.0, (anim_time * 8.0).sin(), 0.0),
34                    Some(StageSection::Recover) => (1.0, 1.0, anim_time.powf(0.25)),
35                    _ => (0.0, 0.0, 0.0),
36                };
37                let pullback = 1.0 - move3;
38                let move2 = move2 * pullback;
39                let move1 = move1 * pullback;
40                next.head.orientation = Quaternion::rotation_x(move1 * 0.5 + move2 * -0.05);
41
42                next.hand_r.position = Vec3::new(
43                    s_a.hand.0 + move1 * -4.0,
44                    s_a.hand.1 + move1 * 6.0,
45                    s_a.hand.2 + move1 * 10.0 + move2 * -1.0,
46                );
47                next.hand_r.orientation = Quaternion::rotation_x(move1 * 2.3 + move2 * -0.2)
48                    * Quaternion::rotation_y(move1 * 1.2);
49                next.chest.orientation = Quaternion::rotation_x(move1 * 0.25);
50                next.hand_l.position = Vec3::new(
51                    -s_a.hand.0 + move1 * 3.0,
52                    s_a.hand.1 + move1 * 2.0,
53                    s_a.hand.2,
54                );
55
56                next.hand_l.orientation =
57                    Quaternion::rotation_x(move1 * 0.8) * Quaternion::rotation_y(move1 * -0.5);
58            },
59            Some(ItemUseKind::Consumable(ConsumableKind::Charm)) => {
60                let (move1, move2, move3) = match stage_section {
61                    Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
62                    Some(StageSection::Action) => (1.0, (anim_time * 6.0).sin(), 0.0),
63                    Some(StageSection::Recover) => (1.0, 1.0, anim_time.powf(0.25)),
64                    _ => (0.0, 0.0, 0.0),
65                };
66
67                let pullback = 1.0 - move3;
68                let move1 = move1 * pullback;
69                let move2 = move2 * pullback;
70
71                next.head.orientation =
72                    Quaternion::rotation_x(move1 * -0.3) * Quaternion::rotation_z((move2) * 0.25);
73                next.chest.orientation = Quaternion::rotation_x(move1 * -0.2);
74                next.shoulder_r.orientation = Quaternion::rotation_x(move1 * 0.7);
75                next.shoulder_l.orientation = Quaternion::rotation_x(move1 * 0.7);
76
77                next.hand_r.position = Vec3::new(
78                    s_a.hand.0 - move1 * 1.5 + move2 * 1.0,
79                    s_a.hand.1 + move1 * 8.0,
80                    s_a.hand.2 + move1 * 4.0,
81                );
82                next.hand_l.position = Vec3::new(
83                    -s_a.hand.0 + move1 * 1.5 + move2 * 1.0,
84                    s_a.hand.1 + move1 * 8.0,
85                    s_a.hand.2 + move1 * 4.0,
86                );
87
88                next.hand_r.orientation =
89                    Quaternion::rotation_z(move1 * 0.4) * Quaternion::rotation_x(move1 * 2.3);
90                next.hand_l.orientation =
91                    Quaternion::rotation_z(move1 * -0.4) * Quaternion::rotation_x(move1 * 2.3);
92            },
93            Some(ItemUseKind::Consumable(ConsumableKind::Food | ConsumableKind::ComplexFood)) => {
94                let (move1, move2, move3) = match stage_section {
95                    Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
96                    Some(StageSection::Action) => (1.0, (anim_time * 12.0).sin(), 0.0),
97                    Some(StageSection::Recover) => (1.0, 1.0, anim_time.powf(0.25)),
98                    _ => (0.0, 0.0, 0.0),
99                };
100                let pullback = 1.0 - move3;
101                let move2 = move2 * pullback;
102                let move1 = move1 * pullback;
103                next.head.position =
104                    Vec3::new(0.0, s_a.head.0 + move1 * 2.0, s_a.head.1 + move1 * 1.0);
105                next.head.orientation =
106                    Quaternion::rotation_x(move1 * -0.3) * Quaternion::rotation_z(move2 * -0.15);
107
108                next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + move1 * -3.0);
109                next.chest.orientation =
110                    Quaternion::rotation_x(move1 * 0.3) * Quaternion::rotation_z(move2 * 0.05);
111
112                next.belt.position = Vec3::new(0.0, s_a.belt.0 + move1 * 1.0, s_a.belt.1);
113                next.belt.orientation = Quaternion::rotation_x(move1 * 0.2);
114
115                next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
116
117                next.shorts.position = Vec3::new(0.0, s_a.shorts.0 + move1 * 3.0, s_a.shorts.1);
118                next.shorts.orientation = Quaternion::rotation_x(move1 * 0.7);
119
120                next.hand_l.position = Vec3::new(
121                    -s_a.hand.0 + move1 * 3.0 + move2 * -1.0,
122                    s_a.hand.1 + move1 * 5.0,
123                    s_a.hand.2 + move1 * 3.0 + move2 * -2.0,
124                );
125
126                next.hand_l.orientation = Quaternion::rotation_x(move1 * 1.2)
127                    * Quaternion::rotation_y(move1 * -0.5 + move2 * 0.3);
128
129                next.hand_r.position = Vec3::new(
130                    s_a.hand.0 + move1 * -3.0 + move2 * -1.0,
131                    s_a.hand.1 + move1 * 5.0,
132                    s_a.hand.2 + move1 * 3.0 + move2 * 2.0,
133                );
134                next.hand_r.orientation = Quaternion::rotation_x(move1 * 1.2)
135                    * Quaternion::rotation_y(move1 * 0.5 + move2 * 0.3);
136
137                next.foot_l.position = Vec3::new(
138                    -s_a.foot.0,
139                    s_a.foot.1 + move1 * 5.0,
140                    s_a.foot.2 + move1 * 2.0,
141                );
142                next.foot_l.orientation = Quaternion::rotation_x(move1 * 1.2);
143
144                next.foot_r.position = Vec3::new(
145                    s_a.foot.0,
146                    s_a.foot.1 + move1 * 5.0,
147                    s_a.foot.2 + move1 * 2.0,
148                );
149                next.foot_r.orientation = Quaternion::rotation_x(move1 * 1.2);
150
151                next.shoulder_l.position =
152                    Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
153
154                next.shoulder_r.position =
155                    Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
156            },
157            _ => {},
158        }
159
160        next
161    }
162}