Another terrain issue

visualcubb
Posts: 7
Joined: Thu Nov 29, 2007 5:55 pm

Another terrain issue

Post by visualcubb »

Hi all.

This is my first post here, i'm just download bullet some weeks ago and i need some little help.

I already have a basic engine to load, configure and render in OpenGL mesh created from Maya 8.5, i just need a physic engine to finish that, but i have a little problem with bullet.

As an example, i'm using the CollisionInterfaceDemo from bullet's packet, and when i use some premade shapes (sphere, cubes, etc) collision works fine. But if i put two meshShapes, collision never responds, only works if one of those objects is a premade shape and the other one is a meshShape.

That's one problem, the other one is, when i try to get a collision from a terrain mesh, bullet detect and keep the collision until i go "under" the terrain or if i go over the most biggest point of the terrainShape, with or without "visual" collision.

If you want some code to see what's happening its just the same code of that example.

Hope you can help me.

Thanks.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Another terrain issue

Post by Erwin Coumans »

visualcubb wrote:As an example, i'm using the CollisionInterfaceDemo from bullet's packet, and when i use some premade shapes (sphere, cubes, etc) collision works fine. But if i put two meshShapes, collision never responds, only works if one of those objects is a premade shape and the other one is a meshShape.
Bullet btBvhTriangleMeshShape are supposed to be used only for static triangle meshes, and there is no collision detection between 2 static triangle meshes. If you really need collision detection between concave triangle meshes, you can use GIMPACT.
That's one problem, the other one is, when i try to get a collision from a terrain mesh, bullet detect and keep the collision until i go "under" the terrain or if i go over the most biggest point of the terrainShape, with or without "visual" collision.

If you want some code to see what's happening its just the same code of that example.
Which example, how can it be reproduced exactly?

Thanks,
Erwin
visualcubb
Posts: 7
Joined: Thu Nov 29, 2007 5:55 pm

Re: Another terrain issue

Post by visualcubb »

I'm using the ConcavePhysicsDemo, this is the problem:

This is the example, the red cube and the brown "terrain" are the two models that i want to take responde when they collide each other.

Image

When i touch the terrain with the red cube, Bullet detects the collision:

Image

But, if i come back to the original position with the red cube, bullet still show a collision.

Image

And only said that there's no collision when i go over the most biggest point of the terrainShape

Image

I really apreciate any help that you can give me.

Thanks.

PD: the code is exactly the same as the ConcavePhysicsDemo, i just put another concave model.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Another terrain issue

Post by Erwin Coumans »

Are you using full Bullet btDiscreteDynamicsWorld with simulation, or only the collision detection parts?

Can you attach a reproduction codebase?
Thanks,
Erwin
visualcubb
Posts: 7
Joined: Thu Nov 29, 2007 5:55 pm

Re: Another terrain issue

Post by visualcubb »

Erwin Coumans wrote:Are you using full Bullet btDiscreteDynamicsWorld with simulation, or only the collision detection parts?

Can you attach a reproduction codebase?
Thanks,
Erwin

Only Collision detection part Erwin. i'll put some code in a few hour, i'm at work now :).

PD: Thanks for your fast answer :)
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Another terrain issue

Post by Erwin Coumans »

Are you using the btCollisionWorld::performDiscreteCollisionDetection?

It sounds like the btPersistentManifold::refreshContactPoints(...) is not called. This method is responsible for disposing invalid contact points in the btPersistentManifold contact cache.

This is being called within void btConvexConcaveCollisionAlgorithm::processCollision.

Hope this helps,
Erwin
visualcubb
Posts: 7
Joined: Thu Nov 29, 2007 5:55 pm

Re: Another terrain issue

Post by visualcubb »

Erwin Coumans wrote:Are you using the btCollisionWorld::performDiscreteCollisionDetection?

It sounds like the btPersistentManifold::refreshContactPoints(...) is not called. This method is responsible for disposing invalid contact points in the btPersistentManifold contact cache.

This is being called within void btConvexConcaveCollisionAlgorithm::processCollision.

Hope this helps,
Erwin

THis is my code:

Code: Select all

if (collisionWorld)
		collisionWorld->performDiscreteCollisionDetection();

	
	if( (v_count = collisionWorld->getDispatcher()->getNumManifolds()) > 0)
	{
		btPersistentManifold* contactManifold = 
			collisionWorld->getDispatcher()->getManifoldByIndexInternal(v_count-1);
		btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
		btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
		contactManifold->refreshContactPoints(obA->getWorldTransform(),obB->getWorldTransform());
		v_count = obB->getCompanionId();
	
		if( contactManifold->getNumContacts()> 0)
			collide = true;

		contactManifold->clearManifold();
		
	}

	else
		collide = false;
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Another terrain issue

Post by Erwin Coumans »

It is not easy to track down the issue in your case. For sure the contact points in Bullet are updated correctly, just compare with the unmodified ConcaveDemo.

One thing to note is that you need to check if the distance for all contacts is negative, so not just checking the number of contacts. The contact caching of btPersistentManifold keeps 'invalid' contacts that might become valid soon again.

So try to make a change from

Code: Select all

  if( contactManifold->getNumContacts()> 0)
         collide = true;
into

Code: Select all

  if( contactManifold->getNumContacts()> 0)
 {
  for (int i=0;i<contactManifold->getNumContacts();i++)
  {
    btManifoldPoint& cp = manifoldPtr->getContactPoint(i);
    if (cp.getDistance() <= btScalar(0.))
    {
         collide = true;
    }
   }
 }
Hope this helps,
Erwin
visualcubb
Posts: 7
Joined: Thu Nov 29, 2007 5:55 pm

Re: Another terrain issue

Post by visualcubb »

Erwin Coumans wrote:It is not easy to track down the issue in your case. For sure the contact points in Bullet are updated correctly, just compare with the unmodified ConcaveDemo.

One thing to note is that you need to check if the distance for all contacts is negative, so not just checking the number of contacts. The contact caching of btPersistentManifold keeps 'invalid' contacts that might become valid soon again.

So try to make a change from

Code: Select all

  if( contactManifold->getNumContacts()> 0)
         collide = true;
into

Code: Select all

  if( contactManifold->getNumContacts()> 0)
 {
  for (int i=0;i<contactManifold->getNumContacts();i++)
  {
    btManifoldPoint& cp = manifoldPtr->getContactPoint(i);
    if (cp.getDistance() <= btScalar(0.))
    {
         collide = true;
    }
   }
 }
Hope this helps,
Erwin

Well, maybe that's the problem, ill try to make this change today, but, i don't like the way to fix this, there're too many iterations, is there any chance to reduce the contact points just to 1? i don't need precision, just want to know if there is or there is not a collision.

Thanks Erwin.
visualcubb
Posts: 7
Joined: Thu Nov 29, 2007 5:55 pm

Re: Another terrain issue

Post by visualcubb »

Doesn't work :( ill keep trying.

THanks.
visualcubb
Posts: 7
Joined: Thu Nov 29, 2007 5:55 pm

Re: Another terrain issue

Post by visualcubb »

OK! Now it's working very good.

But like i said before, is there any change to configure Bullet so he just calculate 1 collision point?.
I don't like the idea to ask for every contact point asking about his distance.