veloren_voxygen_anim/dragon/
idle.rs1use super::{
2 super::{Animation, vek::*},
3 DragonSkeleton, SkeletonAttr,
4};
5use std::{f32::consts::PI, ops::Mul};
6
7pub struct IdleAnimation;
8
9impl Animation for IdleAnimation {
10 type Dependency<'a> = f32;
11 type Skeleton = DragonSkeleton;
12
13 #[cfg(feature = "use-dyn-lib")]
14 const UPDATE_FN: &'static [u8] = b"dragon_idle\0";
15
16 #[cfg_attr(feature = "be-dyn-lib", export_name = "dragon_idle")]
17 fn update_skeleton_inner(
18 skeleton: &Self::Skeleton,
19 global_time: Self::Dependency<'_>,
20 anim_time: f32,
21 _rate: &mut f32,
22 s_a: &SkeletonAttr,
23 ) -> Self::Skeleton {
24 let mut next = (*skeleton).clone();
25
26 let ultra_slow = (anim_time * 1.0).sin();
27 let slow = (anim_time * 2.5).sin();
28 let slowalt = (anim_time * 2.5 + PI / 2.0).sin();
29
30 let dragon_look = Vec2::new(
31 (global_time / 2.0 + anim_time / 8.0)
32 .floor()
33 .mul(7331.0)
34 .sin()
35 * 0.5,
36 (global_time / 2.0 + anim_time / 8.0)
37 .floor()
38 .mul(1337.0)
39 .sin()
40 * 0.25,
41 );
42
43 next.head_upper.scale = Vec3::one() * 1.05;
44 next.head_lower.scale = Vec3::one() * 1.05;
45 next.jaw.scale = Vec3::one() * 1.05;
46 next.tail_front.scale = Vec3::one() * 0.98;
47 next.tail_rear.scale = Vec3::one() * 0.98;
48
49 next.head_upper.position =
50 Vec3::new(0.0, s_a.head_upper.0, s_a.head_upper.1 + ultra_slow * 0.20);
51 next.head_upper.orientation = Quaternion::rotation_z(0.8 * dragon_look.x)
52 * Quaternion::rotation_x(0.8 * dragon_look.y);
53
54 next.head_lower.position =
55 Vec3::new(0.0, s_a.head_lower.0, s_a.head_lower.1 + ultra_slow * 0.20);
56 next.head_lower.orientation = Quaternion::rotation_z(0.8 * dragon_look.x)
57 * Quaternion::rotation_x(-0.2 + 0.8 * dragon_look.y);
58
59 next.jaw.position = Vec3::new(0.0, s_a.jaw.0, s_a.jaw.1);
60 next.jaw.orientation = Quaternion::rotation_x(slow * 0.04);
61
62 next.chest_front.position = Vec3::new(0.0, s_a.chest_front.0, s_a.chest_front.1);
63 next.chest_front.orientation = Quaternion::rotation_y(0.0);
64
65 next.chest_rear.position = Vec3::new(0.0, s_a.chest_rear.0, s_a.chest_rear.1);
66 next.chest_rear.orientation = Quaternion::rotation_y(0.0);
67
68 next.tail_front.position = Vec3::new(0.0, s_a.tail_front.0, s_a.tail_front.1);
69 next.tail_front.orientation =
70 Quaternion::rotation_z(slowalt * 0.10) * Quaternion::rotation_x(0.1);
71
72 next.tail_rear.position = Vec3::new(0.0, s_a.tail_rear.0, s_a.tail_rear.1);
73 next.tail_rear.orientation =
74 Quaternion::rotation_z(slowalt * 0.12) * Quaternion::rotation_x(0.05);
75
76 next.foot_fl.position = Vec3::new(-s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2);
77
78 next.foot_fr.position = Vec3::new(s_a.feet_f.0, s_a.feet_f.1, s_a.feet_f.2);
79
80 next.foot_bl.position = Vec3::new(-s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2);
81
82 next.foot_br.position = Vec3::new(s_a.feet_b.0, s_a.feet_b.1, s_a.feet_b.2);
83
84 next.wing_in_l.position = Vec3::new(-s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
85 next.wing_in_l.orientation = Quaternion::rotation_y(0.8 + slow * 0.02);
86
87 next.wing_in_r.position = Vec3::new(s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
88 next.wing_in_r.orientation = Quaternion::rotation_y(-0.8 - slow * 0.02);
89
90 next.wing_out_l.position = Vec3::new(-s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
91 next.wing_out_l.orientation = Quaternion::rotation_y(-2.0 + slow * 0.02);
92
93 next.wing_out_r.position = Vec3::new(s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
94 next.wing_out_r.orientation = Quaternion::rotation_y(2.0 - slow * 0.02);
95
96 next
97 }
98}