Merge pull request #122 from dimforge/dominance
Implement dominance groups
This commit is contained in:
@@ -92,6 +92,8 @@ pub struct RigidBody {
|
|||||||
pub(crate) changes: RigidBodyChanges,
|
pub(crate) changes: RigidBodyChanges,
|
||||||
/// The status of the body, governing how it is affected by external forces.
|
/// The status of the body, governing how it is affected by external forces.
|
||||||
pub body_status: BodyStatus,
|
pub body_status: BodyStatus,
|
||||||
|
/// The dominance group this rigid-body is part of.
|
||||||
|
dominance_group: i8,
|
||||||
/// User-defined data associated to this rigid-body.
|
/// User-defined data associated to this rigid-body.
|
||||||
pub user_data: u128,
|
pub user_data: u128,
|
||||||
}
|
}
|
||||||
@@ -122,6 +124,7 @@ impl RigidBody {
|
|||||||
flags: RigidBodyFlags::empty(),
|
flags: RigidBodyFlags::empty(),
|
||||||
changes: RigidBodyChanges::all(),
|
changes: RigidBodyChanges::all(),
|
||||||
body_status: BodyStatus::Dynamic,
|
body_status: BodyStatus::Dynamic,
|
||||||
|
dominance_group: 0,
|
||||||
user_data: 0,
|
user_data: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,6 +162,19 @@ impl RigidBody {
|
|||||||
&self.mass_properties
|
&self.mass_properties
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The dominance group of this rigid-body.
|
||||||
|
///
|
||||||
|
/// This method always returns `i8::MAX + 1` for non-dynamic
|
||||||
|
/// rigid-bodies.
|
||||||
|
#[inline]
|
||||||
|
pub fn effective_dominance_group(&self) -> i16 {
|
||||||
|
if self.is_dynamic() {
|
||||||
|
self.dominance_group as i16
|
||||||
|
} else {
|
||||||
|
i8::MAX as i16 + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the rigid-body's mass properties.
|
/// Sets the rigid-body's mass properties.
|
||||||
///
|
///
|
||||||
/// If `wake_up` is `true` then the rigid-body will be woken up if it was
|
/// If `wake_up` is `true` then the rigid-body will be woken up if it was
|
||||||
@@ -648,6 +664,7 @@ pub struct RigidBodyBuilder {
|
|||||||
mass_properties: MassProperties,
|
mass_properties: MassProperties,
|
||||||
can_sleep: bool,
|
can_sleep: bool,
|
||||||
sleeping: bool,
|
sleeping: bool,
|
||||||
|
dominance_group: i8,
|
||||||
user_data: u128,
|
user_data: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -666,6 +683,7 @@ impl RigidBodyBuilder {
|
|||||||
mass_properties: MassProperties::zero(),
|
mass_properties: MassProperties::zero(),
|
||||||
can_sleep: true,
|
can_sleep: true,
|
||||||
sleeping: false,
|
sleeping: false,
|
||||||
|
dominance_group: 0,
|
||||||
user_data: 0,
|
user_data: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -691,6 +709,12 @@ impl RigidBodyBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the dominance group of this rigid-body.
|
||||||
|
pub fn dominance_group(mut self, group: i8) -> Self {
|
||||||
|
self.dominance_group = group;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the initial translation of the rigid-body to be created.
|
/// Sets the initial translation of the rigid-body to be created.
|
||||||
#[cfg(feature = "dim2")]
|
#[cfg(feature = "dim2")]
|
||||||
pub fn translation(mut self, x: Real, y: Real) -> Self {
|
pub fn translation(mut self, x: Real, y: Real) -> Self {
|
||||||
@@ -880,6 +904,7 @@ impl RigidBodyBuilder {
|
|||||||
rb.angular_damping = self.angular_damping;
|
rb.angular_damping = self.angular_damping;
|
||||||
rb.gravity_scale = self.gravity_scale;
|
rb.gravity_scale = self.gravity_scale;
|
||||||
rb.flags = self.flags;
|
rb.flags = self.flags;
|
||||||
|
rb.dominance_group = self.dominance_group;
|
||||||
|
|
||||||
if self.can_sleep && self.sleeping {
|
if self.can_sleep && self.sleeping {
|
||||||
rb.sleep();
|
rb.sleep();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use crate::dynamics::{JointGraphEdge, JointIndex, RigidBodySet};
|
|||||||
use crate::geometry::{ContactManifold, ContactManifoldIndex};
|
use crate::geometry::{ContactManifold, ContactManifoldIndex};
|
||||||
|
|
||||||
pub(crate) fn categorize_contacts(
|
pub(crate) fn categorize_contacts(
|
||||||
bodies: &RigidBodySet,
|
_bodies: &RigidBodySet, // Unused but useful to simplify the parallel code.
|
||||||
manifolds: &[&mut ContactManifold],
|
manifolds: &[&mut ContactManifold],
|
||||||
manifold_indices: &[ContactManifoldIndex],
|
manifold_indices: &[ContactManifoldIndex],
|
||||||
out_ground: &mut Vec<ContactManifoldIndex>,
|
out_ground: &mut Vec<ContactManifoldIndex>,
|
||||||
@@ -10,10 +10,8 @@ pub(crate) fn categorize_contacts(
|
|||||||
) {
|
) {
|
||||||
for manifold_i in manifold_indices {
|
for manifold_i in manifold_indices {
|
||||||
let manifold = &manifolds[*manifold_i];
|
let manifold = &manifolds[*manifold_i];
|
||||||
let rb1 = &bodies[manifold.data.body_pair.body1];
|
|
||||||
let rb2 = &bodies[manifold.data.body_pair.body2];
|
|
||||||
|
|
||||||
if !rb1.is_dynamic() || !rb2.is_dynamic() {
|
if manifold.data.relative_dominance != 0 {
|
||||||
out_ground.push(*manifold_i)
|
out_ground.push(*manifold_i)
|
||||||
} else {
|
} else {
|
||||||
out_not_ground.push(*manifold_i)
|
out_not_ground.push(*manifold_i)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ impl PositionGroundConstraint {
|
|||||||
) {
|
) {
|
||||||
let mut rb1 = &bodies[manifold.data.body_pair.body1];
|
let mut rb1 = &bodies[manifold.data.body_pair.body1];
|
||||||
let mut rb2 = &bodies[manifold.data.body_pair.body2];
|
let mut rb2 = &bodies[manifold.data.body_pair.body2];
|
||||||
let flip = !rb2.is_dynamic();
|
let flip = manifold.data.relative_dominance < 0;
|
||||||
|
|
||||||
let n1 = if flip {
|
let n1 = if flip {
|
||||||
std::mem::swap(&mut rb1, &mut rb2);
|
std::mem::swap(&mut rb1, &mut rb2);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ impl WPositionGroundConstraint {
|
|||||||
let mut flipped = [false; SIMD_WIDTH];
|
let mut flipped = [false; SIMD_WIDTH];
|
||||||
|
|
||||||
for ii in 0..SIMD_WIDTH {
|
for ii in 0..SIMD_WIDTH {
|
||||||
if !rbs2[ii].is_dynamic() {
|
if manifolds[ii].data.relative_dominance < 0 {
|
||||||
flipped[ii] = true;
|
flipped[ii] = true;
|
||||||
std::mem::swap(&mut rbs1[ii], &mut rbs2[ii]);
|
std::mem::swap(&mut rbs1[ii], &mut rbs2[ii]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,6 +144,8 @@ impl VelocityConstraint {
|
|||||||
out_constraints: &mut Vec<AnyVelocityConstraint>,
|
out_constraints: &mut Vec<AnyVelocityConstraint>,
|
||||||
push: bool,
|
push: bool,
|
||||||
) {
|
) {
|
||||||
|
assert_eq!(manifold.data.relative_dominance, 0);
|
||||||
|
|
||||||
let inv_dt = params.inv_dt();
|
let inv_dt = params.inv_dt();
|
||||||
let rb1 = &bodies[manifold.data.body_pair.body1];
|
let rb1 = &bodies[manifold.data.body_pair.body1];
|
||||||
let rb2 = &bodies[manifold.data.body_pair.body2];
|
let rb2 = &bodies[manifold.data.body_pair.body2];
|
||||||
|
|||||||
@@ -67,6 +67,10 @@ impl WVelocityConstraint {
|
|||||||
out_constraints: &mut Vec<AnyVelocityConstraint>,
|
out_constraints: &mut Vec<AnyVelocityConstraint>,
|
||||||
push: bool,
|
push: bool,
|
||||||
) {
|
) {
|
||||||
|
for ii in 0..SIMD_WIDTH {
|
||||||
|
assert_eq!(manifolds[ii].data.relative_dominance, 0);
|
||||||
|
}
|
||||||
|
|
||||||
let inv_dt = SimdReal::splat(params.inv_dt());
|
let inv_dt = SimdReal::splat(params.inv_dt());
|
||||||
let rbs1 = array![|ii| &bodies[manifolds[ii].data.body_pair.body1]; SIMD_WIDTH];
|
let rbs1 = array![|ii| &bodies[manifolds[ii].data.body_pair.body1]; SIMD_WIDTH];
|
||||||
let rbs2 = array![|ii| &bodies[manifolds[ii].data.body_pair.body2]; SIMD_WIDTH];
|
let rbs2 = array![|ii| &bodies[manifolds[ii].data.body_pair.body2]; SIMD_WIDTH];
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ impl VelocityGroundConstraint {
|
|||||||
let inv_dt = params.inv_dt();
|
let inv_dt = params.inv_dt();
|
||||||
let mut rb1 = &bodies[manifold.data.body_pair.body1];
|
let mut rb1 = &bodies[manifold.data.body_pair.body1];
|
||||||
let mut rb2 = &bodies[manifold.data.body_pair.body2];
|
let mut rb2 = &bodies[manifold.data.body_pair.body2];
|
||||||
let flipped = !rb2.is_dynamic();
|
let flipped = manifold.data.relative_dominance < 0;
|
||||||
|
|
||||||
let (force_dir1, flipped_multiplier) = if flipped {
|
let (force_dir1, flipped_multiplier) = if flipped {
|
||||||
std::mem::swap(&mut rb1, &mut rb2);
|
std::mem::swap(&mut rb1, &mut rb2);
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ impl WVelocityGroundConstraint {
|
|||||||
let mut flipped = [1.0; SIMD_WIDTH];
|
let mut flipped = [1.0; SIMD_WIDTH];
|
||||||
|
|
||||||
for ii in 0..SIMD_WIDTH {
|
for ii in 0..SIMD_WIDTH {
|
||||||
if !rbs2[ii].is_dynamic() {
|
if manifolds[ii].data.relative_dominance < 0 {
|
||||||
std::mem::swap(&mut rbs1[ii], &mut rbs2[ii]);
|
std::mem::swap(&mut rbs1[ii], &mut rbs2[ii]);
|
||||||
flipped[ii] = -1.0;
|
flipped[ii] = -1.0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ pub struct ContactManifoldData {
|
|||||||
/// The contacts that will be seen by the constraints solver for computing forces.
|
/// The contacts that will be seen by the constraints solver for computing forces.
|
||||||
#[cfg_attr(feature = "serde-serialize", serde(skip))]
|
#[cfg_attr(feature = "serde-serialize", serde(skip))]
|
||||||
pub solver_contacts: Vec<SolverContact>,
|
pub solver_contacts: Vec<SolverContact>,
|
||||||
|
/// The relative dominance of the bodies involved in this contact manifold.
|
||||||
|
pub relative_dominance: i16,
|
||||||
/// A user-defined piece of data.
|
/// A user-defined piece of data.
|
||||||
pub user_data: u32,
|
pub user_data: u32,
|
||||||
}
|
}
|
||||||
@@ -122,7 +124,7 @@ pub struct ContactManifoldData {
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
pub struct SolverContact {
|
pub struct SolverContact {
|
||||||
/// The index of the manifold contact used to generate this solver contact.
|
/// The index of the manifold contact used to generate this solver contact.
|
||||||
pub contact_id: u8,
|
pub(crate) contact_id: u8,
|
||||||
/// The world-space contact point.
|
/// The world-space contact point.
|
||||||
pub point: Point<Real>,
|
pub point: Point<Real>,
|
||||||
/// The distance between the two original contacts points along the contact normal.
|
/// The distance between the two original contacts points along the contact normal.
|
||||||
@@ -177,6 +179,7 @@ impl ContactManifoldData {
|
|||||||
solver_flags,
|
solver_flags,
|
||||||
normal: Vector::zeros(),
|
normal: Vector::zeros(),
|
||||||
solver_contacts: Vec::new(),
|
solver_contacts: Vec::new(),
|
||||||
|
relative_dominance: 0,
|
||||||
user_data: 0,
|
user_data: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -555,6 +555,8 @@ impl NarrowPhase {
|
|||||||
manifold.data.solver_contacts.clear();
|
manifold.data.solver_contacts.clear();
|
||||||
manifold.data.body_pair = BodyPair::new(co1.parent(), co2.parent());
|
manifold.data.body_pair = BodyPair::new(co1.parent(), co2.parent());
|
||||||
manifold.data.solver_flags = solver_flags;
|
manifold.data.solver_flags = solver_flags;
|
||||||
|
manifold.data.relative_dominance =
|
||||||
|
rb1.effective_dominance_group() - rb2.effective_dominance_group();
|
||||||
manifold.data.normal = world_pos1 * manifold.local_n1;
|
manifold.data.normal = world_pos1 * manifold.local_n1;
|
||||||
|
|
||||||
// Generate solver contacts.
|
// Generate solver contacts.
|
||||||
|
|||||||
Reference in New Issue
Block a user