Collision sensitivity. Ignoring collisions below a threshold

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Collision sensitivity. Ignoring collisions below a threshold

Post by Spankenstein »

I'm detecting a collision for a particular object using

Code: Select all

        protected override void Events_InitialCollisionDetected(EntityCollidable info, BroadPhaseEntry entry, INarrowPhasePair pair)
        {
...
I would like to ignore collisions below a certain threshold (based on sensitivity). What would be the best way to determine the impact strength of the collision?

Average contact depth
Average contact velocity

...or adopt an entirely different approach?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision sensitivity. Ignoring collisions below a thres

Post by Norbo »

What would be the best way to determine the impact strength of the collision?
In isolation, the best way would be to look at a contact's normal force. It can be found by enumerating over a pair's contact collection. Of course, that requires that the solver run first, which would change the velocity of objects. I'll assume that won't work for what you're trying to do.

For sparse simulations, using velocity would be a good approximation. The velocity of a contact combined with the distribution of mass in the pair determines the required contact impulse. However, this approximation would fail if there's a complex interaction, e.g. a stack of objects with low velocity, but due to gravity, the involved forces are very high.

Using penetration depth runs into problems when ignored objects suddenly become deep enough to trigger collision response, despite still having a low velocity. This may be desired, but I suspect it would look a little weird.

Off the top of my head, the velocity-based approximation will probably be the best route short of calculating the forces independently of the simulation.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Collision sensitivity. Ignoring collisions below a thres

Post by Spankenstein »

In isolation, the best way would be to look at a contact's normal force. It can be found by enumerating over a pair's contact collection.
Thanks Norbo, I'll give this a go first before going down the velocity route:

Code: Select all

            float averageForce = 0f;

            int numContacts = collidablePair.Contacts.Count;

            for (int i = 0; i < numContacts; ++i)
            {
                averageForce += collidablePair.Contacts[i].NormalForce;
            }

            averageForce /= numContacts;
Do you know of a typical range of values for the NormalForce, or is it [0, float.MaxValue]?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision sensitivity. Ignoring collisions below a thres

Post by Norbo »

Do you know of a typical range of values for the NormalForce, or is it [0, float.MaxValue]?
The technical min and max are indeed all nonnegative numbers. The actual number depends on the velocities and inertias involved in a collision. A couple of slow boxes each with mass 1 will have pretty low impulses.

However, note that those forces are not available until after they have been applied to entities. That means your objects will noticeably respond to a collision for a frame before you have a chance to analyze it for sensitivity.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Collision sensitivity. Ignoring collisions below a thres

Post by Spankenstein »

That means your objects will noticeably respond to a collision for a frame before you have a chance to analyze it for sensitivity.
I can live with that for the time being.
The actual number depends on the velocities and inertias involved in a collision.
So I should scale the minimum based on the mass of each object involved. Is it just a case of having a minimum threshold and multiplying it by the mass of the object, or is there more involved?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision sensitivity. Ignoring collisions below a thres

Post by Norbo »

So I should scale the minimum based on the mass of each object involved. Is it just a case of having a minimum threshold and multiplying it by the mass of the object, or is there more involved?
There is more involved, but that will probably be a decent approximation. It will be more correct if objects tend to have similar shapes (i.e. similar inertia tensors). However, by choosing a variable sensitivity based on mass, the impulse is being partially scaled back into a velocity comparison. It will likely have similar results.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Collision sensitivity. Ignoring collisions below a thres

Post by Spankenstein »

There is more involved, but that will probably be a decent approximation.
How could I normalize the NormalForce (accumulatedImpulse) based on the mass of the object? In other words I would like to obtain a value in the range of [0, 1] for the average NormalForce no matter what the mass of the object is.

I don't mind ignoring the inertia tensors if it saves on calculation, what would you recommend?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision sensitivity. Ignoring collisions below a thres

Post by Norbo »

The maximum value that corresponds to '1' on that interval would be unknown, so scaling into that range without clamping would be impossible without some extra arbitrary choices. It should end up being equivalent to the non-interval based approaches too, unless more arbitrary rules are added. Given that it explicitly tries to remove mass from the equation, for most interactions, it would be roughly equivalent to a velocity check.

The only way to know which route is best is to figure out the exact requirements for the simulation, and pick the option that fits- each of the approaches so far is similar with slight behavior differences. I suspect any of the approximations will be "pretty close," and hopefully "close enough."
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Collision sensitivity. Ignoring collisions below a thres

Post by Spankenstein »

The only way to know which route is best is to figure out the exact requirements for the simulation, and pick the option that fits- each of the approaches so far is similar with slight behavior differences.
If I base it on velocity or normal force then how would one deal with the following scenario:

- Each time a cube hits a collidable object in the enviroment it flashes.
- Events_InitialCollisionDetected is called each time the cube collides.
- I don't want the flashing to be constantly retriggering so I must set a limit to what constitutes a new collision.

The velocity isn't going to help me filter out the collisions in this case as it will be similar from one frame to the next and Events_InitialCollisionDetected will fire almost every frame in certain scenarios.

How can I determine a new collision in this case?
Last edited by Spankenstein on Wed Jun 22, 2011 7:26 pm, edited 1 time in total.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision sensitivity. Ignoring collisions below a thres

Post by Norbo »

Events_InitialCollisionDetected will fire far almost every frame in certain scenarios.
InitialCollisionDetected should only fire the first time a collision is found (i.e. the contact count goes from 0 to greater than 0). If things are jittering, there may be other issues present, like scale problems. If the behavior is normal and it's just flashing more than you'd like, I'd say the easiest approach is to use a time-based filter. Keep track of the last time a flash occurred. Don't allow a second flash for that pair until some arbitrary time limit has passed.

If it's colliding with multiple objects and therefore flashing for each individual pair, then time-filtering based on the flasher entity's last contact, rather than individual pairs' last contact times, would do the trick.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Collision sensitivity. Ignoring collisions below a thres

Post by Spankenstein »

I'll give that a go then and report back if there are any issues. Thank you :)
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Collision sensitivity. Ignoring collisions below a thres

Post by Spankenstein »

I'm trying to determine the sensitivity by the maximum speed of the two colliding objects:

Code: Select all

EntityCollidable e = other as EntityCollidable;

            float speed = e == null ? 
                entity.LinearVelocity.LengthSquared() :
                MathTools.Max(entity.LinearVelocity.LengthSquared(), e.Entity.LinearVelocity.LengthSquared());
Now I scale the maximum speed for this collision by the collision sensitivity scale:

Code: Select all

speed = MathTools.Scale((float)Math.Sqrt(speed), 0.1f, 5f * entity.Mass, 100f, 1f);
speed = (speed, MinSpeed, MaxSpeed, MaxSensitivity, MinSensitivity)

The I filter out the collisions using:

Code: Select all

            if (speed > collisionSensitivity)
            {
                return;
            }
Unfortunately this means that if I set the collision sensitivity to 60 then nearly all collisions will be ignored. I don't really want this to happen until I reach 10 or below.

Changing the values for MinSpeed and MaxSpeed doesn't really help very much either, so maybe I'm the wrong track with this?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision sensitivity. Ignoring collisions below a thres

Post by Norbo »

Sorry, I'm not understanding something. I can't quite visualize the usage so I'm not sure what would be considered correct in this context. Going by the previous descriptions, the time based filtering option should work.
Post Reply