veloren_voxygen_anim/object/
shoot.rs

1use super::{
2    super::{Animation, vek::*},
3    ObjectSkeleton, SkeletonAttr,
4};
5use common::{
6    comp::{item::ToolKind, object::Body},
7    states::utils::StageSection,
8};
9pub struct ShootAnimation;
10
11type ShootAnimationDependency = (
12    Option<ToolKind>,
13    Option<ToolKind>,
14    Option<StageSection>,
15    Body,
16);
17impl Animation for ShootAnimation {
18    type Dependency<'a> = ShootAnimationDependency;
19    type Skeleton = ObjectSkeleton;
20
21    #[cfg(feature = "use-dyn-lib")]
22    const UPDATE_FN: &'static [u8] = b"object_shoot\0";
23
24    #[cfg_attr(feature = "be-dyn-lib", export_name = "object_shoot")]
25    fn update_skeleton_inner(
26        skeleton: &Self::Skeleton,
27        (_active_tool_kind, _second_tool_kind, stage_section, body): Self::Dependency<'_>,
28        anim_time: f32,
29        rate: &mut f32,
30        s_a: &SkeletonAttr,
31    ) -> Self::Skeleton {
32        *rate = 1.0;
33
34        let mut next = (*skeleton).clone();
35
36        let (movement1, movement2, movement3) = match stage_section {
37            Some(StageSection::Buildup) => (anim_time, 0.0, 0.0),
38            Some(StageSection::Action) => (1.0, anim_time.powf(0.25), 0.0),
39            Some(StageSection::Recover) => (1.0, 1.0, anim_time),
40            _ => (0.0, 0.0, 0.0),
41        };
42
43        next.bone0.position = Vec3::new(s_a.bone0.0, s_a.bone0.1, s_a.bone0.2);
44        next.bone1.position = Vec3::new(s_a.bone1.0, s_a.bone1.1, s_a.bone1.2);
45
46        #[expect(clippy::single_match)]
47        match body {
48            Body::Crossbow => {
49                next.bone0.position = Vec3::new(s_a.bone0.0, s_a.bone0.1, s_a.bone0.2);
50                next.bone0.orientation =
51                    Quaternion::rotation_x(movement1 * 0.05 + movement2 * 0.1) * (1.0 - movement3);
52
53                next.bone1.position = Vec3::new(s_a.bone1.0, s_a.bone1.1, s_a.bone1.2);
54                next.bone1.orientation = Quaternion::rotation_z(0.0);
55            },
56            _ => {},
57        }
58
59        next
60    }
61}