veloren_voxygen_anim/ship/
idle.rs1use super::{
2 super::{Animation, vek::*},
3 ShipSkeleton, SkeletonAttr,
4};
5use common::comp::item::ToolKind;
6
7pub struct IdleAnimation;
8
9impl Animation for IdleAnimation {
10 type Dependency<'a> = (
11 Option<ToolKind>,
12 Option<ToolKind>,
13 f32,
14 f32,
15 Vec3<f32>,
16 Vec3<f32>,
17 );
18 type Skeleton = ShipSkeleton;
19
20 #[cfg(feature = "use-dyn-lib")]
21 const UPDATE_FN: &'static [u8] = b"ship_idle\0";
22
23 #[cfg_attr(feature = "be-dyn-lib", export_name = "ship_idle")]
24 fn update_skeleton_inner(
25 skeleton: &Self::Skeleton,
26 (_active_tool_kind, _second_tool_kind, _global_time, acc_vel, orientation, last_ori): Self::Dependency<'_>,
27 _anim_time: f32,
28 _rate: &mut f32,
29 s_a: &SkeletonAttr,
30 ) -> Self::Skeleton {
31 let mut next = (*skeleton).clone();
32 let ori: Vec2<f32> = Vec2::from(orientation);
33 let last_ori = Vec2::from(last_ori);
34 let tilt = if vek::Vec2::new(ori, last_ori)
35 .map(|o| o.magnitude_squared())
36 .map(|m| m > 0.001 && m.is_finite())
37 .reduce_and()
38 && ori.angle_between(last_ori).is_finite()
39 {
40 ori.angle_between(last_ori).min(0.2)
41 * last_ori.determine_side(Vec2::zero(), ori).signum()
42 } else {
43 0.0
44 } * 1.3;
45 next.bone0.position = Vec3::new(s_a.bone0.0, s_a.bone0.1, s_a.bone0.2);
46
47 next.bone1.position = Vec3::new(s_a.bone1.0, s_a.bone1.1, s_a.bone1.2);
48 next.bone1.orientation = Quaternion::rotation_z(s_a.bone1_ori)
49 * Quaternion::rotation_y(acc_vel * s_a.bone_rotation_rate);
50
51 next.bone2.position = Vec3::new(s_a.bone2.0, s_a.bone2.1, s_a.bone2.2);
52 next.bone2.orientation = Quaternion::rotation_z(s_a.bone2_ori)
53 * Quaternion::rotation_y(-acc_vel * s_a.bone_rotation_rate);
54
55 next.bone3.position = Vec3::new(s_a.bone3.0, s_a.bone3.1, s_a.bone3.2);
56 next.bone3.orientation = Quaternion::rotation_z(tilt * 25.0);
57 next
58 }
59}