Delete objects on collision, stepping till deactivation

benadler
Posts: 8
Joined: Tue Mar 09, 2010 12:52 pm

Delete objects on collision, stepping till deactivation

Post by benadler »

Hello!

First of all I want to thank Mr. Coumans for writing the Bullet Manual (well, and bullet:)! I don't find the API-Docs to be very helpful in understanding Bullet's architecture, so I had a really hard time to get the basics right - until I found the manual.

Now my questions:

I want to simulate something similar to simulated annealing, but my surface contains holes. So when a sample-sphere falls through my surface's holes, it will somewhen collide with a btStaticPlaneShape created below that surface. As that sample-sphere is of no more interest to my simulation, I want to delete it on collision with that plane.
Reading the manual makes me think it would be most efficient to do the collision/deletion in the broadphase step (as an AABB-check of sphere/plane seems sufficient to detect a collision). But how exactly can I implement this? Do I need to implement my own broadphase? Is it even allowed to removeCollisionObject() in the broadphase, or do later parts of the pipeline rely on all collisionObjects still being present?

Secondly, I'm only interested in the simulation's result, not the process itself. Thus, after testing the code/debugdrawing the iterations, I'd like to stepSimulation() until all sample-spheres have come to a halt. How can I detect this case? Will I have to iterate through all objects after each stepSimulation to see whether they are sleeping/deactivated?

thanks for your help!
ben
Etek
Posts: 15
Joined: Mon Oct 04, 2010 5:55 pm

Re: Delete objects on collision, stepping till deactivation

Post by Etek »

Hello,

Where is the manual you are talking about?

Thanks
benadler
Posts: 8
Joined: Tue Mar 09, 2010 12:52 pm

Re: Delete objects on collision, stepping till deactivation

Post by benadler »

Hi Etek,

first result for google://"bullet manual" - or http://bullet.googlecode.com/svn/trunk/ ... Manual.pdf

cheers,
ben
skeen
Posts: 24
Joined: Wed Dec 08, 2010 11:59 am

Re: Delete objects on collision, stepping till deactivation

Post by skeen »

Hint1: The User Manual is distributed with the SDK too.
Hint2: If you want to figure out how to use Bullet, then the Demoes are a good place to start, watch a simple demo, and then lookup the code to figure out what it does. :)
skeen
Posts: 24
Joined: Wed Dec 08, 2010 11:59 am

Re: Delete objects on collision, stepping till deactivation

Post by skeen »

EDIT: Just appeared to me that this post was quite old! >.<
EDIT: Just appeared to me I was looking at that guys join date! >.<
benadler wrote: I want to simulate something similar to simulated annealing, but my surface contains holes. So when a sample-sphere falls through my surface's holes, it will somewhen collide with a btStaticPlaneShape created below that surface. As that sample-sphere is of no more interest to my simulation, I want to delete it on collision with that plane.
Reading the manual makes me think it would be most efficient to do the collision/deletion in the broadphase step (as an AABB-check of sphere/plane seems sufficient to detect a collision). But how exactly can I implement this? Do I need to implement my own broadphase? Is it even allowed to removeCollisionObject() in the broadphase, or do later parts of the pipeline rely on all collisionObjects still being present?
I want to be fair, my knowledge to Bullet isn't a lot, actually I just got started myself this week. - However I'm doing something along what you'll be wanting to do in one of my test cases. I'm having a slope, where I'm spawning some spheres on, like to roll down, and over the edge. Once this happens they'll drop about 50units, and then get deleted.

What I've done, is to hold a vector with reference to my bodies, and on each iteration, I simply check if their y value (height) is below 'somepoint', and if thats the case, then I'm removing the rigidbody from the engine, as well as from my vector of references.

I'm almost sure, that you're able to build a more efficient way, but for my testcase this seemed fine.
Secondly, I'm only interested in the simulation's result, not the process itself. Thus, after testing the code/debugdrawing the iterations, I'd like to stepSimulation() until all sample-spheres have come to a halt. How can I detect this case? Will I have to iterate through all objects after each stepSimulation to see whether they are sleeping/deactivated?

thanks for your help!
ben
As for my way of the first part, this would simply be to check the size of your reference vector, once that hits zero, theres no more spheres active.
benadler
Posts: 8
Joined: Tue Mar 09, 2010 12:52 pm

Re: Delete objects on collision, stepping till deactivation

Post by benadler »

skeen wrote: What I've done, is to hold a vector with reference to my bodies, and on each iteration, I simply check if their y value (height) is below 'somepoint', and if thats the case, then I'm removing the rigidbody from the engine, as well as from my vector of references.

I'm almost sure, that you're able to build a more efficient way, but for my testcase this seemed fine.
So, if I understand correctly, you have implemented your own broadphase. I'm using a ghost-object for that now, but in principle, both should work.
skeen wrote: As for my way of the first part, this would simply be to check the size of your reference vector, once that hits zero, theres no more spheres active.
Unfortunately in my case, not all spheres will fall, some will just stop rolling on my plane/mesh. And once all of them have come to a halt (or have been deleted), I'd like to stop stepping the world. I just need to know how I can find out *when* that happens.
skeen
Posts: 24
Joined: Wed Dec 08, 2010 11:59 am

Re: Delete objects on collision, stepping till deactivation

Post by skeen »

benadler wrote:
skeen wrote: What I've done, is to hold a vector with reference to my bodies, and on each iteration, I simply check if their y value (height) is below 'somepoint', and if thats the case, then I'm removing the rigidbody from the engine, as well as from my vector of references.

I'm almost sure, that you're able to build a more efficient way, but for my testcase this seemed fine.
So, if I understand correctly, you have implemented your own broadphase. I'm using a ghost-object for that now, but in principle, both should work.
Yes thats kinda what I've done.
benadler wrote:
skeen wrote: As for my way of the first part, this would simply be to check the size of your reference vector, once that hits zero, theres no more spheres active.
Unfortunately in my case, not all spheres will fall, some will just stop rolling on my plane/mesh. And once all of them have come to a halt (or have been deleted), I'd like to stop stepping the world. I just need to know how I can find out *when* that happens.
As your not interrested in the simulation itself, but the result, maybe the performence wouldn't be that critical and you could simply iterate though your list, checking whether objects are moving? - once you can loop your entire vector of objects, and noone is moving, thats when 'it' happens. - where you set off your event or whatever.

To check whether an object is moving, I guess you could just check if the forces affecting it equals Vector<3,float>(0,0,0), or you could register the last iterations position, and check it against the current one (if not changed, body is still).
benadler
Posts: 8
Joined: Tue Mar 09, 2010 12:52 pm

Re: Delete objects on collision, stepping till deactivation

Post by benadler »

skeen wrote: As your not interrested in the simulation itself, but the result, maybe the performence wouldn't be that critical and you could simply iterate though your list, checking whether objects are moving? - once you can loop your entire vector of objects, and noone is moving, thats when 'it' happens. - where you set off your event or whatever.

To check whether an object is moving, I guess you could just check if the forces affecting it equals Vector<3,float>(0,0,0), or you could register the last iterations position, and check it against the current one (if not changed, body is still).
The problem is that I DO need the results quickly (and repeatedly) and I suspect bullet knows full well when a stepSimulation() hasn't caused any movements in the physics world. I'd hate to iterate all objects MotionStates and compare them - in every step.