veloren_voxygen_anim/theropod/
combomelee.rs

1use super::{
2    super::{Animation, vek::*},
3    SkeletonAttr, TheropodSkeleton,
4};
5use common::states::utils::StageSection;
6
7pub struct ComboAnimation;
8
9impl Animation for ComboAnimation {
10    type Dependency<'a> = (Option<&'a str>, StageSection, usize, f32, f32);
11    type Skeleton = TheropodSkeleton;
12
13    #[cfg(feature = "use-dyn-lib")]
14    const UPDATE_FN: &'static [u8] = b"theropod_combo\0";
15
16    #[cfg_attr(feature = "be-dyn-lib", export_name = "theropod_combo")]
17    fn update_skeleton_inner(
18        skeleton: &Self::Skeleton,
19        (_ability_id, stage_section, current_strike, global_time, timer): 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 multi_strike_pullback = 1.0
27            - if matches!(stage_section, StageSection::Recover) {
28                anim_time.powi(4)
29            } else {
30                0.0
31            };
32
33        for strike in 0..=current_strike {
34            match strike {
35                0 => {
36                    let (movement1base, movement2base) = match stage_section {
37                        StageSection::Buildup => (anim_time.powi(2), 0.0),
38                        StageSection::Action => (1.0, anim_time.powi(4)),
39                        _ => (0.0, 0.0),
40                    };
41                    let subtract = global_time - timer;
42                    let check = subtract - subtract.trunc();
43                    let mirror = (check - 0.5).signum();
44                    let movement1 = mirror * movement1base * multi_strike_pullback;
45                    let movement2 = mirror * movement2base * multi_strike_pullback;
46                    let movement1abs = movement1base * multi_strike_pullback;
47                    let movement2abs = movement2base * multi_strike_pullback;
48
49                    next.head.orientation = Quaternion::rotation_x(movement1abs * 0.2)
50                        * Quaternion::rotation_y(movement1 * 0.1 + movement2 * 0.2);
51                    next.neck.orientation = Quaternion::rotation_x(movement1abs * -0.3)
52                        * Quaternion::rotation_y(movement1 * 0.1 + movement2 * 0.1);
53
54                    next.jaw.orientation =
55                        Quaternion::rotation_x(movement1abs * -0.5 + movement2abs * 0.5);
56
57                    next.chest_front.orientation = Quaternion::rotation_x(movement1abs * -0.2);
58                    next.chest_back.orientation = Quaternion::rotation_x(movement1abs * 0.2);
59
60                    next.leg_l.orientation = Quaternion::rotation_x(movement1abs * -0.1);
61
62                    next.leg_r.orientation = Quaternion::rotation_x(movement1abs * -0.1);
63                    next.foot_l.orientation = Quaternion::rotation_x(movement1abs * -0.3);
64                    next.foot_r.orientation = Quaternion::rotation_x(movement1abs * -0.3);
65
66                    next.tail_front.orientation =
67                        Quaternion::rotation_x(0.1 + movement1abs * -0.1 + movement2abs * -0.3)
68                            * Quaternion::rotation_z(movement1 * -0.1 + movement2 * -0.2);
69
70                    next.tail_back.orientation =
71                        Quaternion::rotation_x(0.1 + movement1abs * -0.1 + movement2abs * -0.3)
72                            * Quaternion::rotation_z(movement1 * -0.1 + movement2 * -0.2);
73                },
74                1 | 2 => {
75                    let (movement1base, movement2base) = match stage_section {
76                        StageSection::Buildup => (anim_time.powi(2), 0.0),
77                        StageSection::Action => (1.0, anim_time.powi(4)),
78                        _ => (0.0, 0.0),
79                    };
80                    let subtract = global_time - timer;
81                    let check = subtract - subtract.trunc();
82                    let mirror = (check - 0.5).signum();
83                    let movement1 = mirror * movement1base * multi_strike_pullback;
84                    let movement2 = mirror * movement2base * multi_strike_pullback;
85                    let movement1abs = movement1base * multi_strike_pullback;
86                    let movement2abs = movement2base * multi_strike_pullback;
87
88                    next.head.orientation =
89                        Quaternion::rotation_x(movement1abs * -0.4 + movement2abs * 1.2)
90                            * Quaternion::rotation_y(movement1 * 0.1 + movement2 * -0.1);
91                    next.neck.orientation =
92                        Quaternion::rotation_x(movement1abs * 0.4 + movement2abs * -1.2)
93                            * Quaternion::rotation_y(movement1 * 0.1 + movement2 * -0.1);
94
95                    next.chest_front.orientation =
96                        Quaternion::rotation_x(movement1abs * 0.6 + movement2abs * -1.5);
97                    next.chest_back.orientation =
98                        Quaternion::rotation_x(movement1abs * -0.6 + movement2abs * 1.5);
99
100                    next.leg_l.orientation = Quaternion::rotation_x(movement1abs * -0.5);
101
102                    next.leg_r.orientation = Quaternion::rotation_x(movement1abs * -0.5);
103                    next.foot_l.orientation = Quaternion::rotation_x(movement1abs * 0.4);
104                    next.foot_r.orientation = Quaternion::rotation_x(movement1abs * 0.4);
105
106                    next.tail_front.orientation =
107                        Quaternion::rotation_x(0.1 + movement1abs * -0.1 + movement2abs * -0.3);
108
109                    next.tail_back.orientation =
110                        Quaternion::rotation_x(0.1 + movement1abs * -0.1 + movement2abs * -0.3);
111                },
112                _ => {},
113            }
114        }
115
116        next
117    }
118}