veloren_voxygen_anim/biped_large/
charge.rs1use super::{
2 super::{Animation, vek::*},
3 BipedLargeSkeleton, SkeletonAttr,
4};
5use common::comp::item::ToolKind;
6use core::f32::consts::PI;
7
8pub struct ChargeAnimation;
9
10impl Animation for ChargeAnimation {
11 type Dependency<'a> = (
12 Option<ToolKind>,
13 Option<ToolKind>,
14 f32,
15 Vec3<f32>,
16 Vec3<f32>,
17 f32,
18 );
19 type Skeleton = BipedLargeSkeleton;
20
21 #[cfg(feature = "use-dyn-lib")]
22 const UPDATE_FN: &'static [u8] = b"biped_large_charge\0";
23
24 #[cfg_attr(feature = "be-dyn-lib", export_name = "biped_large_charge")]
25 fn update_skeleton_inner(
26 skeleton: &Self::Skeleton,
27 (active_tool_kind, _second_tool_kind, velocity, orientation, last_ori, _global_time): Self::Dependency<'_>,
28 anim_time: f32,
29 _rate: &mut f32,
30 s_a: &SkeletonAttr,
31 ) -> Self::Skeleton {
32 let mut next = (*skeleton).clone();
33
34 let lab: f32 = 1.0;
35
36 let foot = ((5.0 / (0.2 + 4.8 * ((anim_time * lab * 8.0).sin()).powi(2))).sqrt())
37 * ((anim_time * lab * 8.0).sin());
38 let foote = ((5.0 / (0.5 + 4.5 * ((anim_time * lab * 8.0 + PI / 2.0).sin()).powi(2)))
39 .sqrt())
40 * ((anim_time * lab * 8.0).sin());
41 let stress = ((5.0 / (0.5 + 4.5 * ((anim_time * lab * 20.0).cos()).powi(2))).sqrt())
42 * ((anim_time * lab * 20.0).cos());
43 let quick = ((5.0 / (3.5 + 1.5 * ((anim_time * lab * 8.0).sin()).powi(2))).sqrt())
44 * ((anim_time * lab * 8.0).sin());
45 let stop = (anim_time.powf(0.3)).min(1.2);
46 let stopa = (anim_time.powf(0.9)).min(5.0);
47
48 let ori: Vec2<f32> = Vec2::from(orientation);
49 let last_ori = Vec2::from(last_ori);
50 let tilt = if vek::Vec2::new(ori, last_ori)
51 .map(|o| o.magnitude_squared())
52 .map(|m| m > 0.001 && m.is_finite())
53 .reduce_and()
54 && ori.angle_between(last_ori).is_finite()
55 {
56 ori.angle_between(last_ori).min(0.2)
57 * last_ori.determine_side(Vec2::zero(), ori).signum()
58 } else {
59 0.0
60 } * 1.3;
61
62 next.head.position = Vec3::new(stop * -2.0, -1.5 + stop * 2.5 + s_a.head.0, s_a.head.1);
63 next.head.orientation =
64 Quaternion::rotation_z(stop * -1.0 + tilt * -2.0) * Quaternion::rotation_y(stop * -0.3);
65 next.head.scale = Vec3::one();
66
67 next.upper_torso.position = Vec3::new(0.0, s_a.upper_torso.0, s_a.upper_torso.1);
68 next.upper_torso.orientation =
69 Quaternion::rotation_z(stop * 1.2 + stress * stop * 0.02 + tilt * -2.0);
70
71 next.lower_torso.position = Vec3::new(0.0, s_a.lower_torso.0, s_a.lower_torso.1);
72 next.lower_torso.orientation = Quaternion::rotation_z(stop * -0.7 + tilt * 4.0);
73
74 match active_tool_kind {
75 Some(ToolKind::Staff) | Some(ToolKind::Sceptre) => {
76 next.hand_l.position = Vec3::new(s_a.sthl.0, s_a.sthl.1, s_a.sthl.2);
77 next.hand_l.orientation = Quaternion::rotation_x(s_a.sthl.3);
78
79 next.hand_r.position = Vec3::new(s_a.sthr.0, s_a.sthr.1, s_a.sthr.2);
80 next.hand_r.orientation =
81 Quaternion::rotation_x(s_a.sthr.3) * Quaternion::rotation_y(s_a.sthr.4);
82
83 next.main.position = Vec3::new(0.0, 0.0, 0.0);
84 next.main.orientation = Quaternion::rotation_y(0.0);
85
86 next.control.position = Vec3::new(
87 s_a.stc.0 + quick * 3.5 * (1.0 / (stopa + 0.1)),
88 s_a.stc.1,
89 s_a.stc.2 - stop * 3.0,
90 );
91 next.control.orientation = Quaternion::rotation_x(s_a.stc.3 + stop * -0.2)
92 * Quaternion::rotation_y(s_a.stc.4)
93 * Quaternion::rotation_z(s_a.stc.5 + stop * 0.2);
94 },
95 Some(ToolKind::Bow) => {
96 next.main.position = Vec3::new(0.0, 0.0, 0.0);
97 next.main.orientation = Quaternion::rotation_x(0.0);
98 next.hand_l.position = Vec3::new(s_a.bhl.0, s_a.bhl.1, s_a.bhl.2);
99 next.hand_l.orientation = Quaternion::rotation_x(s_a.bhl.3);
100 next.hand_r.position = Vec3::new(s_a.bhr.0, s_a.bhr.1, s_a.bhr.2);
101 next.hand_r.orientation = Quaternion::rotation_x(s_a.bhr.3);
102
103 next.hold.position = Vec3::new(0.0, -1.0, -15.2);
104 next.hold.orientation = Quaternion::rotation_x(-PI / 2.0);
105 next.hold.scale = Vec3::one() * 1.0;
106
107 next.control.position = Vec3::new(
108 3.0 + s_a.bc.0 + stop * 13.0,
109 -5.0 + s_a.bc.1 + stop * 4.0,
110 6.0 + s_a.bc.2,
111 );
112 next.control.orientation = Quaternion::rotation_x(0.2 + s_a.bc.3)
113 * Quaternion::rotation_y(-0.8 + s_a.bc.4 + stop * -0.4)
114 * Quaternion::rotation_z(s_a.bc.5 + stop * -0.6);
115 },
116 _ => {},
117 }
118
119 if velocity > 0.2 {
120 next.foot_l.position = Vec3::new(
121 -s_a.foot.0 - foot * 1.5,
122 s_a.foot.1 + foote * 2.0,
123 s_a.foot.2,
124 );
125 next.foot_l.orientation = Quaternion::rotation_x(foote * -0.1)
126 * Quaternion::rotation_z(0.4)
127 * Quaternion::rotation_y(0.15);
128
129 next.foot_r.position = Vec3::new(
130 s_a.foot.0 + foot * 1.5,
131 s_a.foot.1 + foote * -1.5,
132 s_a.foot.2,
133 );
134 next.foot_r.orientation = Quaternion::rotation_z(0.4);
135 } else {
136 next.foot_l.position = Vec3::new(
137 -s_a.foot.0,
138 -2.5 + stop * -1.3,
139 s_a.foot.2 + tilt * -4.0 * foot,
140 );
141 next.foot_l.orientation =
142 Quaternion::rotation_x(stop * -0.2 - 0.2 + stop * stress * 0.02)
143 * Quaternion::rotation_z(stop * 0.1)
144 * Quaternion::rotation_y(stop * 0.08);
145
146 next.foot_r.position =
147 Vec3::new(s_a.foot.0, 3.5 + stop * 1.5, s_a.foot.2 + tilt * 4.0 * foot);
148 next.foot_r.orientation =
149 Quaternion::rotation_x(stop * 0.1) * Quaternion::rotation_z(stop * 0.1);
150 }
151
152 next
153 }
154}