veloren_voxygen_anim/character/
sneak.rs1use super::{
2 super::{Animation, vek::*},
3 CharacterSkeleton, SkeletonAttr,
4};
5use common::comp::item::ToolKind;
6use std::{f32::consts::PI, ops::Mul};
7
8pub struct SneakAnimation;
9
10impl Animation for SneakAnimation {
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_sneak\0";
16
17 #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "character_sneak"))]
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
76 next.hold.scale = Vec3::one() * 0.0;
77
78 if speed > 0.5 {
79 next.hand_l.position = Vec3::new(1.0 - s_a.hand.0, 4.0 + s_a.hand.1, 1.0 + s_a.hand.2);
80 next.hand_l.orientation = Quaternion::rotation_x(1.0);
81
82 next.hand_r.position = Vec3::new(-1.0 + s_a.hand.0, -1.0 + s_a.hand.1, s_a.hand.2);
83 next.hand_r.orientation = Quaternion::rotation_x(0.4);
84 next.head.position = Vec3::new(0.0, 1.0 + s_a.head.0, -1.0 + s_a.head.1 + short * 0.06);
85 next.head.orientation =
86 Quaternion::rotation_z(tilt * -2.5 + head_look.x * 0.2 - short * 0.06)
87 * Quaternion::rotation_x(head_look.y + 0.45);
88
89 next.chest.position = Vec3::new(0.0, s_a.chest.0, -1.0 + s_a.chest.1 + shortalt * -0.5);
90 next.chest.orientation = Quaternion::rotation_z(0.3 + short * 0.08 + tilt * -0.2)
91 * Quaternion::rotation_y(tilt * 0.8)
92 * Quaternion::rotation_x(-0.5);
93
94 next.belt.position = Vec3::new(0.0, 0.5 + s_a.belt.0, 0.7 + s_a.belt.1);
95 next.belt.orientation = Quaternion::rotation_z(short * 0.1 + tilt * -1.1)
96 * Quaternion::rotation_y(tilt * 0.5)
97 * Quaternion::rotation_x(0.2);
98
99 next.back.orientation =
100 Quaternion::rotation_x(-0.25 + short * 0.1 + noisea * 0.1 + noiseb * 0.1);
101
102 next.shorts.position = Vec3::new(0.0, 1.0 + s_a.shorts.0, 1.0 + s_a.shorts.1);
103 next.shorts.orientation = Quaternion::rotation_z(short * 0.16 + tilt * -1.5)
104 * Quaternion::rotation_y(tilt * 0.7)
105 * Quaternion::rotation_x(0.3);
106
107 next.foot_l.position = Vec3::new(
108 -s_a.foot.0,
109 s_a.foot.1 + foothoril * -10.5 * walkintensity - lower * 1.0,
110 1.0 + s_a.foot.2 + ((footvertl * -1.7).max(-1.0)) * walkintensity,
111 );
112 next.foot_l.orientation =
113 Quaternion::rotation_x(-0.2 + footrotl * -0.8 * walkintensity)
114 * Quaternion::rotation_y(tilt * 1.8);
115
116 next.foot_r.position = Vec3::new(
117 s_a.foot.0,
118 s_a.foot.1 + foothorir * -10.5 * walkintensity - lower * 1.0,
119 1.0 + s_a.foot.2 + ((footvertr * -1.7).max(-1.0)) * walkintensity,
120 );
121 next.foot_r.orientation =
122 Quaternion::rotation_x(-0.2 + footrotr * -0.8 * walkintensity)
123 * Quaternion::rotation_y(tilt * 1.8);
124
125 next.shoulder_l.orientation = Quaternion::rotation_x(short * 0.15 * walkintensity);
126
127 next.shoulder_r.orientation = Quaternion::rotation_x(short * -0.15 * walkintensity);
128
129 next.lantern.orientation =
130 Quaternion::rotation_x(shorte * 0.2 + 0.4) * Quaternion::rotation_y(shorte * 0.1);
131 } else {
132 next.head.position = Vec3::new(
133 0.0,
134 1.0 + s_a.head.0,
135 -2.0 + s_a.head.1 + slow * 0.1 + breathe * -0.05,
136 );
137 next.head.orientation = Quaternion::rotation_z(head_look.x)
138 * Quaternion::rotation_x(0.6 + head_look.y.abs());
139
140 next.chest.position = Vec3::new(0.0, s_a.chest.0, -3.0 + s_a.chest.1 + slow * 0.1);
141 next.chest.orientation = Quaternion::rotation_x(-0.7);
142
143 next.belt.position = Vec3::new(0.0, s_a.belt.0, s_a.belt.1);
144 next.belt.orientation = Quaternion::rotation_z(0.3 + head_look.x * -0.1);
145
146 next.hand_l.position = Vec3::new(1.0 - s_a.hand.0, 5.0 + s_a.hand.1, 0.0 + s_a.hand.2);
147 next.hand_l.orientation = Quaternion::rotation_x(1.35);
148
149 next.hand_r.position = Vec3::new(-1.0 + s_a.hand.0, s_a.hand.1, s_a.hand.2);
150 next.hand_r.orientation = Quaternion::rotation_x(0.4);
151
152 next.shorts.position = Vec3::new(0.0, s_a.shorts.0, s_a.shorts.1);
153 next.shorts.orientation = Quaternion::rotation_z(0.6 + head_look.x * -0.2);
154
155 next.foot_l.position = Vec3::new(-s_a.foot.0, -6.0 + s_a.foot.1, 1.0 + s_a.foot.2);
156 next.foot_l.orientation = Quaternion::rotation_x(-0.5);
157
158 next.foot_r.position = Vec3::new(s_a.foot.0, 4.0 + s_a.foot.1, s_a.foot.2);
159 }
160
161 next.do_hold_lantern(s_a, anim_time, anim_time, speed / 10.0, 0.0, tilt);
162
163 next
164 }
165}