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 next.head.scale = Vec3::one() * s_a.head_scale;
69 next.shoulder_l.scale = Vec3::one() * 1.1;
70 next.shoulder_r.scale = Vec3::one() * 1.1;
71 next.back.scale = Vec3::one() * 1.02;
72
73 next.head.position = Vec3::new(0.0, s_a.head.0, -1.0 + s_a.head.1);
74 next.head.orientation =
75 Quaternion::rotation_x(0.25 + slow * 0.04) * Quaternion::rotation_z(tilt * -2.5);
76
77 next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + 1.0);
78 next.chest.orientation =
79 Quaternion::rotation_x(speednorm * -0.3) * Quaternion::rotation_z(tilt * -2.0);
80
81 next.belt.position = Vec3::new(
82 0.0,
83 s_a.belt.0 + speednorm * 1.2,
84 s_a.belt.1 + speednorm * 1.0,
85 );
86 next.belt.orientation =
87 Quaternion::rotation_x(speednorm * 0.3) * Quaternion::rotation_z(tilt * 2.0);
88
89 next.back.position = Vec3::new(0.0, s_a.back.0, s_a.back.1);
90 next.back.orientation = Quaternion::rotation_z(0.0);
91
92 next.shorts.position = Vec3::new(
93 0.0,
94 s_a.shorts.0 + speednorm * 1.2,
95 s_a.shorts.1 + speednorm * 1.0,
96 );
97 next.shorts.orientation =
98 Quaternion::rotation_x(speednorm * 0.5) * Quaternion::rotation_z(tilt * 3.0);
99
100 if switch > 0.0 {
101 next.hand_l.position = Vec3::new(
102 -s_a.hand.0,
103 1.0 + s_a.hand.1 + 4.0,
104 2.0 + s_a.hand.2 + slow * 1.5,
105 );
106 next.hand_l.orientation =
107 Quaternion::rotation_x(1.9 + slow * 0.4) * Quaternion::rotation_y(0.2);
108
109 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1 - 3.0, s_a.hand.2 + slow * 1.5);
110 next.hand_r.orientation =
111 Quaternion::rotation_x(-0.5 + slow * -0.4) * Quaternion::rotation_y(-0.2);
112 } else {
113 next.hand_l.position =
114 Vec3::new(-s_a.hand.0, s_a.hand.1 - 3.0, s_a.hand.2 + slow * 1.5);
115 next.hand_l.orientation =
116 Quaternion::rotation_x(-0.5 + slow * -0.4) * Quaternion::rotation_y(0.2);
117
118 next.hand_r.position = Vec3::new(
119 s_a.hand.0,
120 1.0 + s_a.hand.1 + 4.0,
121 2.0 + s_a.hand.2 + slow * 1.5,
122 );
123 next.hand_r.orientation =
124 Quaternion::rotation_x(1.9 + slow * 0.4) * Quaternion::rotation_y(-0.2);
125 };
126
127 next.foot_l.position = Vec3::new(
128 -s_a.foot.0,
129 s_a.foot.1 - 5.0 * switch,
130 2.0 + s_a.foot.2 + slow * 1.5 + falling * -2.0,
131 );
132 next.foot_l.orientation = Quaternion::rotation_x(-0.8 * switch + slow * -0.2 * switch);
133
134 next.foot_r.position = Vec3::new(
135 s_a.foot.0,
136 s_a.foot.1 + 5.0 * switch,
137 2.0 + s_a.foot.2 + slow * 1.5 + falling * -2.0,
138 );
139 next.foot_r.orientation = Quaternion::rotation_x(0.8 * switch + slow * 0.2 * switch);
140
141 next.shoulder_l.position = Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
142 next.shoulder_l.orientation = Quaternion::rotation_x(0.4 * switch);
143
144 next.shoulder_r.position = Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
145 next.shoulder_r.orientation = Quaternion::rotation_x(-0.4 * switch);
146
147 next.glider.position = Vec3::new(0.0, 0.0, 10.0);
148 next.glider.scale = Vec3::one() * 0.0;
149
150 next.do_tools_on_back(hands, active_tool_kind, second_tool_kind);
151
152 next.do_hold_lantern(
153 s_a,
154 anim_time,
155 anim_time,
156 speednorm,
157 0.0,
158 tilt,
159 Some(last_ori),
160 Some(*look_dir),
161 );
162
163 next.torso.position = Vec3::new(0.0, 0.0, 0.0);
164 next.torso.orientation = Quaternion::rotation_x(0.0);
165
166 next
167 }
168}