1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::Bone;
use nalgebra::DualQuaternion;
use std::collections::BTreeMap;
pub fn blend_towards_bones(
start: &BTreeMap<u8, Bone>,
end: &BTreeMap<u8, Bone>,
interp_param: f32,
) -> BTreeMap<u8, Bone> {
start
.iter()
.zip(end.iter())
.map(
|((prev_joint_idx, prev_action_bone), (cur_joint_idx, cur_action_bone))| {
if prev_joint_idx != cur_joint_idx {
panic!("We do not currently support the current action having different joints than the previous action");
}
let new_bone = interpolate_bone(*prev_action_bone, *cur_action_bone, interp_param);
(*cur_joint_idx, new_bone)
},
)
.collect()
}
pub fn interpolate_bone(start_bone: Bone, end_bone: Bone, amount: f32) -> Bone {
match start_bone {
Bone::DualQuat(start) => match end_bone {
Bone::DualQuat(mut end) => Bone::DualQuat(interpolate_dual_quats(start, end, amount)),
_ => panic!(
r#"You may only interpolate bones of the same type. Please convert
your end bone into a dual quaternion before interpolating"#
),
},
Bone::Matrix(_matrix) => unimplemented!(),
}
}
pub fn interpolate_dual_quats(
start: DualQuaternion<f32>,
mut end: DualQuaternion<f32>,
amount: f32,
) -> DualQuaternion<f32> {
if start.real.dot(&end.real) < 0.0 {
end = end * -1.;
}
start + ((end - start) * amount)
}