Page 1 of 1
Boxes don't collide
Posted: Mon Apr 30, 2012 7:49 am
by SL RU
I write programm with bepu physics.
But it work very bad, becouse some boxes fall throw other boxes.
Re: Boxes don't collide
Posted: Mon Apr 30, 2012 7:50 am
by SL RU
Why is it?

Re: Boxes don't collide
Posted: Mon Apr 30, 2012 2:13 pm
by Norbo
It looks like the graphics do not match the actual shapes. They may be offset from the actual shape, scaled differently, or both.
The BEPUphysicsDrawer in the
main source download is useful for debug visualization. You could also just put the physics side of things into a BEPUphysicsDemos demo to see if the simulation itself is behaving well (since the demos use the BEPUphysicsDrawer).
Re: Boxes don't collide
Posted: Tue May 01, 2012 11:02 am
by SL RU
Thank you!
I have two boxes with tags: "Box1" and "Box2".
How do I know that they are in contact or not?
Sorry, if there are grammatic errors, becouse I'm from RUSSIA.
Re: Boxes don't collide
Posted: Tue May 01, 2012 4:05 pm
by Norbo
One option would be to check the entity.CollisionInformation.Pairs list on one of the boxes. If it one of the pairs involves the other box, and that pair has contacts in its Contacts list with nonnegative penetration depth, then they are touching.
Each CollidablePairHandler in the pairs list will have a BroadPhaseOverlap in it. There's an EntryA and an EntryB in that. They are BroadPhaseEntry objects; BroadPhaseEntry objects have Tags which you can set. The entity.CollisionInformation property returns an EntityCollidable object which inherits from BroadPhaseEntry, so it has a Tag itself which is separate from the Entity.Tag. If you put your data in that Tag, you can look at the tags in the BroadPhaseEntry objects in the BroadPhaseOverlap to determine if the objects are the ones you want to check.
The BroadPhaseEntry can be cast down to an EntityCollidable if it is in fact an EntityCollidable, too, which would allow you to check the EntityCollidable.Entity property.
Re: Boxes don't collide
Posted: Tue May 01, 2012 4:24 pm
by Norbo
I went ahead and made a little modification to the development version which lets you access a pair's Collidables and Entities directly if you'd like to use it:
http://bepuphysics.codeplex.com/SourceC ... evelopment
Re: Boxes don't collide
Posted: Tue May 01, 2012 5:54 pm
by SL RU
Code: Select all
Box body;
public override void Initialize ()
{
// ЗАДАЧА: добавьте здесь код инициализации
body = new Box(new Vector3(0, 10, 0), 1, 1, 1, 40);
body.Tag = "Box1";
space.Add(body);
Box box;
box = new Box(new Vector3(0, 0, 0), 1, 1, 1);
box.Tag = "Box2";
space.Add(box);
body.CollisionInformation.Events.CreatingContact += new BEPUphysics.Collidables.Events.CreatingContactEventHandler<BEPUphysics.Collidables.MobileCollidables.EntityCollidable>(Events_CreatingContact);
body.CollisionInformation.Events.PairTouched += new BEPUphysics.Collidables.Events.PairTouchedEventHandler<EntityCollidable>(Events_PairTouched);
base.Initialize();
}
void Events_PairTouched (EntityCollidable sender, Collidable other, CollidablePairHandler pair)
{
if (pair.BroadPhaseOverlap.EntryA.Tag == "Box1" || pair.BroadPhaseOverlap.EntryB.Tag == "Box2")
{
MessageBox.Show("OK!!!");
}
}
This is an example of my code.
I see that the Box body falls on the Box box, but the program does not show MessegeBox.
Help me please!

Re: Boxes don't collide
Posted: Tue May 01, 2012 5:57 pm
by Norbo
The BroadPhaseEntry.Tag is separate from the Entity.Tag. If you want to use the BroadPhaseEntry.Tag, the entity.CollisionInformation.Tag must be set.