A Few Mechanical Questions

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Wabafet
Posts: 3
Joined: Wed Feb 18, 2015 12:29 am

A Few Mechanical Questions

Post by Wabafet »

Hello,

I am porting a game from a different physics engine and have run into some things I can't figure out a translation for.

What is the best way to do one-off collision detection against a Space? For example a shape that represents an area of effect to find all other Entities in the volume to apply some effect to. I see how to get a list of broad phase overlaps with a bounding box or sphere but nothing more precise.

How can I manually test for collisions between objects? I see in the GJK Toolbox a static method for two convex shapes but what about with meshes? Is there something for generic collidables?

How would I go about viewing and altering contacts between objects and the force/impulse they apply on each other before their contacts are solved? I want to apply impact damage to objects which could destroy one object and alter/invalidate the contact data.

Thank you for your time.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: A Few Mechanical Questions

Post by Norbo »

What is the best way to do one-off collision detection against a Space? For example a shape that represents an area of effect to find all other Entities in the volume to apply some effect to. I see how to get a list of broad phase overlaps with a bounding box or sphere but nothing more precise.

How can I manually test for collisions between objects? I see in the GJK Toolbox a static method for two convex shapes but what about with meshes? Is there something for generic collidables?
In the general case, NarrowPhaseHelper.GetPairHandler could be used to create a pair handler. After calling UpdateCollision, check the Contacts property. The NarrowPhaseHelper.Intersecting function uses that to perform one-off boolean tests between collidables, for example. This involves some boilerplate, though- check the source of the Intersecting function for a look at how to acquire and release the pair properly.

The pair handlers are stateful and designed for repeated use, hence some of the awkwardness. If you expect these queries to be repeated every frame, it may be slightly faster to just have a collision proxy in the space itself collecting pairs and contacts for analysis.
How would I go about viewing and altering contacts between objects and the force/impulse they apply on each other before their contacts are solved? I want to apply impact damage to objects which could destroy one object and alter/invalidate the contact data.
A callback could be attached to the Space.Solver.Starting event. This would execute before the solver runs, but after all the contact information has been generated. Check the collidable.Pairs list and each pair's Contacts collection. The contacts collection contains references to the actual Contact object which can be modified to change the result of the collision. If you want to stop a pair from being solved, you can change the pair's CollisionRule to NoSolver or more restrictive.

It is not possible to check the impulses that the contacts will apply during the next run of the solver, since that is what the solver computes. The contacts collection does expose information about the previous frame's impulses, though.

The immediate collision events (those with present tense names, like CreatingContact) execute from within pair handler collision detection, so they can be used for this purpose too. However, they run from a multithreaded context and care must be taken to avoid corrupting state.

If you need to add/remove objects to the space, defer these until after the end of a time step if possible; doing it in the middle can cause problems.
Post Reply