veloren_voxygen_anim/character/
equip.rs1use super::{
2 super::{Animation, vek::*},
3 CharacterSkeleton, SkeletonAttr,
4};
5use common::comp::item::ToolKind;
6use core::f32::consts::PI;
7
8pub struct EquipAnimation;
9
10impl Animation for EquipAnimation {
11 type Dependency<'a> = (Option<ToolKind>, Option<ToolKind>, f32, f32);
12 type Skeleton = CharacterSkeleton;
13
14 #[cfg(feature = "use-dyn-lib")]
15 const UPDATE_FN: &'static [u8] = b"character_equip\0";
16
17 #[cfg_attr(feature = "be-dyn-lib", unsafe(export_name = "character_equip"))]
18 fn update_skeleton_inner(
19 skeleton: &Self::Skeleton,
20 (active_tool_kind, _second_tool_kind, _velocity, _global_time): Self::Dependency<'_>,
21 anim_time: f32,
22 rate: &mut f32,
23 _s_a: &SkeletonAttr,
24 ) -> Self::Skeleton {
25 *rate = 1.0;
26 let mut next = (*skeleton).clone();
27 let equip_alt = (4.0 * anim_time).min(1.0);
28 let equip_slow = 1.0 + (anim_time * 12.0 + PI).cos();
29 let equip_slowa = 1.0 + (anim_time * 12.0 + PI / 4.0).cos();
30 next.hand_l.orientation = Quaternion::rotation_y(-2.3) * Quaternion::rotation_z(PI / 2.0);
31 next.hand_r.orientation = Quaternion::rotation_y(-2.3) * Quaternion::rotation_z(PI / 2.0);
32 next.control.position = Vec3::new(equip_slowa * -1.5, 0.0, equip_slow * 1.5);
33
34 match active_tool_kind {
35 Some(ToolKind::Sword) => {
36 next.hand_l.position = Vec3::new(-8.0, -5.0, 17.0);
37 next.hand_r.position = Vec3::new(-6.0, -4.5, 14.0);
38 },
39 Some(ToolKind::Axe) => {
40 next.hand_l.position = Vec3::new(-7.0, -5.0, 17.0);
41 next.hand_r.position = Vec3::new(-5.0, -4.5, 14.0);
42 },
43 Some(ToolKind::Hammer | ToolKind::Pick | ToolKind::Shovel) => {
44 next.hand_l.position = Vec3::new(-5.0, -5.0, 13.0);
45 next.hand_r.position = Vec3::new(-3.0, -4.5, 10.0);
46 },
47 Some(ToolKind::Staff) | Some(ToolKind::Sceptre) => {
48 next.hand_l.position = Vec3::new(-3.0, -5.0, 8.0);
49 next.hand_r.position = Vec3::new(-1.75, -4.5, 5.0);
50 },
51 Some(ToolKind::Bow) => {
52 next.hand_l.position = Vec3::new(-3.0, -5.0, 9.0);
53 next.hand_r.position = Vec3::new(-1.75, -4.5, 7.0);
54 },
55 Some(ToolKind::Instrument) => {
56 next.hand_l.position = Vec3::new(-5.0, -5.0, 8.0);
57 },
58 Some(ToolKind::Throwable) => {
59 next.main.position += Vec3::new(0.0, 0.0, 4.0) * equip_alt;
60 next.main.orientation.rotate_x(-PI / 3.0 * equip_alt);
61 next.main.scale = Vec3::one() * equip_alt;
62 next.second.position += Vec3::new(0.0, 0.0, 4.0) * equip_alt;
63 next.second.orientation.rotate_x(-PI / 3.0 * equip_alt);
64 next.second.scale = Vec3::one() * equip_alt;
65 },
66 _ => {},
67 }
68
69 next
70 }
71}