Easy way to set up ghost objects? (resolved mostly)

lulzfish
Posts: 43
Joined: Mon Jan 03, 2011 4:26 pm

Easy way to set up ghost objects? (resolved mostly)

Post by lulzfish »

I'm migrating a small project from ODE, and I'm not sure how to implement part of it with Bullet.
The program lets users spawn dominoes using a "builder domino" which moves around freely and can add a domino to the world as long as it is not intersecting any existing dominoes.

In ODE, I implemented this using a geom that had no body attached, and my collision callback would report any collisions with the builder domino, but not create a response.

In Bullet, I tried a few ways of implementing this with btGhostObject. The wiki page for "Collision Callbacks and Triggers" is pretty confusing. I copied the manifold-related code for btGhostObject, but it always returns 0 because the dominoes are colliding with the builder domino's ghost object, and being pushed away instead of just detected.

I then tried to use different collision flags, which stopped the dominoes from colliding with the builder, but it still would not detect collisions.

I also tried switching from btGhostObject to btPairCachingGhostObject. If anyone can explain the difference between them, that would help.

The wiki page I used didn't say how to create a ghost object. >:(
This is what I'm using currently:

Code: Select all

btPairCachingGhostObject * builderDomino;
/* some irrelevant code */
builderDomino = new btPairCachingGhostObject ();
builderDomino->setCollisionShape (dominoes.dominoCI->m_collisionShape);
builderDomino->setWorldTransform (dominoes.dominoCI->m_startWorldTransform);
world->addCollisionObject (builderDomino);
It gives the proper shape and transform, but the newly spawned dominoes are kicked out of the builder's spawn volume, which is incorrect.

Then after each frame's world->stepSimulation, I run the code from the "btGhostObject" section in http://www.bulletphysics.org/mediawiki- ... d_Triggers, and print out the numPairs, which is always 0 because it seems to either collide with the dominoes and kick them out, or not collide at all.

What am I doing wrong?
Last edited by lulzfish on Mon Jan 03, 2011 6:57 pm, edited 1 time in total.
lulzfish
Posts: 43
Joined: Mon Jan 03, 2011 4:26 pm

Re: Easy way to set up ghost objects?

Post by lulzfish »

I searched the forum a little more thoroughly and figured that issue out: (But just got another listed near the end of this post)

It was the same issue as this guy had:
http://bulletphysics.org/Bullet/phpBB3/ ... ect#p17879

I had to tell my broadphase to set up some kind of callback for the ghost object. I still don't understand it, but it seems to be working now.

Also had to play with the collision flags. Initialization is now something like:

Code: Select all

builderDomino = new btPairCachingGhostObject ();
builderDomino->setCollisionShape (dominoes.dominoCI->m_collisionShape);
builderDomino->setWorldTransform (dominoes.dominoCI->m_startWorldTransform);
builderDomino->setCollisionFlags (builderDomino->getCollisionFlags()
	| btCollisionObject::CF_NO_CONTACT_RESPONSE);
world->addCollisionObject (builderDomino, btBroadphaseProxy::DefaultFilter,
	btBroadphaseProxy::AllFilter);
broadphase->getOverlappingPairCache()->setInternalGhostPairCallback(
	new btGhostPairCallback());
It would still be nice to know what the difference is between GhostObject and PairCachingGhostObject?

Also, it seems to be using the AABB instead of doing actual collision, so some dominoes are blocking spawn although they should be clear of it. How can I fix that?
Actually, it looks like something even broader than AABB, I have a situation where all the dominoes are entirely beneath the bottom of the builder domino, but it still thinks it is being blocked.

The ghost object for the builder domino appears to extend 0.125 units above and below the actual domino.