Boxes don't collide

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
SL RU
Posts: 6
Joined: Sat Apr 28, 2012 10:07 am

Boxes don't collide

Post by SL RU »

I write programm with bepu physics.
But it work very bad, becouse some boxes fall throw other boxes.
Attachments
1.png
1.png (10.49 KiB) Viewed 5597 times
SL RU
Posts: 6
Joined: Sat Apr 28, 2012 10:07 am

Re: Boxes don't collide

Post by SL RU »

Why is it? :?:
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Boxes don't collide

Post 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).
SL RU
Posts: 6
Joined: Sat Apr 28, 2012 10:07 am

Re: Boxes don't collide

Post 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.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Boxes don't collide

Post 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.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Boxes don't collide

Post 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
SL RU
Posts: 6
Joined: Sat Apr 28, 2012 10:07 am

Re: Boxes don't collide

Post 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! :?: :?: :?:
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Boxes don't collide

Post 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.
Post Reply