[C++] Little problem with Ghost Object (filter/groups prob)

Ripiz
Posts: 47
Joined: Mon Aug 16, 2010 10:43 am

[C++] Little problem with Ghost Object (filter/groups prob)

Post by Ripiz »

I'm using btKinematicClosestNotMeConvexResultCallback and Ghost Object's convexSweepTest() to detect if collision happened, however, if I set Default Filter for Ghost Object, my Body collides with Ghost Object, and doesn't behave properly. I'm having trouble figuring how to make it, so Body won't detect collision with Ghost Object, but Ghost Object's convexSweepTest() would detect collision with other objects (except same Body).

Here's my callback class:

Code: Select all

class btKinematicClosestNotMeConvexResultCallback : public btCollisionWorld::ClosestConvexResultCallback{
	public:
		btKinematicClosestNotMeConvexResultCallback(btCollisionObject* me) : ClosestConvexResultCallback(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 0.0, 0.0)){
			m_me = me;
		}

		virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult& convexResult,bool normalInWorldSpace){
			if (convexResult.m_hitCollisionObject == m_me)
				return btScalar(1.0);

			btVector3 hitNormalWorld;
			if (normalInWorldSpace){
				hitNormalWorld = convexResult.m_hitNormalLocal;
			}
			else{
				hitNormalWorld = convexResult.m_hitCollisionObject->getWorldTransform().getBasis()*convexResult.m_hitNormalLocal;
			}

			return ClosestConvexResultCallback::addSingleResult(convexResult, normalInWorldSpace);
		}
	protected:
		btCollisionObject* m_me;
		const btVector3 m_up;
		btScalar m_minSlopeDot;
};
Body and Ghost Object initialization:

Code: Select all

		bodyCollision = new btSphereShape(1);
		btTransform startTransform;
		startTransform.setIdentity();
		startTransform.setOrigin(btVector3(position.x, position.y, position.z));

		btVector3 localInertia(0, 0, 0);
		bodyCollision->calculateLocalInertia(1, localInertia);

		bodyMotionState = new btDefaultMotionState(startTransform);
		btRigidBody::btRigidBodyConstructionInfo rbInfo(1, bodyMotionState, bodyCollision, localInertia);

		body = new btRigidBody(rbInfo);
		physics->addRigidBody(body);
		body->setLinearVelocity(btVector3(direction.x, direction.y, direction.z) * 100);
		body->setFriction(0.5f);

		m_ghostObject = new btPairCachingGhostObject();
		m_ghostObject->setWorldTransform(startTransform);
		m_ghostObject->setCollisionShape(bodyCollision);
		physics->addCollisionObject(m_ghostObject);
convexSweepTest():

Code: Select all

btKinematicClosestNotMeConvexResultCallback callback(body);
		m_ghostObject->convexSweepTest((btConvexShape*)m_ghostObject->getCollisionShape(), m_ghostObject->getWorldTransform(), body->getWorldTransform(), callback);
		if(!callback.hasHit()){
			m_ghostObject->setWorldTransform(body->getWorldTransform());
		}
		else{
				// remove object
		}

Anyone know how to achieve this? Thank you in advance.


Edit:
Solved myself...