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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
use crate::dynamics::{BodyPair, RigidBodyHandle};
use crate::geometry::{ColliderPair, ContactManifold};
use crate::math::{Point, Real, Vector};
use parry::query::ContactManifoldsWorkspace;
bitflags::bitflags! {
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
pub struct SolverFlags: u32 {
const COMPUTE_IMPULSES = 0b001;
const MODIFY_SOLVER_CONTACTS = 0b010;
}
}
impl Default for SolverFlags {
fn default() -> Self {
SolverFlags::COMPUTE_IMPULSES
}
}
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
pub struct ContactData {
pub impulse: Real,
#[cfg(feature = "dim2")]
pub tangent_impulse: Real,
#[cfg(feature = "dim3")]
pub tangent_impulse: [Real; 2],
}
impl ContactData {
#[cfg(feature = "dim2")]
pub(crate) fn zero_tangent_impulse() -> Real {
0.0
}
#[cfg(feature = "dim3")]
pub(crate) fn zero_tangent_impulse() -> [Real; 2] {
[0.0, 0.0]
}
}
impl Default for ContactData {
fn default() -> Self {
Self {
impulse: 0.0,
tangent_impulse: Self::zero_tangent_impulse(),
}
}
}
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Clone)]
pub struct ContactPair {
pub pair: ColliderPair,
pub manifolds: Vec<ContactManifold>,
pub has_any_active_contact: bool,
pub(crate) workspace: Option<ContactManifoldsWorkspace>,
}
impl ContactPair {
pub(crate) fn new(pair: ColliderPair) -> Self {
Self {
pair,
has_any_active_contact: false,
manifolds: Vec::new(),
workspace: None,
}
}
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
pub struct ContactManifoldData {
pub body_pair: BodyPair,
pub(crate) warmstart_multiplier: Real,
#[cfg_attr(feature = "serde-serialize", serde(skip))]
pub(crate) constraint_index: usize,
#[cfg_attr(feature = "serde-serialize", serde(skip))]
pub(crate) position_constraint_index: usize,
pub solver_flags: SolverFlags,
#[cfg_attr(feature = "serde-serialize", serde(skip))]
pub normal: Vector<Real>,
#[cfg_attr(feature = "serde-serialize", serde(skip))]
pub solver_contacts: Vec<SolverContact>,
pub relative_dominance: i16,
pub user_data: u32,
}
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
pub struct SolverContact {
pub(crate) contact_id: u8,
pub point: Point<Real>,
pub dist: Real,
pub friction: Real,
pub restitution: Real,
pub tangent_velocity: Vector<Real>,
pub data: ContactData,
}
impl SolverContact {
pub fn is_bouncy(&self) -> bool {
let is_new = self.data.impulse == 0.0;
if is_new {
self.restitution > 0.0
} else {
self.restitution >= 1.0
}
}
}
impl Default for ContactManifoldData {
fn default() -> Self {
Self::new(
BodyPair::new(RigidBodyHandle::invalid(), RigidBodyHandle::invalid()),
SolverFlags::empty(),
)
}
}
impl ContactManifoldData {
pub(crate) fn new(body_pair: BodyPair, solver_flags: SolverFlags) -> ContactManifoldData {
Self {
body_pair,
warmstart_multiplier: Self::min_warmstart_multiplier(),
constraint_index: 0,
position_constraint_index: 0,
solver_flags,
normal: Vector::zeros(),
solver_contacts: Vec::new(),
relative_dominance: 0,
user_data: 0,
}
}
#[inline]
pub fn num_active_contacts(&self) -> usize {
self.solver_contacts.len()
}
pub(crate) fn min_warmstart_multiplier() -> Real {
1.0
}
}