Best way to enumerate Actors within radius?

JeremyStieglitz
Posts: 4
Joined: Mon Nov 02, 2009 11:14 pm

Best way to enumerate Actors within radius?

Post by JeremyStieglitz »

Hey guys,

I'm pretty new to Bullet (have used Tokamak, Newton, PhysX, and Havok in the past), but am loving it so far. On our new game, we're using Bullet for all of the collision detection and spatial partition checks, and so I'm wondering what's the fastest API method in Bullet for checking which collision objects are within a radius? Should I just do a sphere convex check?

Would it be faster, perhaps, to do a coarse AABB check (is there an API method for this?) and then a distance test to each object's spherical bounds?

Thanks a bunch all,
Jeremy
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Best way to enumerate Actors within radius?

Post by Erwin Coumans »

There are several ways, it all depends. It is easier to calculate the objects within an AABB, instead of a sphere radius. So first find the objects within an AABB, and then try to cull the results further.

The fastest way to get all objects within an AABB is using the btGhostObject, and preferably don't add, move or remove that ghost object if possible
(for example if you need to know all objects within a radius of a door, keep that ghost object at the door location as long as the door exists).

Culling the results further to a sphere radius efficiently can be tricky, especially if objects have complex collision shapes: you can use the collision dispatcher and do pair queries. We will create some example how to do this. But before doing so, can you approximate it using a distance check using the object center?

Thanks,
Erwin
JeremyStieglitz
Posts: 4
Joined: Mon Nov 02, 2009 11:14 pm

Re: Best way to enumerate Actors within radius?

Post by JeremyStieglitz »

Thanks a lot Erwin. I will do an experiment tomorrow to see how the process works with btGhostObject (I was indeed looking into that as an option). I'll let you know how it goes...

Keep up the great work on Bullet!!

-Jeremy
edouard
Posts: 8
Joined: Fri Sep 25, 2009 2:08 pm

Re: Best way to enumerate Actors within radius?

Post by edouard »

The fastest way to get all objects within an AABB is using the btGhostObject, and preferably don't add, move or remove that ghost object
I'm curious about the side effect of moving the GhostObject, why should we avoid trying to move it?

and if we want to move it what are our other option?

thanks
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Best way to enumerate Actors within radius?

Post by sparkprime »

I'd guess that if you move it slowly it's fine -- i.e. you can attach it to a vehicle or something like that. But warping it all over the place would not be a good idea.