veloren_voxygen_anim/character/
jump.rs1use super::{
2 super::{Animation, vek::*},
3 CharacterSkeleton, SkeletonAttr,
4};
5use common::{
6 comp::item::{Hands, ToolKind},
7 util::Dir,
8};
9
10pub struct JumpAnimation;
11impl Animation for JumpAnimation {
12 type Dependency<'a> = (
13 Option<ToolKind>,
14 Option<ToolKind>,
15 (Option<Hands>, Option<Hands>),
16 Vec3<f32>,
17 Vec3<f32>,
18 Vec3<f32>,
19 Dir,
20 f32,
21 );
22 type Skeleton = CharacterSkeleton;
23
24 #[cfg(feature = "use-dyn-lib")]
25 const UPDATE_FN: &'static [u8] = b"character_jump\0";
26
27 #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "character_jump"))]
28 fn update_skeleton_inner(
29 skeleton: &Self::Skeleton,
30 (
31 active_tool_kind,
32 second_tool_kind,
33 hands,
34 velocity,
35 orientation,
36 last_ori,
37 look_dir,
38 global_time,
39 ): Self::Dependency<'_>,
40 anim_time: f32,
41 _rate: &mut f32,
42 s_a: &SkeletonAttr,
43 ) -> Self::Skeleton {
44 let mut next = (*skeleton).clone();
45 let slow = (anim_time * 7.0).sin();
46
47 let subtract = global_time - anim_time;
48 let check = subtract - subtract.trunc();
49 let switch = (check - 0.5).signum();
50
51 let falling = (velocity.z * 0.1).clamped(-1.0, 1.0);
52 let speed = Vec2::<f32>::from(velocity).magnitude();
53 let speednorm = (speed / 10.0).min(1.0);
54
55 let ori: Vec2<f32> = Vec2::from(orientation);
56 let last_ori_xy = Vec2::from(last_ori);
57 let tilt = if vek::Vec2::new(ori, last_ori_xy)
58 .map(|o| o.magnitude_squared())
59 .map(|m| m > 0.001 && m.is_finite())
60 .reduce_and()
61 && ori.angle_between(last_ori_xy).is_finite()
62 {
63 ori.angle_between(last_ori_xy).min(0.2)
64 * last_ori_xy.determine_side(Vec2::zero(), ori).signum()
65 } else {
66 0.0
67 } * 1.3;
68
69 next.hold.scale = Vec3::one() * 0.0;
70
71 next.head.scale = Vec3::one() * s_a.head_scale;
72 next.shoulder_l.scale = Vec3::one() * 1.1;
73 next.shoulder_r.scale = Vec3::one() * 1.1;
74 next.back.scale = Vec3::one() * 1.02;
75
76 next.head.position = Vec3::new(0.0, s_a.head.0, -1.0 + s_a.head.1);
77 next.head.orientation =
78 Quaternion::rotation_x(0.25 + slow * 0.04) * Quaternion::rotation_z(tilt * -2.5);
79
80 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + 1.0);
81 next.chest.orientation =
82 Quaternion::rotation_x(speednorm * -0.3) * Quaternion::rotation_z(tilt * -2.0);
83
84 next.belt.position = Vec3::new(
85 0.0,
86 s_a.belt.0 + speednorm * 1.2,
87 s_a.belt.1 + speednorm * 1.0,
88 );
89 next.belt.orientation =
90 Quaternion::rotation_x(speednorm * 0.3) * Quaternion::rotation_z(tilt * 2.0);
91
92 next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
93 next.back.orientation = Quaternion::rotation_z(0.0);
94
95 next.shorts.position = Vec3::new(
96 0.0,
97 s_a.shorts.0 + speednorm * 1.2,
98 s_a.shorts.1 + speednorm * 1.0,
99 );
100 next.shorts.orientation =
101 Quaternion::rotation_x(speednorm * 0.5) * Quaternion::rotation_z(tilt * 3.0);
102
103 if switch > 0.0 {
104 next.hand_l.position = Vec3::new(
105 -s_a.hand.0,
106 1.0 + s_a.hand.1 + 4.0,
107 2.0 + s_a.hand.2 + slow * 1.5,
108 );
109 next.hand_l.orientation =
110 Quaternion::rotation_x(1.9 + slow * 0.4) * Quaternion::rotation_y(0.2);
111
112 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1 - 3.0, s_a.hand.2 + slow * 1.5);
113 next.hand_r.orientation =
114 Quaternion::rotation_x(-0.5 + slow * -0.4) * Quaternion::rotation_y(-0.2);
115 } else {
116 next.hand_l.position =
117 Vec3::new(-s_a.hand.0, s_a.hand.1 - 3.0, s_a.hand.2 + slow * 1.5);
118 next.hand_l.orientation =
119 Quaternion::rotation_x(-0.5 + slow * -0.4) * Quaternion::rotation_y(0.2);
120
121 next.hand_r.position = Vec3::new(
122 s_a.hand.0,
123 1.0 + s_a.hand.1 + 4.0,
124 2.0 + s_a.hand.2 + slow * 1.5,
125 );
126 next.hand_r.orientation =
127 Quaternion::rotation_x(1.9 + slow * 0.4) * Quaternion::rotation_y(-0.2);
128 };
129
130 next.foot_l.position = Vec3::new(
131 -s_a.foot.0,
132 s_a.foot.1 - 5.0 * switch,
133 2.0 + s_a.foot.2 + slow * 1.5 + falling * -2.0,
134 );
135 next.foot_l.orientation = Quaternion::rotation_x(-0.8 * switch + slow * -0.2 * switch);
136
137 next.foot_r.position = Vec3::new(
138 s_a.foot.0,
139 s_a.foot.1 + 5.0 * switch,
140 2.0 + s_a.foot.2 + slow * 1.5 + falling * -2.0,
141 );
142 next.foot_r.orientation = Quaternion::rotation_x(0.8 * switch + slow * 0.2 * switch);
143
144 next.shoulder_l.position = Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
145 next.shoulder_l.orientation = Quaternion::rotation_x(0.4 * switch);
146
147 next.shoulder_r.position = Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
148 next.shoulder_r.orientation = Quaternion::rotation_x(-0.4 * switch);
149
150 next.glider.position = Vec3::new(0.0, 0.0, 10.0);
151 next.glider.scale = Vec3::one() * 0.0;
152
153 next.do_tools_on_back(hands, active_tool_kind, second_tool_kind);
154
155 next.do_hold_lantern(
156 s_a,
157 anim_time,
158 anim_time,
159 speednorm,
160 0.0,
161 tilt,
162 Some(last_ori),
163 Some(*look_dir),
164 );
165
166 next.torso.position = Vec3::new(0.0, 0.0, 0.0);
167 next.torso.orientation = Quaternion::rotation_x(0.0);
168
169 next
170 }
171}