veloren_voxygen_anim/character/
pet.rs1use super::{
2 super::{Animation, vek::*},
3 CharacterSkeleton, SkeletonAttr,
4};
5
6use std::f32::consts::PI;
7
8pub struct PetAnimation;
9
10impl Animation for PetAnimation {
11 type Dependency<'a> = (Vec3<f32>, Vec3<f32>, f32);
12 type Skeleton = CharacterSkeleton;
13
14 #[cfg(feature = "use-dyn-lib")]
15 const UPDATE_FN: &'static [u8] = b"character_pet\0";
16
17 #[cfg_attr(feature = "be-dyn-lib", export_name = "character_pet")]
18 fn update_skeleton_inner(
19 skeleton: &Self::Skeleton,
20 (pos, target_pos, _global_time): Self::Dependency<'_>,
21 anim_time: f32,
22 _rate: &mut f32,
23 s_a: &SkeletonAttr,
24 ) -> Self::Skeleton {
25 let mut next = (*skeleton).clone();
26
27 let fast = (anim_time * 3.0).sin();
28 let fast_offset = (anim_time * 3.0 + PI * 0.5).sin();
29
30 let z_diff = target_pos.z - pos.z;
31
32 next.head.orientation = Quaternion::rotation_x(-1. * PI / 2. / 9.);
34
35 next.hand_r.position = Vec3::new(
37 s_a.hand.0 + -2. * fast_offset,
38 s_a.hand.1 + 8.0,
39 s_a.hand.2 + 4.0 + 1. * fast + z_diff,
40 );
41
42 next.hand_r.orientation =
44 Quaternion::rotation_x(PI / 2. + fast * 0.15).rotated_z(fast_offset * 0.5);
45
46 next
47 }
48}