Problem with triangle meshes and collision only

User avatar
chaosavy
Posts: 29
Joined: Wed Nov 11, 2009 9:09 pm

Problem with triangle meshes and collision only

Post by chaosavy »

Hi, I'm using collision only aspect of Bullet, following the collision only demo to integrate Bullet with Ogre, I'm also using btOgre to convert my collision shapes from Ogre meshes to Bullet meshes. Everything works as expected when I use convex shapes, however when I switch to trimesh I no longer get collisions (any collisions).

Is there something I"m missing when using triangle shapes as opposed to using convex shapes?

Here is the code that I'm using:



Initializing bullet

Code: Select all

	btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
	btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
	btVector3	worldAabbMin(-20000,-20000,-20000);
	btVector3	worldAabbMax(20000,20000,20000);

	btAxisSweep3*	broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);

	collisionWorld = new btCollisionWorld(dispatcher,broadphase,collisionConfiguration);
Adding collision shape

Code: Select all

	BtOgre::StaticMeshToShapeConverter converter(entity);

	btBvhTriangleMeshShape* shapeTMP=converter.createTrimesh();

	btMatrix3x3 basisA;
	basisA.setIdentity();

	newBody.btColObj = new btCollisionObject;
	newBody.btColObj->getWorldTransform().setBasis(basisA);
	newBody.btColObj->setCollisionShape(shapeTMP);
	collisionWorld->addCollisionObject(newBody.btColObj);

	//Initial position
	newBody.btColObj->getWorldTransform().setOrigin(btVector3(newBody.prevPos.x, newBody.prevPos.y, newBody.prevPos.z));


Testing for collisions

Code: Select all


	if (collisionWorld)
		collisionWorld->performDiscreteCollisionDetection();


	int numManifolds = collisionWorld->getDispatcher()->getNumManifolds();
	int i;
	for (i=0;i<numManifolds;i++)
	{
		btPersistentManifold* contactManifold = collisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
		btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
		btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());

		Ogre::Entity *a=static_cast<Ogre::Entity*>(obA->getUserPointer());
		Ogre::Entity *b=static_cast<Ogre::Entity*>(obB->getUserPointer());

		int mover = findBody(a); //Need to get the previous position, entities and scene nodes
		int hit = findBody(b); //Need to get the previous position, entities and scene nodes

		//This gets collisions to be much closer
		/* Check all contacts points */
		int numContacts = contactManifold->getNumContacts();
		for (int j=0;j<numContacts;j++)
		{
			btManifoldPoint& pt = contactManifold->getContactPoint(j);

			if (pt.getDistance()<0.f)
			{
				collision(timeSinceLastFrame, mover, a, hit, b);
				break;
	      		}
		 }
	}

any ideas? thanks
Mattg
Posts: 12
Joined: Thu Oct 22, 2009 12:50 am

Re: Problem with triangle meshes and collision only

Post by Mattg »

I don't think mesh vs. mesh collision is supported if that's what you're doing.
User avatar
chaosavy
Posts: 29
Joined: Wed Nov 11, 2009 9:09 pm

Re: Problem with triangle meshes and collision only

Post by chaosavy »

are you saying that triangle mesh to triangle mesh collision is not supported?
Mattg
Posts: 12
Joined: Thu Oct 22, 2009 12:50 am

Re: Problem with triangle meshes and collision only

Post by Mattg »

Yes but I'm not sure. I know that triangle meshes aren't supported for dynamic bodies. Therefore there's no case where bullet need to do triangle mesh vs. triangle mesh collision which makes me think it's not supported/not implemented.
User avatar
chaosavy
Posts: 29
Joined: Wed Nov 11, 2009 9:09 pm

Re: Problem with triangle meshes and collision only

Post by chaosavy »

Looks like that's the deal, thanks for the help, I did some searching and found this

http://bulletphysics.org/Bullet/phpBB3/ ... ape#p15622

The issue I'm having is that I'm trying to create a carrier type space ship, that has an opening for fighter ships to land/pass through.

What I think I'll do is shoot a triangle detecting ray when I collide with these types of ships as a fighter ship to see if I should be going through the opening.