veloren_voxygen_anim/bird_large/
breathe.rs

1use super::{
2    super::{Animation, vek::*},
3    BirdLargeSkeleton, SkeletonAttr,
4};
5use common::{states::utils::StageSection, util::Dir};
6
7pub struct BreatheAnimation;
8
9type BreatheAnimationDependency<'a> = (
10    Vec3<f32>,
11    f32,
12    Vec3<f32>,
13    Vec3<f32>,
14    Option<StageSection>,
15    f32,
16    Dir,
17    bool,
18    Option<&'a str>,
19);
20
21impl Animation for BreatheAnimation {
22    type Dependency<'a> = BreatheAnimationDependency<'a>;
23    type Skeleton = BirdLargeSkeleton;
24
25    #[cfg(feature = "use-dyn-lib")]
26    const UPDATE_FN: &'static [u8] = b"bird_large_breathe\0";
27
28    #[cfg_attr(feature = "be-dyn-lib", export_name = "bird_large_breathe")]
29    fn update_skeleton_inner(
30        skeleton: &Self::Skeleton,
31        (
32            velocity,
33            global_time,
34            _orientation,
35            _last_ori,
36            stage_section,
37            timer,
38            look_dir,
39            on_ground,
40            ability_id,
41        ): Self::Dependency<'_>,
42        anim_time: f32,
43        _rate: &mut f32,
44        s_a: &SkeletonAttr,
45    ) -> Self::Skeleton {
46        let mut next = (*skeleton).clone();
47
48        let (movement1base, movement2base, movement3, twitch) = match stage_section {
49            Some(StageSection::Buildup) => (anim_time.powf(0.25), 0.0, 0.0, 0.0),
50            Some(StageSection::Action) => (1.0, anim_time.min(1.0).powf(0.1), 0.0, anim_time),
51            Some(StageSection::Recover) => (1.0, 1.0, anim_time, 1.0),
52            _ => (0.0, 0.0, 0.0, 0.0),
53        };
54
55        let pullback = 1.0 - movement3;
56        let subtract = global_time - timer;
57        let check = subtract - subtract.trunc();
58        let mirror = (check - 0.5).signum();
59        let twitch2 = mirror * (twitch * 20.0).sin() * pullback;
60
61        let movement1abs = movement1base * pullback;
62        let movement2abs = movement2base * pullback;
63
64        let wave_slow_cos = (anim_time * 4.5).cos();
65
66        next.chest.position = Vec3::new(
67            0.0,
68            s_a.chest.0,
69            s_a.chest.1 + wave_slow_cos * 0.06 + twitch2 * 0.1,
70        );
71
72        next.neck.position = Vec3::new(0.0, s_a.neck.0, s_a.neck.1);
73        next.neck.orientation =
74            Quaternion::rotation_x(movement1abs * 0.8 - movement2abs * 0.5 + twitch2 * -0.02);
75
76        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
77        next.head.orientation =
78            Quaternion::rotation_x(movement1abs * 0.5 - movement2abs * 0.5 + look_dir.z * 0.4);
79
80        next.beak.position = Vec3::new(0.0, s_a.beak.0, s_a.beak.1);
81        next.beak.orientation = Quaternion::rotation_x(movement1abs * -0.7 + twitch2 * 0.1);
82
83        if on_ground {
84            next.chest.orientation =
85                Quaternion::rotation_x(movement1abs * 0.2 - movement2abs * 0.5 + twitch2 * 0.03);
86            next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + movement2abs * -3.0);
87            next.wing_in_l.position = Vec3::new(-s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
88            next.wing_in_r.position = Vec3::new(s_a.wing_in.0, s_a.wing_in.1, s_a.wing_in.2);
89
90            next.wing_in_l.orientation =
91                Quaternion::rotation_y(
92                    -1.0 + movement1abs * 0.8 - movement2abs * 0.4 + twitch2 * 0.03,
93                ) * Quaternion::rotation_z(0.2 - movement1abs * 0.8 + movement2abs * 0.4);
94            next.wing_in_r.orientation =
95                Quaternion::rotation_y(
96                    1.0 - movement1abs * 0.8 + movement2abs * 0.4 + twitch2 * -0.03,
97                ) * Quaternion::rotation_z(-0.2 + movement1abs * 0.8 - movement2abs * 0.4);
98
99            next.wing_mid_l.position = Vec3::new(-s_a.wing_mid.0, s_a.wing_mid.1, s_a.wing_mid.2);
100            next.wing_mid_r.position = Vec3::new(s_a.wing_mid.0, s_a.wing_mid.1, s_a.wing_mid.2);
101            next.wing_mid_l.orientation =
102                Quaternion::rotation_y(-0.1) * Quaternion::rotation_z(0.7);
103            next.wing_mid_r.orientation =
104                Quaternion::rotation_y(0.1) * Quaternion::rotation_z(-0.7);
105
106            next.wing_out_l.position = Vec3::new(-s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
107            next.wing_out_r.position = Vec3::new(s_a.wing_out.0, s_a.wing_out.1, s_a.wing_out.2);
108            next.wing_out_l.orientation =
109                Quaternion::rotation_y(-0.2) * Quaternion::rotation_z(0.2);
110            next.wing_out_r.orientation =
111                Quaternion::rotation_y(0.2) * Quaternion::rotation_z(-0.2);
112
113            next.tail_front.position = Vec3::new(0.0, s_a.tail_front.0, s_a.tail_front.1);
114            next.tail_front.orientation =
115                Quaternion::rotation_x(-movement1abs * 0.1 + movement2abs * 0.1 + twitch2 * 0.1);
116            next.tail_rear.position = Vec3::new(0.0, s_a.tail_rear.0, s_a.tail_rear.1);
117            next.tail_rear.orientation =
118                Quaternion::rotation_x(-movement1abs * 0.1 + movement2abs * 0.1 + twitch2 * -0.2);
119        } else {
120            match ability_id {
121                Some("common.abilities.custom.birdlargefire.heat_laser") => {
122                    next.chest.orientation = Quaternion::rotation_x(
123                        movement1abs * 0.2 - movement2abs * 0.5 + twitch2 * 0.03,
124                    );
125                    next.chest.position =
126                        Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + movement2abs * -3.0);
127                    next.neck.orientation = Quaternion::rotation_x(
128                        movement1abs * -0.4
129                            + movement2abs * (-0.5 + velocity.xy().magnitude() * 0.2).min(0.0),
130                    );
131
132                    next.head.orientation = Quaternion::rotation_x(
133                        movement1abs * 0.5
134                            + movement2abs * (-0.5 + velocity.xy().magnitude() * 0.2).min(0.0)
135                            + look_dir.z * 0.4,
136                    );
137                },
138                _ => {
139                    next.neck.orientation = Quaternion::rotation_x(
140                        movement1abs * -0.4
141                            + movement2abs * (-0.5 + velocity.xy().magnitude() * 0.2).min(0.0),
142                    );
143
144                    next.head.orientation = Quaternion::rotation_x(
145                        movement1abs * 0.5
146                            + movement2abs * (-0.5 + velocity.xy().magnitude() * 0.2).min(0.0)
147                            + look_dir.z * 0.4,
148                    );
149                },
150            };
151        }
152        next
153    }
154}