Understanding collisions

charles_west
Posts: 11
Joined: Mon Oct 19, 2009 12:41 am

Understanding collisions

Post by charles_west »

Hello, I'm a little new at this and I'm trying to put together my first practical application using Bullet and Ogre. So far, I have a ball that falls on a plane, bounces and settles down. I have also implemented basic representation of this in ogre as well as a mouse/keyboard controlled camera. Now I would like to see if I can work with collisions.

In the wiki, the first implementation of collision notification looks like this:

Code: Select all

	//Assume world->stepSimulation or world->performDiscreteCollisionDetection has been called

	int numManifolds = world->getDispatcher()->getNumManifolds();
	for (int i=0;i<numManifolds;i++)
	{
		btPersistentManifold* contactManifold =  world->getDispatcher()->getManifoldByIndexInternal(i);
		btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
		btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
	
		int numContacts = contactManifold->getNumContacts();
		for (int j=0;j<numContacts;j++)
		{
			btManifoldPoint& pt = contactManifold->getContactPoint(j);
			if (pt.getDistance()<0.f)
			{
				const btVector3& ptA = pt.getPositionWorldOnA();
				const btVector3& ptB = pt.getPositionWorldOnB();
				const btVector3& normalOnB = pt.m_normalWorldOnB;
			}
		}
	}
There isn't too much commenting in the API on what some of these things are meant for, so I was hoping I could give my best guess of what is happening here and be corrected.

As far as I can tell, in the first line the number of contacts that are occurring is retrieved (this is for each pair of objects right?). It then iterates through each pair that is currently in contact. In each iteration, it retrieves the collision shapes that are involved in the collision (can I cast for a rigid body and use the userData pointer to find the application objects involved?). It then retrieves how many contact points are involved in the collision and retrieves where it is occurring and the object normal. I'm a little confused about this part. Why are there two points if it is a single contact location?

If I may ask, what have I missed and where am I wrong? Thanks.
Michael Stengel
Posts: 6
Joined: Tue Jul 06, 2010 4:10 pm
Location: Wolfsburg

Re: Understanding collisions

Post by Michael Stengel »

Hi Charles,
in theory you have to differentiate between penetration and contact (touching contact). For a penetration you can estimate a pair of points P_i and P_j (look at the first picture).
penetration_contact.JPG
Touching of objects is the limiting case, when P_i and P_j are equal (second picture).
touching_contact.JPG
The collision detection always gives you contact pairs (one point on object i, one point on object j in world coordinates + the normal on object j) and not a (touching) contact. You can see that two objects are in touch (so do not penetrate), if the distance between these two points are in a certain epsilon.

Hope this helps!
Michael
You do not have the required permissions to view the files attached to this post.