Ghost Object collision callback with related CollisionBody

Post Reply
kulebril
Posts: 10
Joined: Wed Jan 16, 2013 1:36 pm

Ghost Object collision callback with related CollisionBody

Post by kulebril »

Hi:

Im implementing a ghost object so I could get contact added and contact removed callbacks to notify my engine.

Y used a btGhostPairCallback and implemented the addOverlappingPair and removeOverlappingPair


and now I get the collision pair additions and removal, BUT they appear to use the AABB of the ghost and not the Capsule i gave to the GhostObject:

this is my Initialization :

Code: Select all

                                btDynamicsWorld			       *phyWorld;
				btCollisionWorld					*collisionWorld;
				BtOgre::DebugDrawer			*dbgdraw;
				btAxisSweep3					*mBroadphase;
				btDefaultCollisionConfiguration		*mCollisionConfig;
				btCollisionDispatcher				*mDispatcher;
				btSequentialImpulseConstraintSolver *mSolver;


  mBroadphase = new btAxisSweep3(btVector3(-10000,-10000,-10000), btVector3(10000,10000,10000), 1024);

BtGhostPairCallback * GhostCallback=new BtGhostPairCallback(); //uses B capital, because is my Implementation of it (class BtGhostPairCallback : public btGhostPairCallback)

	 mCollisionConfig = new btDefaultCollisionConfiguration();
	 mDispatcher = new btCollisionDispatcher(mCollisionConfig);
	 mSolver = new btSequentialImpulseConstraintSolver();

				 
	
	 collisionWorld = new btCollisionWorld(
								mDispatcher,
								mBroadphase,
								mCollisionConfig);

	 phyWorld = new btDiscreteDynamicsWorld(
mDispatcher,
mBroadphase, 
mSolver, 
mCollisionConfig);

	phyWorld->setGravity(btVector3(0,(float)-9.80,0));
  	phyWorld->getPairCache()->setInternalGhostPairCallback(GhostCallback);
				
and now the creation of the Ghost

Code: Select all

if (shape=="ghost")
		{
			BtGhost * Ghost=new BtGhost(obj); //again BtGhost is mine and contains a btGhostObject

				Ghost->m_ghostObject = new BtGhostObject();
				Ghost->m_ghostObject->setUserPointer(Ghost);

	btTransform startTransform;
				startTransform=btTransform::getIdentity();
				startTransform.setOrigin	(BtOgre::Convert::toBullet(obj->Node->getPosition()));
				startTransform.setRotation	(BtOgre::Convert::toBullet(obj->Node->getOrientation()));
				
				Ghost->m_ghostObject->setWorldTransform(startTransform);				
		
				btScalar characterHeight=obj->Entity->getBoundingBox().getSize().y;
				btScalar characterWidth =obj->Entity->getBoundingBox().getSize().x;

				btConvexShape* capsule = new btCapsuleShape
( characterWidth/2, characterHeight/2);

				Ghost->m_ghostObject->setCollisionShape (capsule);
				Ghost->m_ghostObject->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT);


				btScalar stepHeight = btScalar(0.1);

				Ghost->m_character = new BtGhostController (
						Ghost->m_ghostObject,
						capsule,
						stepHeight);
				Ghost->m_character->setGravity(9.8);
									
					Ghost->Obj=static_cast<OOBJECT*>(pobj);
					Ghost->ShapeName=shape;
					Ghost->Shape=capsule;
					Ghost->Body=Ghost->m_ghostObject;
					Ghost->Body->setUserPointer((void*)Ghost);

				this->phyWorld->addCollisionObject(
					Ghost->m_ghostObject,
					btBroadphaseProxy::CharacterFilter, 
					btBroadphaseProxy::StaticFilter | 
					btBroadphaseProxy::DefaultFilter);

				this->phyWorld->addAction(Ghost->m_character);

				Ghost->m_character->setJumpSpeed(20.0);

			

			this->Bodies.push_back(Ghost);
			std::string name=pobj->GetName();
			this->mBodies[name]=Ghost;
			this->dBodies[Ghost]=pobj;
			this->UpdateList.push_back(Ghost);
	
		return Ghost;
		}

So, that's the code... what im missing? why i get contact with the ghost but not the capsule?

thanks!
efaj
Posts: 8
Joined: Sun Dec 09, 2012 12:30 pm

Re: Ghost Object collision callback with related CollisionBo

Post by efaj »

I'm having this same problem apparently.
If I create the object within the ghost's AABB, collision is calculated properly... but, when it leaves the AABB, and goes back in, the error behaviour resurfaces, with the AABB being used as the shape.
efaj
Posts: 8
Joined: Sun Dec 09, 2012 12:30 pm

Re: Ghost Object collision callback with related CollisionBo

Post by efaj »

efaj wrote:I'm having this same problem apparently.
If I create the object within the ghost's AABB, collision is calculated properly... but, when it leaves the AABB, and goes back in, the error behaviour resurfaces, with the AABB being used as the shape.
I just fixed mine....... I simply wasn't clearing the ManifoldArray after each loop. Maybe that's OP's problem.
You need to clear it because

Code: Select all

collisionPair->m_algorithm->getAllContactManifolds(manifoldArray);
doesn't alter the manifoldArray when there is no contact. So, when the object is within the broadphase (AABB), this function gets called, but since at the narrowphase there's no contact, manifoldArray isn't touched, and keeps the data from the previous loop. Or something along those lines.
Post Reply