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