problem with collision using btbvhtrianglemesh

haba
Posts: 21
Joined: Sun Oct 12, 2008 3:38 pm

problem with collision using btbvhtrianglemesh

Post by haba »

Hi,

I'm testing a simple collision between a btBoxShape and a btTriangleMesh (it's just a square plane built with two triangles). When I make the box fall onto the plane, the box starts twitching (as if it is stuck...). Does anyone have any idea of what the problem might be?

Edit: I tried moving the plane up and down, and when the plane is lower, so that the box gets more speed before colliding, the effect is worse, and the contrary when the plane is higher...

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

Re: problem with collision using btbvhtrianglemesh

Post by Erwin Coumans »

What is the size of the box? What is your timestep and gravity?

Can you reproduce it in a Bullet demo?

Thanks,
Erwin
haba
Posts: 21
Joined: Sun Oct 12, 2008 3:38 pm

Re: problem with collision using btbvhtrianglemesh

Post by haba »

Gravity is set to -10.

The floor (plane) is as follows:

Code: Select all

btTriangleMesh *mesh = new btTriangleMesh();
btVector3 v0(-50, 0, 50);
btVector3 v1(50, 0, 50);
btVector3 v2(50, 0, -50);
btVector3 v3(-50, 0, 50);
btVector3 v4(50, 0, -50);
btVector3 v5(-50, 0, -50);
mesh->addTriangle(v0, v1, v2);
mesh->addTriangle(v3, v4, v5);
		
btCollisionShape *mTriMeshShape = new btBvhTriangleMeshShape(mesh, false);
				
trans.setIdentity();
trans.setOrigin(btVector3(0, -22, 0));
motionState = new btDefaultMotionState(trans);
		
box2 = new btRigidBody(btScalar(0.0), motionState, mTriMeshShape, btVector3(0,0,0));
dynamicsWorld->addRigidBody(box2);	
The box that falls on the floor:

Code: Select all

shape = new btBoxShape(btVector3(10,10,10));
		
trans.setIdentity();
trans.setOrigin(btVector3(-10, 100, 0));
motionState = new btDefaultMotionState(trans);
		
box1 = new btRigidBody(btScalar(1.0), motionState, shape, btVector3(1,1,1));
dynamicsWorld->addRigidBody(box1);

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

Re: problem with collision using btbvhtrianglemesh

Post by Erwin Coumans »

You need to provide a proper inertia tensor, that matches the mass/volume:

Code: Select all

btScalar mass = 1.0;
shape->calculateLocalInertia(mass,localInertia);
btRigidBody* box1 = new btRigidBody(mass, motionState, shape, localInertia);
Hope this helps,
Erwin
haba
Posts: 21
Joined: Sun Oct 12, 2008 3:38 pm

Re: problem with collision using btbvhtrianglemesh

Post by haba »

That makes sense!
Problem solved! Thanks!