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