Add solver flags for controlling whether or not some contacts should be taken into account by the constraints solver.
This commit is contained in:
@@ -9,6 +9,16 @@ use {
|
||||
simba::simd::SimdValue,
|
||||
};
|
||||
|
||||
bitflags::bitflags! {
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
/// Flags affecting the behavior of the constraints solver for a given contact manifold.
|
||||
pub struct SolverFlags: u32 {
|
||||
/// The constraint solver will take this contact manifold into
|
||||
/// account for force computation.
|
||||
const COMPUTE_FORCES = 0b01;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
/// The type local linear approximation of the neighborhood of a pair contact points on two shapes
|
||||
@@ -206,6 +216,7 @@ impl ContactPair {
|
||||
pub(crate) fn single_manifold<'a, 'b>(
|
||||
&'a mut self,
|
||||
colliders: &'b ColliderSet,
|
||||
flags: SolverFlags,
|
||||
) -> (
|
||||
&'b Collider,
|
||||
&'b Collider,
|
||||
@@ -216,7 +227,7 @@ impl ContactPair {
|
||||
let coll2 = &colliders[self.pair.collider2];
|
||||
|
||||
if self.manifolds.len() == 0 {
|
||||
let manifold = ContactManifold::from_colliders(self.pair, coll1, coll2);
|
||||
let manifold = ContactManifold::from_colliders(self.pair, coll1, coll2, flags);
|
||||
self.manifolds.push(manifold);
|
||||
}
|
||||
|
||||
@@ -288,6 +299,8 @@ pub struct ContactManifold {
|
||||
/// The relative position between the second collider and its parent at the time the
|
||||
/// contact points were generated.
|
||||
pub delta2: Isometry<f32>,
|
||||
/// Flags used to control some aspects of the constraints solver for this contact manifold.
|
||||
pub solver_flags: SolverFlags,
|
||||
}
|
||||
|
||||
impl ContactManifold {
|
||||
@@ -299,6 +312,7 @@ impl ContactManifold {
|
||||
delta2: Isometry<f32>,
|
||||
friction: f32,
|
||||
restitution: f32,
|
||||
solver_flags: SolverFlags,
|
||||
) -> ContactManifold {
|
||||
Self {
|
||||
#[cfg(feature = "dim2")]
|
||||
@@ -319,6 +333,7 @@ impl ContactManifold {
|
||||
delta2,
|
||||
constraint_index: 0,
|
||||
position_constraint_index: 0,
|
||||
solver_flags,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,11 +357,17 @@ impl ContactManifold {
|
||||
delta2: self.delta2,
|
||||
constraint_index: self.constraint_index,
|
||||
position_constraint_index: self.position_constraint_index,
|
||||
solver_flags: self.solver_flags,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_colliders(pair: ColliderPair, coll1: &Collider, coll2: &Collider) -> Self {
|
||||
Self::with_subshape_indices(pair, coll1, coll2, 0, 0)
|
||||
pub(crate) fn from_colliders(
|
||||
pair: ColliderPair,
|
||||
coll1: &Collider,
|
||||
coll2: &Collider,
|
||||
flags: SolverFlags,
|
||||
) -> Self {
|
||||
Self::with_subshape_indices(pair, coll1, coll2, 0, 0, flags)
|
||||
}
|
||||
|
||||
pub(crate) fn with_subshape_indices(
|
||||
@@ -355,6 +376,7 @@ impl ContactManifold {
|
||||
coll2: &Collider,
|
||||
subshape1: usize,
|
||||
subshape2: usize,
|
||||
solver_flags: SolverFlags,
|
||||
) -> Self {
|
||||
Self::new(
|
||||
pair,
|
||||
@@ -364,6 +386,7 @@ impl ContactManifold {
|
||||
*coll2.position_wrt_parent(),
|
||||
(coll1.friction + coll2.friction) * 0.5,
|
||||
(coll1.restitution + coll2.restitution) * 0.5,
|
||||
solver_flags,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user