dimforge / dimforge/ncollide

Penetration queries work only sporadically with compound shapes

Open
#209 5 comments 0 reactions 0 assignees View on GitHub
bug P-low
Dominant language
Rust
Stars
926
Forks
104
PR merge metrics
No merged PRs in 30d

Description

I have found that penetration queries seem to only sometimes work for compound shapes against compound shapes. I'm not sure what the circumstance is when they *do* work, but I have at least one test that consistently fails where it should seemingly return a penetration value:

In this test the north wall of the first room overlaps the south wall of the second. The walls are 0.2 thick.
```rust
#[test]
fn test_compound_penetration() {
let mut r1 = Room::new_with_centered_door(Point::new(0.0, 0.0), 10.0, 10.0, Direction::North);
r1.is_compound = true;
let starter_loc = r1.location();
let mut compound_rm = Compound::new(vec![(origin(), r1.shape())]);

let r2 = Room::new_with_centered_door(Point::new(0.0, 10.0), 10.0, 10.15, Direction::North);
let r2_s = r2.shape();
let r2_shape: &CollisionRect = r2_s.as_shape().unwrap();
let penetration = query::contact(&origin(), &compound_rm, &r2.location(), r2_shape,
WALL_THICKNESS);
assert!(penetration.is_some())
}
```

But the test fails.

For how the "Room" is constructed:
```rust
impl Collidable for Room {
fn location(&self) -> Isometry2 { Isometry2::new(self.center().coords, na::zero()) }
fn shape(&self) -> Shape2D {
let shapes = self.walls.iter().map(|&(w, _)| {
let cr: CollisionRect = w.into();
// Wall locations need to be represented relative to the center of the room
let loc = Isometry2::new(w.center().coords - self.center().coords, na::zero());
(loc, ShapeHandle::new(cr))
});
let whole_shape = Compound::new(shapes.collect());
ShapeHandle::new(whole_shape)
}
fn collision_group(&self) -> CollisionGroups { CollGroups::wall_cg() }
fn coltype(&self) -> CollidableType {
if self.is_compound { CollidableType::CompoundRoomWall } else { CollidableType::RoomWall }
}
}
```

Here is a picture of the rooms where walls are a not-fully-opaque green, so you can see the overlap as a slightly brighter green:
![screenshot from 2018-06-12 21-36-11](https://user-images.githubusercontent.com/517683/41330507-bb4c894c-6e88-11e8-9c20-5cf06fe2e280.png)

Am I doing something wrong here? Or is this a bug for compound shapes?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.