veloren_voxygen_anim/biped_large/
idle.rs

1use super::{
2    super::{Animation, vek::*},
3    BipedLargeSkeleton, SkeletonAttr,
4};
5use common::comp::item::ToolKind;
6use core::{f32::consts::PI, ops::Mul};
7
8pub struct IdleAnimation;
9
10impl Animation for IdleAnimation {
11    type Dependency<'a> = (Option<ToolKind>, Option<ToolKind>, f32);
12    type Skeleton = BipedLargeSkeleton;
13
14    #[cfg(feature = "use-dyn-lib")]
15    const UPDATE_FN: &'static [u8] = b"biped_large_idle\0";
16
17    #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_idle")]
18    fn update_skeleton_inner(
19        skeleton: &Self::Skeleton,
20        (active_tool_kind, _second_tool_kind, 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 lab: f32 = 1.0;
28        let torso = (anim_time * lab + 1.5 * PI).sin() * 1.5;
29
30        let slower = (anim_time * 2.0 + PI).sin() * 1.5;
31        let slow = (anim_time * 7.0 + PI).sin() * 1.5;
32
33        let look = Vec2::new(
34            (global_time / 2.0 + anim_time / 8.0)
35                .floor()
36                .mul(7331.0)
37                .sin()
38                * 0.5,
39            (global_time / 2.0 + anim_time / 8.0)
40                .floor()
41                .mul(1337.0)
42                .sin()
43                * 0.25,
44        );
45
46        let breathe = if s_a.beast {
47            // Controls for the beast breathing
48            let intensity = 0.04;
49            let length = 1.5;
50            let chop = 0.2;
51            let chop_freq = 60.0;
52            intensity * (length * anim_time).sin()
53                + 0.05 * chop * (anim_time * chop_freq).sin() * (anim_time * length).cos()
54        } else {
55            0.0
56        };
57
58        next.jaw.scale = Vec3::one() * 1.02;
59        next.shoulder_l.scale = Vec3::one() * 1.1;
60        next.shoulder_r.scale = Vec3::one() * 1.1;
61        next.hand_l.scale = Vec3::one() * 1.04;
62        next.hand_r.scale = Vec3::one() * 1.04;
63        next.lower_torso.scale = Vec3::one() * 1.02;
64        next.hold.scale = Vec3::one() * 0.0;
65        next.second.scale = Vec3::one() * 0.0;
66
67        next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1 + torso * 0.2);
68        next.head.orientation =
69            Quaternion::rotation_z(look.x * 0.6) * Quaternion::rotation_x(look.y * 0.6 + breathe);
70
71        next.upper_torso.position =
72            Vec3::new(0.0, s_a.upper_torso.0, s_a.upper_torso.1 + torso * -0.5);
73        next.upper_torso.orientation = Quaternion::rotation_x(-breathe);
74
75        next.lower_torso.position =
76            Vec3::new(0.0, s_a.lower_torso.0, s_a.lower_torso.1 + torso * 0.5);
77        next.lower_torso.orientation = Quaternion::rotation_x(breathe);
78
79        if s_a.beast {
80            next.jaw.position = Vec3::new(0.0, s_a.jaw.0, s_a.jaw.1);
81        } else {
82            next.jaw.position = Vec3::new(0.0, s_a.jaw.0 - slower * 0.12, s_a.jaw.1 + slow * 0.2);
83        }
84        next.jaw.orientation = Quaternion::rotation_x(-0.1 + breathe * 2.0);
85
86        next.tail.position = Vec3::new(0.0, s_a.tail.0, s_a.tail.1);
87        next.tail.orientation =
88            Quaternion::rotation_z(0.0 + slow * 0.2) * Quaternion::rotation_x(0.0);
89
90        match active_tool_kind {
91            Some(ToolKind::Bow) => {
92                next.main.position = Vec3::new(0.0, -6.0, 0.0);
93                next.main.orientation =
94                    Quaternion::rotation_y(2.5) * Quaternion::rotation_z(PI / 2.0);
95            },
96            Some(ToolKind::Staff) | Some(ToolKind::Sceptre) => {
97                next.main.position = Vec3::new(-6.0, -5.0, -12.0);
98                next.main.orientation =
99                    Quaternion::rotation_y(0.6) * Quaternion::rotation_z(PI / 2.0);
100            },
101            Some(ToolKind::Sword) => {
102                next.main.position = Vec3::new(-10.0, -8.0, 12.0);
103                next.main.orientation =
104                    Quaternion::rotation_y(2.5) * Quaternion::rotation_z(PI / 2.0);
105            },
106            Some(ToolKind::Hammer) | Some(ToolKind::Axe) => {
107                next.main.position = Vec3::new(-6.0, -8.0, 8.0);
108                next.main.orientation =
109                    Quaternion::rotation_y(2.5) * Quaternion::rotation_z(PI / 2.0);
110                next.second.position = Vec3::new(6.0, -8.0, 8.0);
111                next.second.orientation =
112                    Quaternion::rotation_y(-2.5) * Quaternion::rotation_z(PI / 2.0);
113            },
114            _ => {
115                next.main.position = Vec3::new(-2.0, -5.0, -6.0);
116                next.main.orientation =
117                    Quaternion::rotation_y(0.6) * Quaternion::rotation_z(PI / 2.0);
118            },
119        }
120
121        next.shoulder_l.position = Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
122        next.shoulder_l.orientation = Quaternion::rotation_x(breathe);
123
124        next.shoulder_r.position = Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
125        next.shoulder_r.orientation = Quaternion::rotation_x(breathe);
126
127        next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2 + torso * -0.1);
128
129        next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2 + torso * -0.1);
130
131        next.leg_l.position = Vec3::new(-s_a.leg.0, s_a.leg.1, s_a.leg.2 + torso * -0.2);
132
133        next.leg_r.position = Vec3::new(s_a.leg.0, s_a.leg.1, s_a.leg.2 + torso * -0.2);
134
135        next.foot_l.position = Vec3::new(-s_a.foot.0, s_a.foot.1, s_a.foot.2);
136
137        next.foot_r.position = Vec3::new(s_a.foot.0, s_a.foot.1, s_a.foot.2);
138
139        next.torso.position = Vec3::new(0.0, 0.0, 0.0);
140
141        if s_a.float {
142            next.upper_torso.position = Vec3::new(
143                0.0,
144                s_a.upper_torso.0,
145                s_a.upper_torso.1 + slower * 1.0 + 4.0,
146            );
147            next.foot_l.orientation = Quaternion::rotation_x(-0.5 + slow * 0.1);
148            next.foot_r.orientation = Quaternion::rotation_x(-0.5 + slow * 0.1);
149        }
150
151        next
152    }
153}