Hi there,
I want to add some kind of invisible grid/sector support to our game. Its sole purpose is to tell the coder whether or not an object is present inside a certain gridbox/sector.
E.g., I want to add a 10x10x10 grid at a certain location and want to be able to determine whether gridposition (0, 7, 2) contains a rigidbody, and if it does, preferable which rigidbody.
An obvious way would be to add 1000 static objects formed in a cube shape, with no collision response, and then to check the collison using contact callbacks. However this method doesn't easily scale up if I want to use for example a 50x50x50 grid (== 125k static objects!!!)
Is there any fast way to determine whether or not an object is present in a certain sector? The sector/grid size as well as the location must be user configurable.
Any help would be greatly appreciated.
Cheers,
Martijn
Grid/sector check support
-
- Posts: 133
- Joined: Wed Jul 27, 2005 1:05 pm
- Location: Berkeley, CA
Re: Grid/sector check support
Please see the new btGhostObject in the latest Bullet 2.73 RC.
Thanks,
John
Thanks,
John
-
- Posts: 56
- Joined: Sat Mar 08, 2008 12:37 am
Re: Grid/sector check support
If you need just to quickly check one (or a few) cells of the grid you could easily iterate over all bodies and do a simple check, like this:
Things are worse if you need information about objects in all cells of your grid.
The current version of btCudaBroadphase is based on 3D grid, so it already has information which bodies are inside particular cell.
But for now you need to have CUDA-capable device to use it.
I plan to implement a CPU version of this broadphase soon, maybe it will be helpful for solving tasks of such kind
Thanks,
Roman
Code: Select all
{
for(int i = pDynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
{
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
btVector3 pos = obj->getWorldTransform().getOrigin();
if(your_check_here(pos))
{
return obj;
}
}
return NULL;
}
The current version of btCudaBroadphase is based on 3D grid, so it already has information which bodies are inside particular cell.
But for now you need to have CUDA-capable device to use it.
I plan to implement a CPU version of this broadphase soon, maybe it will be helpful for solving tasks of such kind
Thanks,
Roman