Skip to content

Commit

Permalink
Remove dynamic flipping from heightfield
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Jun 14, 2020
1 parent 8af335c commit 5acab5e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ impl<N: RealField> ContactDispatcher<N> for DefaultContactDispatcher {

if a_is_heightfield || b_is_heightfield {
return Some(wrap(
flip,
HeightFieldShapeManifoldGenerator::<N>::new(b_is_heightfield),
flip ^ b_is_heightfield,
HeightFieldShapeManifoldGenerator::<N>::new(),
));
} else if a_is_capsule && b_is_capsule {
Some(wrap(flip, CapsuleCapsuleManifoldGenerator::<N>::new()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ use std::collections::{hash_map::Entry, HashMap};
/// Collision detector between an heightfield and another shape.
pub struct HeightFieldShapeManifoldGenerator<N: RealField> {
sub_detectors: HashMap<usize, (ContactAlgorithm<N>, usize), DeterministicState>,
flip: bool,
timestamp: usize,
}

impl<N: RealField> HeightFieldShapeManifoldGenerator<N> {
/// Creates a new collision detector between an heightfield and another shape.
pub fn new(flip: bool) -> HeightFieldShapeManifoldGenerator<N> {
pub fn new() -> HeightFieldShapeManifoldGenerator<N> {
HeightFieldShapeManifoldGenerator {
sub_detectors: HashMap::with_hasher(DeterministicState),
flip,
timestamp: 0,
}
}
Expand Down Expand Up @@ -47,20 +45,27 @@ impl<N: RealField> HeightFieldShapeManifoldGenerator<N> {
.entry(i)
{
Entry::Occupied(mut entry) => {
let ok = if self.flip {
entry.get_mut().0.generate_contacts(
dispatcher,
m2,
g2,
proc2,
m1,
elt1,
Some(&(proc1, part_proc1)),
prediction,
manifold,
)
} else {
entry.get_mut().0.generate_contacts(
let ok = entry.get_mut().0.generate_contacts(
dispatcher,
m1,
elt1,
Some(&(proc1, part_proc1)),
m2,
g2,
proc2,
prediction,
manifold,
);

if ok {
entry.get_mut().1 = self.timestamp;
}
}
Entry::Vacant(entry) => {
let new_detector = dispatcher.get_contact_algorithm(elt1, g2);

if let Some(mut new_detector) = new_detector {
let _ = new_detector.generate_contacts(
dispatcher,
m1,
elt1,
Expand All @@ -70,46 +75,7 @@ impl<N: RealField> HeightFieldShapeManifoldGenerator<N> {
proc2,
prediction,
manifold,
)
};

if ok {
entry.get_mut().1 = self.timestamp;
}
}
Entry::Vacant(entry) => {
let new_detector = if self.flip {
dispatcher.get_contact_algorithm(g2, elt1)
} else {
dispatcher.get_contact_algorithm(elt1, g2)
};

if let Some(mut new_detector) = new_detector {
if self.flip {
let _ = new_detector.generate_contacts(
dispatcher,
m2,
g2,
proc2,
m1,
elt1,
Some(&(proc1, part_proc1)),
prediction,
manifold,
);
} else {
let _ = new_detector.generate_contacts(
dispatcher,
m1,
elt1,
Some(&(proc1, part_proc1)),
m2,
g2,
proc2,
prediction,
manifold,
);
}
);
let _ = entry.insert((new_detector, self.timestamp));
}
}
Expand All @@ -135,16 +101,9 @@ impl<N: RealField> ContactManifoldGenerator<N> for HeightFieldShapeManifoldGener
prediction: &ContactPrediction<N>,
manifold: &mut ContactManifold<N>,
) -> bool {
if !self.flip {
if let Some(hf) = a.as_shape::<HeightField<N>>() {
self.do_update(d, ma, hf, proc1, mb, b, proc2, prediction, manifold);
return true;
}
} else {
if let Some(hf) = b.as_shape::<HeightField<N>>() {
self.do_update(d, mb, hf, proc2, ma, a, proc1, prediction, manifold);
return true;
}
if let Some(hf) = a.as_shape::<HeightField<N>>() {
self.do_update(d, ma, hf, proc1, mb, b, proc2, prediction, manifold);
return true;
}

return false;
Expand Down

0 comments on commit 5acab5e

Please sign in to comment.