What are allowed penetration and default margin?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
00se7en
Posts: 9
Joined: Tue Dec 18, 2007 1:19 am

What are allowed penetration and default margin?

Post by 00se7en »

Can you explain, generally, these two settings and how they are used?

I am playing around with a scene involving heightmap terrain, static triangle geometry (from a model), and some simulated primitives. I can notice obvious spacing between the objects when they are resting on each other. Should I adjust the default margin and/or penetration values or will this cause wierd behavior? I have noticed a few odd things when playing with these settings, but don't know exactly how its related. Is it better to adjust these settings globally or on individual objects? Are these two settings related to each other and should adjustments reflect that?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: What are allowed penetration and default margin?

Post by Norbo »

The defaultAllowedPenetration and defaultMargin settings of the simulationSettings are the values of margin and allowedPenetration that entities are given when they are added to the space if no other margin has been defined for them. The defaults are basically just a convenience method to assign margins to unassigned entities, so you can mix and match case-by-case assignments with different defaults without problems.

Imagine an entity's margin as fattening up a shape and smoothing out the corners. A box, in terms of the GJKMPR collision detection system, has rounded edges as in the attached picture, marginExample.jpg (exaggerated for example's sake). In reality, the box-box special case collision detection system considers the box with sharp edges, but this shows the general case. The margin you specify is the amount of this fattening to use, and you can think of the margin as the radius of a sphere that is being swept across the object's surface.

The reason margins exist is to aid collision detection. Having the margin allows faster and more accurate general case collision detection algorithms to be used. You can also use them to tweak your object's shape by giving it excessive fatness, though you should keep it above zero for the sake of robustness (technically it will work with a zero margin, just not as well or as fast).

The allowedPenetration of an object is a separate concept related to position correction. When two entities overlap by some amount, the amount of overlap is checked against the allowedPenetration. If they are too deeply intersecting, an extra force is applied to return the objects to a better touching state. If they are within the allowedPenetration no force is applied. This value should be kept above zero to prevent jitter caused by the engine constantly applying tiny position correction forces. Keeping it about where the default is will keep objects from sinking into each other too much.


To address visible gaps, you can either adjust margins (to an extent as mentioned above), modify the core shape's dimensions, or modify the graphical representation. Using allowedPenetration to adjust gaps isn't very effective since objects can still be stopped completely even when barely intersecting.
Attachments
marginExample.jpg
marginExample.jpg (59.17 KiB) Viewed 4178 times
Post Reply