♫ Broadphase: testing a single aabb ♫

entropyExplorer
Posts: 4
Joined: Wed Dec 28, 2011 12:11 pm

♫ Broadphase: testing a single aabb ♫

Post by entropyExplorer »

Hello,

So my problem is a simple one: I would like to give my broadphase interface the following information:

Vector3 max, min; //These describe an "imaginary aabb"

and have it return a list of all colliding objects.
===============================
===============================
My problem is that all the functions I found want there to be a collisionObject in the system that represents the object. I'm combining 2 physics engines together, so I just want to be able to give it the aabb info.
===============================
===============================

Code: Select all

for each(flsmObject *obj in game.flsmObjects) {
		Vector3f max = obj->rigidBody->boundingBox.max;
		Vector3f min = obj->rigidBody->boundingBox.min;

		btBroadphaseProxy* proxy = overlappingPairCache->createProxy(convert(min), convert(max), 0, this, 1, COL_PHYSICAL, dispatcher, 0);
		btBroadphaseAabbCallback callback = btSingleContactCallback callback();
		overlappingPairCache->aabbTest(convert(min), convert(max), callback);
		
	}
^^This is what I've been attempting... in my confusion. Any ideas will be much appreciated.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: ♫ Broadphase: testing a single aabb ♫

Post by Flix »

First of all I don't know if I've understood what you're trying to do correctly, and further more I've never tried the aabbTest method myself.

Anyway what I'd do to perform an aabbTest on all the world (created with a btDbvtBroadphase) is something like:

Code: Select all

btDbvtBroadphase*	dbvtBroadphase = dynamic_cast <btDbvtBroadphase*> (m_dynamicsWorld->getBroadphase());
dbvtBroadphase->aabbTest(min,max,callback);
I've found another post with some guidelines on how to build the callback here:http://bulletphysics.org/Bullet/phpBB3/ ... t=aabbTest (last post).

Hope it works and it's what you were looking for :? .

[Edit:] Maybe it works with other broadphases too (not only with dbvtBroadphase):

Code: Select all

m_dynamicsWorld->getBroadphase()->aabbTest(...);
However from your post I suspect you already know how to use aabbTest... are you trying to create a btRigidBody with automatic btGhostObject capability ? If so, the title of your post is a bit misleading...
entropyExplorer
Posts: 4
Joined: Wed Dec 28, 2011 12:11 pm

Re: ♫ Broadphase: testing a single aabb ♫

Post by entropyExplorer »

Yea... I should have been more eloquent in describing my problem.

Basically it is this: Bullet usually does collision with existing objects. It will take their aabb, almost automatically, and find out if they are in collision. I want to test to see if there is collision between objects from a physics engine running parallel to it. So, at first, I'm going to take all the aabb's from the OTHER physics engine and test to see what objects they are in collision with in BULLET. I do not want to create a rigidbody in Bullet that represents the objects in the OTHER physics engine, so I'm only testing to see if their(objects from the foreign engine) aabb's are in collision with bullet objects. I'm only trying to make the two engines interact with each other when it is necessary. So that means they will only talk to each other when objects are in collision with each other AND when those objects are in different engines. This way I only need to make them communicate for collision detection and collision resolution(updating velocities if I understand properly).

Thank you for the link, I'll let you know how it works out for me.
monkeyman
Posts: 22
Joined: Sat Nov 26, 2011 5:41 pm

Re: ♫ Broadphase: testing a single aabb ♫

Post by monkeyman »

Just as a side note: if you try to combine your physics engines by looping over all the AABB's of the objects of one of them into the broadphase of the other, you are probably not utilizing the broadphase in a very efficient way. Depending on your usage scenario, this might be better than creating actual collision-objects in Bullet (or vice versa) or it could be worse..
entropyExplorer
Posts: 4
Joined: Wed Dec 28, 2011 12:11 pm

Re: ♫ Broadphase: testing a single aabb ♫

Post by entropyExplorer »

monkeyman, thank you for pointing that out. It is possible that this is entirely the least efficient way to do broadphase. But due to broadphase being naturally pretty rapid I think I can do this the dirty way with only negligible slow down. Aabb's great simplicity is what im banking on.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: ♫ Broadphase: testing a single aabb ♫

Post by Flix »

entropyExplorer wrote:So, at first, I'm going to take all the aabb's from the OTHER physics engine and test to see what objects they are in collision with in BULLET. I do not want to create a rigidbody in Bullet that represents the objects in the OTHER physics engine, so I'm only testing to see if their(objects from the foreign engine) aabb's are in collision with bullet objects.
Well, aabbTest(...) does not require a btRigidBody/btCollisionObject to be present, so it should work in your case. The problem is that aabbTest(...) is a broadphase test, and so it will report false positives (there is a contactTest(...) method for the narrowphase, but it needs a btCollisionShape inside a btCollisionObject to work).

On a closer look, about the implementation, I think that the btBroadphaseAabbCallback can be simplified a lot in this way:

Code: Select all

struct btMyBroadphaseAabbCallback : public btBroadphaseAabbCallback {
  btAlignedObjectArray < btCollisionObject* >& m_collisionObjectArray;
  short int m_collisionFilterGroup, m_collisionFilterMask;// Optional
  btMyBroadphaseAabbCallback(btAlignedObjectArray < btCollisionObject* >& collisionObjectArray, short int collisionGroup=btBroadphaseProxy::DefaultFilter, short int collisionMask=btBroadphaseProxy::AllFilter) :
    m_collisionObjectArray(collisionObjectArray), m_collisionFilterGroup(collisionGroup), m_collisionFilterMask(collisionMask) 
    { 
    m_collisionObjectArray.resize(0);
    }
// Optional:
  SIMD_FORCE_INLINE bool needsCollision(const btBroadphaseProxy* proxy) const {
    bool collides = (proxy->m_collisionFilterGroup & m_collisionFilterMask) != 0;
    collides = collides && (m_collisionFilterGroup & proxy->m_collisionFilterMask);
    return collides;
  }

  virtual bool process (const btBroadphaseProxy *proxy) {
  	// Basically this is the only method to implement in btBroadphaseAabbCallback.
  	// If we don't need any filtering/excluding objects, we can just write: 
  	// m_collisionObjectArray.push_back((btCollisionObject *)proxy->m_clientObject);return true;
  	// and we're done
  	
    if (needsCollision(proxy)) m_collisionObjectArray.push_back((btCollisionObject *)proxy->m_clientObject);
    return true;
  }
};

// Usage:
btAlignedObjectArray < btCollisionObject* > collisionObjectArray;
btMyBroadphaseAabbCallback callback(collisionObjectArray);
m_dynamicsWorld->getBroadphase()->aabbTest(min,max,callback);
// Now collisionObjectArray should be filled.
As you can see, the filtering is completely optional (and in the link I posted a collision object to exclude was present too). The only method to override is the 'process(...)' method.

PS. It might seem strange, but I've never used the above code myself, so I hope it works... :?