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