Concave-concave collision detection accuracy problem

Post Reply
CGBullet
Posts: 1
Joined: Fri Aug 17, 2012 3:32 pm

Concave-concave collision detection accuracy problem

Post by CGBullet »

Hi all,

I'm using the code below for collision detection of large concave triangle meshes.

This works, but the accuracy is quite low. Collisions are reported even when the objects are at least 1.0 units away from each other. I have other ways of verifying this distance, so I know it is the case.

The meshes only undergo translation and rotation, so they don't change shape or size. Also, there aren't more than a couple in the world at a time.

What am I missing?

Code: Select all

static btScalar gContactBreakingThreshold = 0.0f; // doesn't seem to have an effect though

void vtkBulletCollisionDetection::InitWorld()
{
	this->configuration = new btDefaultCollisionConfiguration();
	this->dispatcher = new btCollisionDispatcher(this->configuration);
	this->broadphase = new btSimpleBroadphase();

	this->world = new btCollisionWorld(this->dispatcher, this->broadphase, this->configuration);

	btGImpactCollisionAlgorithm::registerAlgorithm(this->dispatcher);
}

btRigidBody* vtkBulletCollisionDetection::CreateRigidBody(vtkPolyData *vtk_poly_data, vtkMatrix4x4 *vtk_matrix)
{
	int number_of_triangles;
	int number_of_points;
	int *triangles;
	btScalar *points;

	this->GetTriangleData(number_of_triangles, triangles, number_of_points, points, vtk_poly_data);

	btTriangleIndexVertexArray* bt_triangle_array = new btTriangleIndexVertexArray(number_of_triangles, triangles, 3 * sizeof(int), number_of_points, points, 3 * sizeof(btScalar));
	btGImpactMeshShape *bt_mesh_shape = new btGImpactMeshShape(bt_triangle_array);
	bt_mesh_shape->updateBound();

	btScalar matrix[15];
	this->GetMatrixData(matrix, vtk_matrix);

	btTransform bt_transform;
	bt_transform.setFromOpenGLMatrix(matrix);

	btRigidBody* bt_rigid_body = new btRigidBody(1.0, new btDefaultMotionState(bt_transform), bt_mesh_shape);
	bt_rigid_body->setContactProcessingThreshold(0.0); // this doesn't seem to help either

	return bt_rigid_body;
}

void vtkBulletCollisionDetection::AddActor(vtkActor *vtk_actor)
{
	btRigidBody* bt_rigid_body = this->CreateRigidBody(vtkPolyData::SafeDownCast(vtk_actor->GetMapper()->GetInput()), vtk_actor->GetMatrix());

	this->world->addCollisionObject(bt_rigid_body);

	this->actor_body_dictionary.push_back(ABPair(vtk_actor, bt_rigid_body));

	this->UpdateTransform(vtk_actor);
}

void vtkBulletCollisionDetection::UpdateTransform(vtkActor *vtk_actor)
{
	btRigidBody* bt_rigid_body;

	for(int i = 0; i < this->actor_body_dictionary.size(); i++)
	{
		ABPair pair = this->actor_body_dictionary[i];

		if(pair.first == vtk_actor)
		{
			bt_rigid_body = pair.second;

			break;
		}
	}

	btScalar matrix[15];
	this->GetMatrixData(matrix, vtk_actor->GetMatrix());

	btTransform bt_transform;
	bt_transform.setFromOpenGLMatrix(matrix);
	bt_rigid_body->setWorldTransform(bt_transform);
}

int vtkBulletCollisionDetection::CollisionQuery()
{
	this->world->performDiscreteCollisionDetection();

	int num_manifolds = this->world->getDispatcher()->getNumManifolds();
	if(num_manifolds == 0)
		return 0;

    int num_contacts = manifold->getNumContacts();

	return num_contacts;
}
Post Reply