Internal Edges problem - I think I've encountered

Adversus
Posts: 19
Joined: Mon Nov 10, 2008 11:24 am

Internal Edges problem - I think I've encountered

Post by Adversus »

Hi Guys,

I hope you will be able to help as I'm a bit lost at the moment. I've been trying to follow the KinematicCharacterController and the ConcaveDemo without much luck.

Currently I'm trying to get collision detection and response working for:

I have a rigid Body that acts as my level geometry with mass=0.0 that's just polygon soup that uses a btBvhTriangleMeshShape created by:

/

Code: Select all

/ create the collision mesh
bool useQuantizedAabbCompression = true;
collisionShape = new btBvhTriangleMeshShape(triangleMesh, useQuantizedAabbCompression); 
and a collision object that uses created by:

Code: Select all

// create the collision capsule
collisionShape = new btCapsuleShape( btScalar(radius), btScalar(height) );
Now I detect the collisions with a callback set by setInternalTickCallback (code below) and try to separate them (following the same principle as the KinematicCharacterController however the normal doesn't appear to be correct sometimes and I have weird behavior especially when sliding across internal edges, is this the internal edges problem? Is there a way to solve this?

Cheers and thanks for any help you can give,
John.

Code: Select all

// bullet collision deletection
int numManifolds = dynamicsWorld->getDispatcher()->getNumManifolds();
for ( int i=0; i<numManifolds; i++)
{
	// get the contact manifold
	btPersistentManifold *contactManifold = dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
	
	// collision ?
	if( contactManifold->getNumContacts() > 0 )
	{
		bool penetration = false;
		// get the collision objects
		btCollisionObject *objA = static_cast<btCollisionObject*>(contactManifold->getBody0());
		btCollisionObject *objB = static_cast<btCollisionObject*>(contactManifold->getBody1());
		
		btVector3 normal;
		btVector3 translation(0.0,0.0,0.0);			
		
		// separate
		btScalar maxPen = btScalar(0.0);
		for (int p=0;p<contactManifold->getNumContacts();p++)
		{
			if( contactManifold->getNumContacts() > 1 )
			{
				int i=0;
				i++;
			}
			
			const btManifoldPoint&pt = contactManifold->getContactPoint(p);
			
			if (pt.getDistance() < 0.0)
			{
				if (pt.getDistance() < maxPen)
				{
					maxPen = pt.getDistance();
					normal = pt.m_normalWorldOnB;
					printf("col_point:%d : normal:%4.2f,%4.2f,%4.2f\n", p, normal.getX(), normal.getY(), normal.getZ() );
//						Pause();
				}
				translation += pt.m_normalWorldOnB * pt.getDistance() * btScalar(-0.2);
				penetration = true;
			} 
			else 
			{
				//printf("touching %f\n", pt.getDistance());
			}
		}	
		
		if( penetration )
		{
			// get the entities
			Entity *entityA = static_cast<Entity*>(objA->getUserPointer());
			Entity *entityB = static_cast<Entity*>(objB->getUserPointer());						
			
			// get the current pos of Entity A
			btVector3 currentPos = ToBulletVector( entityA->GetPosition() ); 
			
			// move entity A away
			entityA->SetPosition( ToIrrVector(currentPos + translation) );
			
			//				btTransform start, end;
			//				m_targetPosition = currentPos + walkMove;
			//				start.setIdentity ();
			//				end.setIdentity ();				
			
			// call the collision callbacks
			entityA->OnCollision( *entityB );
			entityB->OnCollision( *entityA );
		}
	}	
	
	//you can un-comment out this line, and then all points are removed
	//contactManifold->clearManifold();	
}	
Adversus
Posts: 19
Joined: Mon Nov 10, 2008 11:24 am

Re: Internal Edges problem - I think I've encountered

Post by Adversus »

OK I've changed my code a little and I've improved it alot by looping over it more each frame and writing a custom btOverlappingPairCallback however I tend to find that my object follows the edges of the triangles even though the triangles are co-planar. I'm pretty sure this is the internal edges problem now as I've been looking at the normals and they seem wrong.

How do these internal edge normals get created? Surely if the points lie across co-planar or close then the normal should be the average of the triangles normals and not some edge that lies perpendicular.

I'm I missing something, I'm a bit confused.