BEPU for Physics Modeling

Discuss any questions about BEPUphysics or problems encountered.
fezzick22
Posts: 13
Joined: Mon Jul 25, 2011 3:54 am

BEPU for Physics Modeling

Post by fezzick22 »

Hi,

I am new to using BEPU and was wondering if I could get some help with the following problem. I have a static sphere, and a bunch of dynamic spheres trapped inside of a box with some initial velocity v and no gravity (similar to an ideal gas). I want the dynamic spheres to stick to the static sphere whenever they collide with it. The only way I can see to go about doing this is to use one of the collision events on the dynamic sphere (currently looking at InitialCollisionDetected) and adding a new DistanceLimit constraint to the solver whenever a collision with this sphere occurs. What type of constraint would you recommend I implement in this case, and is there a way to implement custom constraints?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: BEPU for Physics Modeling

Post by Norbo »

A DistanceLimit would probably work okay. If it allows a little extra distance, that would prevent it from fighting the contact constraints.

Another option would be a WeldJoint, which is internally composed of a BallSocketJoint and NoRotationJoint. With that, you could disable the collision between the connected objects using collision rules (http://bepuphysics.codeplex.com/wikipag ... umentation).
is there a way to implement custom constraints?
Yes, though doing so requires pretty in-depth knowledge. An example constraint, implemented externally to the main library, can be found in the development version's HorizontalMotionConstraint for the new character (http://bepuphysics.codeplex.com/SourceC ... evelopment). The existing constraint types (http://bepuphysics.codeplex.com/wikipag ... umentation) cover pretty much all the degrees of freedom and various common behaviors. Combinations of them can be used to create even more.
fezzick22
Posts: 13
Joined: Mon Jul 25, 2011 3:54 am

Re: BEPU for Physics Modeling

Post by fezzick22 »

So on further analysis I have some more questions about how this engine works. In my particular application I am trying to roughly simulate diffusion using a course particle system. I currently set up a simulation which includes 10000 particles which are given an initial linear velocity and spawned randomly in a contained box. The box is made up of six immobile boxes which have been set to static. I have set all of the coefficients of linear dampening, angular dampening and .material.Bounciness parameters to 0.0 to try and ignore the dampening of the system over time in order to best simulate this phenomenon. However, not only do the particles appear to be slowing down still, but they also all get stuck in the corners of the box over time. I was wondering if you could comment on how I can change the coefficient of restitution in the model at one spot, or how I could go about combating this issue.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: BEPU for Physics Modeling

Post by Norbo »

However, not only do the particles appear to be slowing down still
I would assume that this is partly related to the deactivation system. Once an object goes below a threshold, it will try to deactivate. Part of the deactivation process is "stabilization," which saps energy from slow moving objects. Once they are slow enough for long enough, they deactivate completely. More information can be found in this thread: http://www.bepu-games.com/forums/viewto ... f=4&t=1292
but they also all get stuck in the corners of the box over time.
This would be expected with zero bounciness. They hit a wall and lose all velocity along the normal of that wall, then continue to slide with the remaining tangential velocity until they hit another obstacle, and so on until no velocity remains. Setting the bounciness to a higher value (closer to 1) will keep the objects moving and out of the corners for the most part.

Note that a bounciness value of 1 may add energy to the system over time, depending on the configuration. Some damping may be required to keep the system from entering a positive feedback loop.
I was wondering if you could comment on how I can change the coefficient of restitution in the model at one spot
You could use separate boxes or do something with contact events and overwriting material properties, but it seems like there would be some better way to accomplish the goal. It sounds like you don't want a fully bouncy environment, but also don't want zero bounciness; what is the specific desired end result behavior?
fezzick22
Posts: 13
Joined: Mon Jul 25, 2011 3:54 am

Re: BEPU for Physics Modeling

Post by fezzick22 »

Thanks for answering those questions. I understand you would want to deactivate objects which are not moving and sap energy from them over time to stabilize the physics interactions. Is this in addition to the linear and angular momentum dampening parameters? I already set both of those to zero to try and weaken there effects.

Here is the application I am trying to use this engine for. I want to simulate particles diffusing in a box. In this box there can be other groups of static structures, usually represented by compound structures made with spheres. I want to measure how far the particles diffuse through these compound objects.
fezzick22
Posts: 13
Joined: Mon Jul 25, 2011 3:54 am

Re: BEPU for Physics Modeling

Post by fezzick22 »

And I just figured out the problem. One of the coefficients was not being set correctly. That seemed to fix the problem.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: BEPU for Physics Modeling

Post by Norbo »

Is this in addition to the linear and angular momentum dampening parameters?
Yes. It only occurs if enabled and if the objects have very low velocities, though.
fezzick22
Posts: 13
Joined: Mon Jul 25, 2011 3:54 am

Re: BEPU for Physics Modeling

Post by fezzick22 »

Does your engines support large amount of particles possible via a particle system approach?

Also, is their a way to specify a collision event for a specific for a specific group of objects with another. Say I have one group of spheres, and a group of boxes, and a group of cones. I only want a collision event to run an update if a cone and a sphere collide, but I still want collisions to occur between all of these objects. I tried utilizing collision rules but there does not seem to be an option created for this particular instance.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: BEPU for Physics Modeling

Post by Norbo »

Does your engines support large amount of particles possible via a particle system approach?
Not directly. However, if you need collision-enabled particles, it would be simple enough to add in a proxy to the broad phase that detects collision pairs. A custom narrow phase handler for those particles could do something like find an approximate distance to the other object in the pair. Those distances could then be used to apply forces to both objects, probably external to the solver. The particle itself wouldn't be a full Entity, but rather a stripped down Particle type that only has mass and perhaps a few special configuration factors. The simplified collision detection, response, and update processes would allow for much greater numbers of particles than if it were just a bunch of Sphere entities.

When designing the engine's architecture for extensibility, such a particle system was one of the use cases I had in mind. I may actually add in such a particle system, possibly to the demos as a sample of external extension, if time allows in v0.17.0/v1.0.0.
Also, is their a way to specify a collision event for a specific for a specific group of objects with another. Say I have one group of spheres, and a group of boxes, and a group of cones. I only want a collision event to run an update if a cone and a sphere collide, but I still want collisions to occur between all of these objects.
The best way would be to do the filter logic within the event handler itself.
fezzick22
Posts: 13
Joined: Mon Jul 25, 2011 3:54 am

Re: BEPU for Physics Modeling

Post by fezzick22 »

Ok so I have been using the PairTouched event to handle all of my collision detection event updates and it works well. The problem with this approach is that I can only access the entity who called the collision, not the entity it is colliding with. I need to be able to access both properties to determine whether to throw the event or not. I was planning on writing my own custom contact event handler to deal with this situation. From what I can glean from the documentation this can be accomplished using the IContactEventTrigger interface. Was this what you were suggesting?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: BEPU for Physics Modeling

Post by Norbo »

Was this what you were suggesting?
No; while technically doable, that would be relatively difficult.

The second parameter to the events is either a BroadPhaseEntry or Collidable, depending on the event. BroadPhaseEntry is the superclass of objects which live in the collision detection pipeline. Collidable is a child of BroadPhaseEntry that encompasses objects which create contacts with other objects. EntityCollidable is a child of Collidable which encompasses Entity-owned objects which create contacts with other objects.

So, in order to get the other Entity in a collision, you can attempt to cast the other BroadPhaseEntry/Collidable parameter to an EntityCollidable. If it is an EntityCollidable, then you can access the Entity.

A common use case for this is to get to the Entity's Tag property and the user data stored within that Tag. If this is what you need, then you may want to just use the BroadPhaseEntry's Tag instead. Note that the BroadPhaseEntry's Tag is separate data from the Entity's Tag. In other words, you can independently set Entity.Tag and Entity.CollisionInformation.Tag, because the CollisionInformation property returns the entity's EntityCollidable, a BroadPhaseEntry.
fezzick22
Posts: 13
Joined: Mon Jul 25, 2011 3:54 am

Re: BEPU for Physics Modeling

Post by fezzick22 »

I figured this out yesterday after perusing the documentation. Thanks for outlining this though, it makes much mores sense to me now. Still learning all the intricacies of this engine.
fezzick22
Posts: 13
Joined: Mon Jul 25, 2011 3:54 am

Re: BEPU for Physics Modeling

Post by fezzick22 »

Ok, so I have another question. Say I have a sphere and a cone, and I want them to stick together. For example we have a bunch of spheres and cones floating around in space. When they hit, they stick together, and their orientation is locked with respect to one another. However, I still want them to be able to interact with other spheres and cones in the space. Is the best way to do this to utilize a constraint, or create a compound body?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: BEPU for Physics Modeling

Post by Norbo »

Either a WeldJoint and forming a CompoundBody would work. It may be easier to just create WeldJoint between objects, though the run time performance of the compounds should be a bit faster. If a little bit of wiggle is wanted/desired, then WeldJoint is needed. If absolute rigidity is required, then a compound should be used.

The difficulty with compounds is that a CompoundShape is currently immutable, so it will take some entity/collidable recreation to get working.
fezzick22
Posts: 13
Joined: Mon Jul 25, 2011 3:54 am

Re: BEPU for Physics Modeling

Post by fezzick22 »

Imuutable? Sorry I am not sure I follow. Does this mean that compound bodies do not actually collide with each other? I am running into a problem where compound bodies appear to be moving inside of one another. I am not quite sure what is going on with that.
Post Reply