Can I get the DynamicWorld from a btCollisionObject?

SteveDeFacto
Posts: 31
Joined: Sat Jul 23, 2011 4:24 pm

Can I get the DynamicWorld from a btCollisionObject?

Post by SteveDeFacto »

I am trying to disable collision on objects that are touching but I have run into a problem due to the structure of my project and the required use of call backs to test for collision. I am unable to get a pointer to the DynamicWorld from a btCollisionObject and I have no global pointer to the world which I can use.

Below is an example of what I'm trying to do.

Code: Select all

struct DisablePairCollision : public btCollisionWorld::ContactResultCallback
{
	virtual	btScalar	addSingleResult(btManifoldPoint& cp,	const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
	{
		btTransform bodyMatA, bodyMatB;
		bodyMatA = colObj0->getWorldTransform();
		bodyMatB = colObj1->getWorldTransform();
		btTransform frameInA, frameInB;
		frameInA = bodyMatB * bodyMatA.inverse();
		frameInB.setIdentity();
		btGeneric6DofConstraint* Constraint;
		Constraint = new btGeneric6DofConstraint( colObj0, colObj1, frameInA, frameInB, true );
		Constraint->setLinearLowerLimit( btVector3(1, 1, 1 ) );
		Constraint->setLinearUpperLimit( btVector3(0, 0, 0 ) );
		Constraint->setAngularLowerLimit( btVector3(1, 1, 1 ) );
		Constraint->setAngularUpperLimit( btVector3(0, 0, 0 ) );
		DynamicWorld->addConstraint(Constraint, true);
		return 0;
	}
};
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Can I get the DynamicWorld from a btCollisionObject?

Post by Erwin Coumans »

Have you considered storing a pointer to the world in your custom 'DisablePairCollision' structure?

We try to avoid circular dependencies in Bullet (and the world already knows about collision objects, so we can't add a pointer vise versa)
Thanks,
Erwin
SteveDeFacto
Posts: 31
Joined: Sat Jul 23, 2011 4:24 pm

Re: Can I get the DynamicWorld from a btCollisionObject?

Post by SteveDeFacto »

Erwin Coumans wrote:Have you considered storing a pointer to the world in your custom 'DisablePairCollision' structure?

We try to avoid circular dependencies in Bullet (and the world already knows about collision objects, so we can't add a pointer vise versa)
Thanks,
Erwin
That did work! Thank you!