Problems with internal types / collision masks

EruFeanor
Posts: 1
Joined: Wed Apr 16, 2014 1:07 pm

Problems with internal types / collision masks

Post by EruFeanor »

Hallo im new to bullet so my problem may be my current understanding of bit-masks in bullet.

The Problem:
I created a class, btFractureBody, which inherits from the btRigidbody class and defines a mask for these kind of rigidbodys as internal type.

Code: Select all

[btFractureBody]#define CUSTOM_FRACTURE_TYPE (btRigidBody::CO_USER_TYPE | btRigidBody::CO_RIGID_BODY | btRigidBody::CO_COLLISION_OBJECT)
When a btFractureBody is initialized i set the internal type to my custom mask.

Code: Select all

[btFractureBody]
btFractureBody(const btRigidBodyConstructionInfo& constructionInfo, btDynamicsWorld* world)
	:btRigidBody(constructionInfo),
	m_world(world),
	m_principalAxis(btTransform::getIdentity())
{
	m_masses.push_back(constructionInfo.m_mass);
	m_internalType  = m_internalType | CUSTOM_FRACTURE_TYPE;
	m_collisionFlags = m_collisionFlags | CollisionFlags::CF_CUSTOM_MATERIAL_CALLBACK;
}
in the same class (btFractureBody) i have added a static collision callback method which i set to be a a in the demo.

Code: Select all

[btFractureBody]
bool btFractureBody::collisionCallback(btManifoldPoint& cp,const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
{
	bool isFractureObject0 = (colObj0->getInternalType() & CUSTOM_FRACTURE_TYPE) == CUSTOM_FRACTURE_TYPE;
	bool isFractureObject1 = (colObj1->getInternalType() & CUSTOM_FRACTURE_TYPE) == CUSTOM_FRACTURE_TYPE;

	if(isFractureObject0 || isFractureObject1)
		printf("obj0: %d idx0: %d\nobj1: %d idx1: %d\n\n", isFractureObject0, index0, isFractureObject1, index1);

	if(isFractureObject0 && cp.m_appliedImpulse > BREAK_THRESHOLD)
	{
		btFractureBody* fb = (btFractureBody*)upcast(colObj0);
		btScalar radius = cp.m_appliedImpulse/20.f;				
		btVector3 hitPos	= cp.getPositionWorldOnA();

		btCompoundShape* compoundShape = (btCompoundShape*)colObj0->getCollisionShape();

		int size = compoundShape->getNumChildShapes();			
                printf("num childs: %d\n", size);
		for(int i=1; i<size; i++)
		{
			if( (compoundShape->getChildTransform(i).getOrigin()-hitPos).length2() < pow(radius,2) )
				fb->removeChildBodyByIndex(i);
		}
		fb->shiftToCenterOfMass();
	}
	return false;
}

[Demo:initPhysics]
gContactAddedCallback = (ContactAddedCallback)btFractureBody::collisionCallback;
The programm prints for the number of childeren unrealistic values e.g. minus values, which indicates that given collision object does not contain a compound shape, but every btFracturBody must contains a compound shape, only childs are added.

The collision callback as it is does not work, can you tell me why, every kind of advice is appriciated, thanks.