veloren_voxygen_anim/biped_small/
spritesummon.rs1use super::{
2 super::{Animation, vek::*},
3 BipedSmallSkeleton, SkeletonAttr,
4};
5use common::{comp::item::ToolKind, states::utils::StageSection};
6
7pub struct SpriteSummonAnimation;
8
9type SpriteSummonAnimationDependency = (
10 Option<ToolKind>,
11 Vec3<f32>,
12 Vec3<f32>,
13 Vec3<f32>,
14 f32,
15 Vec3<f32>,
16 f32,
17 Option<StageSection>,
18 f32,
19);
20
21impl Animation for SpriteSummonAnimation {
22 type Dependency<'a> = SpriteSummonAnimationDependency;
23 type Skeleton = BipedSmallSkeleton;
24
25 #[cfg(feature = "use-dyn-lib")]
26 const UPDATE_FN: &'static [u8] = b"biped_small_spritesummon\0";
27
28 #[cfg_attr(
29 feature = "be-dyn-lib",
30 unsafe(export_name = "biped_small_spritesummon")
31 )]
32
33 fn update_skeleton_inner(
34 skeleton: &Self::Skeleton,
35 (
36 active_tool_kind,
37 _velocity,
38 _orientation,
39 _last_ori,
40 global_time,
41 _avg_vel,
42 _acc_vel,
43 stage_section,
44 timer,
45 ): Self::Dependency<'_>,
46 anim_time: f32,
47 _rate: &mut f32,
48 s_a: &SkeletonAttr,
49 ) -> Self::Skeleton {
50 let mut next = (*skeleton).clone();
51
52 let anim_time = anim_time.min(1.0);
53 let (move1base, twitch, move2base, move3) = match stage_section {
54 Some(StageSection::Buildup) => (anim_time.sqrt(), (anim_time * 13.0).sin(), 0.0, 0.0),
55 Some(StageSection::Action) => (1.0, 1.0, anim_time.powi(4), 0.0),
56 Some(StageSection::Recover) => (1.0, 1.0, 1.0, anim_time),
57 _ => (0.0, 0.0, 0.0, 0.0),
58 };
59 let pullback = 1.0 - move3;
60 let twitch = twitch * pullback;
61 let subtract = global_time - timer;
62 let check = subtract - subtract.trunc();
63 let mirror = (check - 0.5).signum();
64 let move1 = move1base * pullback * mirror;
65 let move2 = move2base * pullback * mirror;
66 let move1abs = move1base * pullback;
67 let move2abs = move2base * pullback;
68 next.hand_l.position = Vec3::new(s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
69 next.hand_r.position = Vec3::new(-s_a.grip.0 * 4.0, 0.0, s_a.grip.2);
70 next.main.orientation = Quaternion::rotation_x(0.0);
71 next.hand_l.orientation = Quaternion::rotation_x(0.0);
72 next.hand_r.orientation = Quaternion::rotation_x(0.0);
73 match active_tool_kind {
74 Some(ToolKind::Natural) => {
75 next.head.orientation =
76 Quaternion::rotation_x(move1abs * 0.5) * Quaternion::rotation_y(twitch * 0.5);
77 next.chest.orientation = Quaternion::rotation_x(move1abs * 0.5 + move2abs * -1.0)
78 * Quaternion::rotation_z(move1 * 1.2 + move2 * -1.8);
79 next.hand_l.position = Vec3::new(-s_a.hand.0, s_a.hand.1, s_a.hand.2);
80 next.hand_l.orientation = Quaternion::rotation_x(1.2);
81 next.hand_r.position = Vec3::new(s_a.hand.0, s_a.hand.1, s_a.hand.2);
82 next.hand_r.orientation = Quaternion::rotation_x(1.2);
83 next.main.position = Vec3::new(0.0, 10.0 + 5.0 * move1abs, 4.0 + 4.0 * move1abs);
84 },
85 _ => {},
86 }
87 next
88 }
89}