Detect when pushed out

Adrick
Posts: 5
Joined: Fri Jul 22, 2011 7:53 am

Detect when pushed out

Post by Adrick »

I've got a ball locked to x/y axis (linear factor) and it rolls around on top of btboxshapes. I have gravity applied and what I'm finding is contactAdded is called during each simulation step and adding an existing contact point (which I understand because it is not yet destroyed) it then processed that contact point a couple of times pushing my ball out of my boxes so it rests on top. When I launch my ball into the air the contact point is thus destroyed.

What I want to know is what is the best way to detect if my ball is already pushed out and not colliding with anything? I am asuming the aabbs used are bigger then my actual ball and box otherwise why aren't the contacts been destroyed when visually the ball sits resting on top of the box ok and I know it is not intersecting.

Anyone shed any light on to whats happening here? cheers!
Adrick
Posts: 5
Joined: Fri Jul 22, 2011 7:53 am

Re: Detect when pushed out

Post by Adrick »

I did some further searching of the bullet forums and found gContactBreakingThreshold and have set it to 0.0f. This seems to cause the contact to be destroyed after it has infact pushed the ball out of the other bodies which is the effect im after, however I have been reading this is a bad idea for games, can someone explain how so?

Also is this the only way to achieve this without having to perform a manual collision detection after each physics step? because that is also costly I here. addSingleResult or something I beleive the option is to take?

Edit: Further testing again I have found that contactAdded is called for every contact there is with my body including ones that weren't destroyed in the previous simulation (i can tell because user pointer is still set and lifetime increases) and I assumed contactProcessed would always return negative distances (intersections) and not cases where the contact is already pushed out of the other body with distance >= 0.0f. So I could drop back to normal contact breaking threshold and code my own work around to monitor what contacts are added and then how they are processed to see if any remain intersected. This is a little painful compared to adjusting the global and having contactDestroyed tell me all contacts have been removed. Still any help at all would be appreciated.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Detect when pushed out

Post by dphil »

however I have been reading this is a bad idea for games, can someone explain how so?
I'm guessing this is because if two objects are close together (in each other's aabb's, for the sake of this argument), then there is a good chance they will collide, or collide again. So it may be premature to destroy a contact the second the objects aren't exactly touching, because they may well end up being bumped together again, or rotating a bit such that they are touching again, etc. In such cases, you could have many extra unnecessary creations and deletions of contacts. So if the contact is only destroyed once the object's aabb's are no longer touching, it's a safer bet that a new contact won't be needed in the immediate future (in simulation time, anyway). Granted I am not too familiar with gContactBreakingThreshold, so I am making some assumptions about it. I think my above statements are along the right lines though.

Contacts exist as long as two object's bounding boxes overlap. If a contact point's distance is <= 0, the objects (not just their aabb's) are physically overlapping at that point. If the distance is > 0, only their aabb's are overlapping at that point (I say "at that point" because some object types have multiple contact points for their contact manifold. I'm still not entirely sure what they mean).
Adrick
Posts: 5
Joined: Fri Jul 22, 2011 7:53 am

Re: Detect when pushed out

Post by Adrick »

dphil thanks for your reply, I figured out this as well and figured I could use a work around with the distance value however I was hoping for another way.

What I've also found is what I beleive is a bug in the collision response, even with setting all values back to default I am able to embed my ball into a tri mesh and leave it there with no user input (no force except I assume gravity) is been applied. It stays there, sometimes it will pop out other times it wont and stayed intersected.

Anyone have this occur for them???