veloren_voxygen_anim/character/
talk.rs1use super::{
2 super::{Animation, vek::*},
3 CharacterSkeleton, SkeletonAttr,
4};
5use common::{comp::item::ToolKind, util::Dir};
6use core::f32::consts::PI;
7
8pub struct TalkAnimation;
9
10impl Animation for TalkAnimation {
11 type Dependency<'a> = (Option<ToolKind>, Option<ToolKind>, f32, f32, Dir);
12 type Skeleton = CharacterSkeleton;
13
14 #[cfg(feature = "use-dyn-lib")]
15 const UPDATE_FN: &'static [u8] = b"character_talk\0";
16
17 #[cfg_attr(feature = "be-dyn-lib", export_name = "character_talk")]
18 fn update_skeleton_inner(
19 skeleton: &Self::Skeleton,
20 (_active_tool_kind, _second_tool_kind, _velocity, _global_time, look_dir): Self::Dependency<
21 '_,
22 >,
23 anim_time: f32,
24 rate: &mut f32,
25 s_a: &SkeletonAttr,
26 ) -> Self::Skeleton {
27 *rate = 1.0;
28 let mut next = (*skeleton).clone();
29
30 let slowa = (anim_time * 6.0).sin();
31 let slowb = (anim_time * 4.0 + PI / 2.0).sin();
32 let slowc = (anim_time * 12.0 + PI / 2.0).sin();
33
34 next.head.orientation =
35 Quaternion::rotation_x(slowc * 0.035 + look_dir.z.atan2(look_dir.xy().magnitude()));
36 next.hand_l.position = Vec3::new(
37 -s_a.hand.0 + 0.5 + slowb * 0.5,
38 s_a.hand.1 + 5.0 + slowc * 1.0,
39 s_a.hand.2 + 2.0 + slowa * 1.0,
40 );
41
42 next.hand_l.orientation = Quaternion::rotation_x(0.0);
43
44 next.hand_r.position = Vec3::new(
45 s_a.hand.0 - 0.5 + slowb * 0.5,
46 s_a.hand.1 + 4.0 + slowc * -1.0,
47 s_a.hand.2 + 2.0 + slowa * 1.0,
48 );
49 next.hand_l.orientation = Quaternion::rotation_y(-0.2 + slowb * 0.2 + slowa * 0.07)
50 * Quaternion::rotation_x(1.3 + slowa * 0.15);
51 next.hand_r.orientation = Quaternion::rotation_y(0.2 + slowa * -0.1 + slowb * 0.07)
52 * Quaternion::rotation_x(1.3 + slowb * -0.15 + slowc * 0.05);
53
54 next
55 }
56}