veloren_voxygen_anim/character/
sneakequip.rs1use super::{
2 super::{Animation, vek::*},
3 CharacterSkeleton, SkeletonAttr,
4};
5use common::comp::item::ToolKind;
6use core::{f32::consts::PI, ops::Mul};
7
8pub struct SneakEquipAnimation;
9
10impl Animation for SneakEquipAnimation {
11 type Dependency<'a> = (Option<ToolKind>, Vec3<f32>, Vec3<f32>, Vec3<f32>, f32);
12 type Skeleton = CharacterSkeleton;
13
14 #[cfg(feature = "use-dyn-lib")]
15 const UPDATE_FN: &'static [u8] = b"character_sneakequip\0";
16
17 #[cfg_attr(feature = "be-dyn-lib", export_name = "character_sneakequip")]
18 fn update_skeleton_inner(
19 skeleton: &Self::Skeleton,
20 (active_tool_kind, velocity, orientation, last_ori, global_time): Self::Dependency<'_>,
21 anim_time: f32,
22 rate: &mut f32,
23 s_a: &SkeletonAttr,
24 ) -> Self::Skeleton {
25 let mut next = (*skeleton).clone();
26 let speed = Vec2::<f32>::from(velocity).magnitude();
27 *rate = 1.0;
28 let slow = (anim_time * 3.0).sin();
29 let breathe = ((anim_time * 0.5).sin()).abs();
30 let walkintensity = if speed > 5.0 { 1.0 } else { 0.45 };
31 let lower = if speed > 5.0 { 0.0 } else { 1.0 };
32 let _snapfoot = if speed > 5.0 { 1.1 } else { 2.0 };
33 let lab: f32 = 1.0;
34 let foothoril = (anim_time * 7.0 * lab + PI * 1.45).sin();
35 let foothorir = (anim_time * 7.0 * lab + PI * (0.45)).sin();
36
37 let footvertl = (anim_time * 7.0 * lab).sin();
38 let footvertr = (anim_time * 7.0 * lab + PI).sin();
39
40 let footrotl = ((5.0 / (2.5 + (2.5) * ((anim_time * 7.0 * lab + PI * 1.4).sin()).powi(2)))
41 .sqrt())
42 * ((anim_time * 7.0 * lab + PI * 1.4).sin());
43
44 let footrotr = ((5.0 / (1.0 + (4.0) * ((anim_time * 7.0 * lab + PI * 0.4).sin()).powi(2)))
45 .sqrt())
46 * ((anim_time * 7.0 * lab + PI * 0.4).sin());
47
48 let short = (anim_time * lab * 7.0).sin();
49 let noisea = (anim_time * 11.0 + PI / 6.0).sin();
50 let noiseb = (anim_time * 19.0 + PI / 4.0).sin();
51
52 let shorte = ((5.0 / (4.0 + 1.0 * ((anim_time * lab * 7.0).sin()).powi(2))).sqrt())
53 * ((anim_time * lab * 7.0).sin());
54
55 let shortalt = (anim_time * lab * 7.0 + PI / 2.0).sin();
56
57 let head_look = Vec2::new(
58 (global_time + anim_time / 18.0).floor().mul(7331.0).sin() * 0.2,
59 (global_time + anim_time / 18.0).floor().mul(1337.0).sin() * 0.1,
60 );
61
62 let orientation: Vec2<f32> = Vec2::from(orientation);
63 let last_ori = Vec2::from(last_ori);
64 let tilt = if vek::Vec2::new(orientation, last_ori)
65 .map(|o| o.magnitude_squared())
66 .map(|m| m > 0.001 && m.is_finite())
67 .reduce_and()
68 && orientation.angle_between(last_ori).is_finite()
69 {
70 orientation.angle_between(last_ori).min(0.2)
71 * last_ori.determine_side(Vec2::zero(), orientation).signum()
72 } else {
73 0.0
74 } * 1.3;
75 next.hold.scale = Vec3::one() * 0.0;
76
77 if speed > 0.5 {
78 next.hand_l.position = Vec3::new(1.0 - s_a.hand.0, 4.0 + s_a.hand.1, 1.0 + s_a.hand.2);
79 next.hand_l.orientation = Quaternion::rotation_x(1.0);
80
81 next.hand_r.position = Vec3::new(-1.0 + s_a.hand.0, -1.0 + s_a.hand.1, s_a.hand.2);
82 next.hand_r.orientation = Quaternion::rotation_x(0.4);
83 next.head.position = Vec3::new(0.0, 1.0 + s_a.head.0, -1.0 + s_a.head.1 + short * 0.06);
84 next.head.orientation =
85 Quaternion::rotation_z(tilt * -2.5 + head_look.x * 0.2 - short * 0.06)
86 * Quaternion::rotation_x(head_look.y + 0.45);
87
88 next.chest.position = Vec3::new(0.0, s_a.chest.0, -1.0 + s_a.chest.1 + shortalt * -0.5);
89 next.chest.orientation = Quaternion::rotation_z(0.3 + short * 0.08 + tilt * -0.2)
90 * Quaternion::rotation_y(tilt * 0.8)
91 * Quaternion::rotation_x(-0.5);
92
93 next.belt.position = Vec3::new(0.0, 0.5 + s_a.belt.0, 0.7 + s_a.belt.1);
94 next.belt.orientation = Quaternion::rotation_z(short * 0.1 + tilt * -1.1)
95 * Quaternion::rotation_y(tilt * 0.5)
96 * Quaternion::rotation_x(0.2);
97
98 next.back.orientation =
99 Quaternion::rotation_x(-0.25 + short * 0.1 + noisea * 0.1 + noiseb * 0.1);
100
101 next.shorts.position = Vec3::new(0.0, 1.0 + s_a.shorts.0, 1.0 + s_a.shorts.1);
102 next.shorts.orientation = Quaternion::rotation_z(short * 0.16 + tilt * -1.5)
103 * Quaternion::rotation_y(tilt * 0.7)
104 * Quaternion::rotation_x(0.3);
105
106 next.foot_l.position = Vec3::new(
107 -s_a.foot.0,
108 s_a.foot.1 + foothoril * -10.5 * walkintensity - lower * 1.0,
109 1.0 + s_a.foot.2 + ((footvertl * -1.7).max(-1.0)) * walkintensity,
110 );
111 next.foot_l.orientation =
112 Quaternion::rotation_x(-0.2 + footrotl * -0.8 * walkintensity)
113 * Quaternion::rotation_y(tilt * 1.8);
114
115 next.foot_r.position = Vec3::new(
116 s_a.foot.0,
117 s_a.foot.1 + foothorir * -10.5 * walkintensity - lower * 1.0,
118 1.0 + s_a.foot.2 + ((footvertr * -1.7).max(-1.0)) * walkintensity,
119 );
120 next.foot_r.orientation =
121 Quaternion::rotation_x(-0.2 + footrotr * -0.8 * walkintensity)
122 * Quaternion::rotation_y(tilt * 1.8);
123
124 next.shoulder_l.orientation = Quaternion::rotation_x(short * 0.15 * walkintensity);
125
126 next.shoulder_r.orientation = Quaternion::rotation_x(short * -0.15 * walkintensity);
127
128 next.lantern.orientation =
129 Quaternion::rotation_x(shorte * 0.2 + 0.4) * Quaternion::rotation_y(shorte * 0.1);
130 } else {
131 next.head.position = Vec3::new(
132 0.0,
133 1.0 + s_a.head.0,
134 -2.0 + s_a.head.1 + slow * 0.1 + breathe * -0.05,
135 );
136 next.head.orientation = Quaternion::rotation_z(head_look.x)
137 * Quaternion::rotation_x(0.6 + head_look.y.abs());
138
139 next.chest.position = Vec3::new(0.0, s_a.chest.0, -3.0 + s_a.chest.1 + slow * 0.1);
140 next.chest.orientation = Quaternion::rotation_x(-0.7);
141
142 next.belt.position = Vec3::new(0.0, s_a.belt.0, s_a.belt.1);
143 next.belt.orientation = Quaternion::rotation_z(0.3 + head_look.x * -0.1);
144
145 next.hand_l.position = Vec3::new(1.0 - s_a.hand.0, 5.0 + s_a.hand.1, 0.0 + s_a.hand.2);
146 next.hand_l.orientation = Quaternion::rotation_x(1.35);
147
148 next.hand_r.position = Vec3::new(-1.0 + s_a.hand.0, s_a.hand.1, s_a.hand.2);
149 next.hand_r.orientation = Quaternion::rotation_x(0.4);
150
151 next.shorts.position = Vec3::new(0.0, s_a.shorts.0, s_a.shorts.1);
152 next.shorts.orientation = Quaternion::rotation_z(0.6 + head_look.x * -0.2);
153
154 next.foot_l.position = Vec3::new(-s_a.foot.0, -6.0 + s_a.foot.1, 1.0 + s_a.foot.2);
155 next.foot_l.orientation = Quaternion::rotation_x(-0.5);
156
157 next.foot_r.position = Vec3::new(s_a.foot.0, 4.0 + s_a.foot.1, s_a.foot.2);
158 }
159
160 if skeleton.holding_lantern {
161 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1 + 5.0, s_a.hand.2 + 9.0);
162 next.hand_r.orientation = Quaternion::rotation_x(2.5);
163
164 next.lantern.position = Vec3::new(0.0, 1.5, -5.5);
165 next.lantern.orientation = next.hand_r.orientation.inverse();
166 }
167 let equip_slow = 1.0 + (anim_time * 12.0 + PI).cos();
168 let equip_slowa = 1.0 + (anim_time * 12.0 + PI / 4.0).cos();
169 next.hand_l.orientation = Quaternion::rotation_y(-2.3) * Quaternion::rotation_z(PI / 2.0);
170 next.hand_r.orientation = Quaternion::rotation_y(-2.3) * Quaternion::rotation_z(PI / 2.0);
171 next.control.position = Vec3::new(equip_slowa * -1.5, 0.0, equip_slow * 1.5);
172
173 match active_tool_kind {
174 Some(ToolKind::Sword) => {
175 next.hand_l.position = Vec3::new(-8.0, -5.0, 17.0);
176 next.hand_r.position = Vec3::new(-6.0, -4.5, 14.0);
177 },
178 Some(ToolKind::Axe) => {
179 next.hand_l.position = Vec3::new(-7.0, -5.0, 17.0);
180 next.hand_r.position = Vec3::new(-5.0, -4.5, 14.0);
181 },
182 Some(ToolKind::Hammer | ToolKind::Pick | ToolKind::Shovel) => {
183 next.hand_l.position = Vec3::new(-5.0, -5.0, 13.0);
184 next.hand_r.position = Vec3::new(-3.0, -4.5, 10.0);
185 },
186 Some(ToolKind::Staff) | Some(ToolKind::Sceptre) => {
187 next.hand_l.position = Vec3::new(-3.0, -5.0, 8.0);
188 next.hand_r.position = Vec3::new(-1.75, -4.5, 5.0);
189 },
190 Some(ToolKind::Bow) => {
191 next.hand_l.position = Vec3::new(-3.0, -5.0, 9.0);
192 next.hand_r.position = Vec3::new(-1.75, -4.5, 7.0);
193 },
194 Some(ToolKind::Instrument) => {
195 next.hand_l.position = Vec3::new(-3.0, -5.0, 10.0);
196 },
197 _ => {},
198 }
199 next
200 }
201}