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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use na::RealField;
use ncollide::query::{ContactManifold, TrackedContact};
use ncollide::shape::FeatureId;
use crate::object::{BodyHandle, BodyPartHandle, Collider, ColliderAnchor, ColliderHandle};
#[derive(Clone)]
pub struct ColliderContactManifold<'a, N: RealField, Handle: BodyHandle, CollHandle: ColliderHandle>
{
pub handle1: CollHandle,
pub collider1: &'a Collider<N, Handle>,
pub handle2: CollHandle,
pub collider2: &'a Collider<N, Handle>,
pub manifold: &'a ContactManifold<N>,
}
impl<'a, N: RealField, Handle: BodyHandle, CollHandle: ColliderHandle>
ColliderContactManifold<'a, N, Handle, CollHandle>
{
pub fn new(
handle1: CollHandle,
collider1: &'a Collider<N, Handle>,
handle2: CollHandle,
collider2: &'a Collider<N, Handle>,
manifold: &'a ContactManifold<N>,
) -> Self {
ColliderContactManifold {
handle1,
collider1,
handle2,
collider2,
manifold,
}
}
pub fn len(&self) -> usize {
self.manifold.len()
}
pub fn contacts(&self) -> impl Iterator<Item = &TrackedContact<N>> {
self.manifold.contacts()
}
pub fn deepest_contact(&self) -> Option<&TrackedContact<N>> {
self.manifold.deepest_contact()
}
pub fn body1(&self) -> Handle {
self.collider1.body()
}
pub fn body2(&self) -> Handle {
self.collider2.body()
}
pub fn body_part1(&self, feature1: FeatureId) -> BodyPartHandle<Handle> {
match self.collider1.anchor() {
ColliderAnchor::OnBodyPart { body_part, .. } => *body_part,
ColliderAnchor::OnDeformableBody {
body, body_parts, ..
} => {
let subshape_id = self.collider1.shape().subshape_containing_feature(feature1);
if let Some(body_parts) = body_parts {
BodyPartHandle(*body, body_parts[subshape_id])
} else {
BodyPartHandle(*body, subshape_id)
}
}
}
}
pub fn body_part2(&self, feature2: FeatureId) -> BodyPartHandle<Handle> {
match self.collider2.anchor() {
ColliderAnchor::OnBodyPart { body_part, .. } => *body_part,
ColliderAnchor::OnDeformableBody {
body, body_parts, ..
} => {
let subshape_id = self.collider2.shape().subshape_containing_feature(feature2);
if let Some(body_parts) = body_parts {
BodyPartHandle(*body, body_parts[subshape_id])
} else {
BodyPartHandle(*body, subshape_id)
}
}
}
}
pub fn anchor1(&self) -> &ColliderAnchor<N, Handle> {
self.collider1.anchor()
}
pub fn anchor2(&self) -> &ColliderAnchor<N, Handle> {
self.collider2.anchor()
}
}