Problem to adjust collision behaviour

Post Reply
Kalinarm
Posts: 6
Joined: Tue May 08, 2012 2:46 pm

Problem to adjust collision behaviour

Post by Kalinarm » Tue May 08, 2012 3:04 pm

Hi everybody,
i don't find a concrete answer in this forum, so i ask my question here.
I have a sphere and a shape body. only the sphere is dynamic (i.e. mass !=0)

i initialize my physic word with :

Code: Select all

	myCollisionConfiguration = new btDefaultCollisionConfiguration(); 
	myDispatcher = new	btCollisionDispatcher(myCollisionConfiguration);
	myBroadphase = new btDbvtBroadphase();
	mySequentialImpulseConstraintSolver = new btSequentialImpulseConstraintSolver();
	myWorld = new btDiscreteDynamicsWorld(myDispatcher,myBroadphase,mySequentialImpulseConstraintSolver,myCollisionConfiguration);
	myWorld->getSolverInfo().m_splitImpulse = true;
	myWorld->setGravity( btVector3(0.0,0.0,0.0) ); 
and initialize my object with :

Code: Select all

btCollisionShape* shape;
	if (m_shape=="sphere")
	{
		shape = new btSphereShape(btVector3(m_size.x,m_size.y,m_size.z).length()/3.0);
	}
	else
	{
		shape = new btBoxShape(btVector3(m_size.x,m_size.y,m_size.z));
	}
	//shape->setMargin(0.3f);
	m_transform.setIdentity();

	//get the intial position of the object
	FCgetPosition f; /* ... */
	m_transform.setOrigin( btVector3(f.position.x,f.position.y,f.position.z) ); 

	//On calcule l'inertie suivant le poids.
	btVector3 localInertia(m_localInertia.x,m_localInertia.y,m_localInertia.z);

	if (m_mass)
		shape->calculateLocalInertia( m_mass, localInertia );
	m_motionState = new btDefaultMotionState(m_transform);
	btRigidBody::btRigidBodyConstructionInfo myBoxRigidBodyConstructionInfo( m_mass, m_motionState, shape, localInertia );
	myBoxRigidBodyConstructionInfo.m_friction=0.0f;
	myBoxRigidBodyConstructionInfo.m_restitution=0.9f;
	m_body = new btRigidBody(myBoxRigidBodyConstructionInfo);
	m_body->setLinearFactor(btVector3(1.0,1.0,0.0));
	m_body->setAngularFactor(btVector3(0.0,0.0,0.0));
	//reference to the physic bullet world
	PHYSIC->getWorld()->addRigidBody(m_body);
	m_body->setLinearVelocity(btVector3(5,15,0));
my scene is one ball in center of 4 box which build borders like in a pool.

My problem is when ball collide with borders : the ball stick on the box. I don't success to adjust the collision to have a "classic" bounce, like in pool but with a total restitution of the velocity after the collision

I follow many pist :

* the margin of the body ( if too higher, the ball go through the border)
* to add "myWorld->getSolverInfo().m_splitImpulse = true;" : nothing change
* adjust contact threshold : nothing change
* i read somewhere to switch continous detection to off, but i've don't find something like that in the API

If someone has some advices or ways of reflexion,
feel free to share it.

Thanks in advance
PS : sorry for my english

marios
Posts: 52
Joined: Mon Jul 19, 2010 3:11 am
Contact:

Re: Problem to adjust collision behaviour

Post by marios » Tue May 08, 2012 6:47 pm

have you set restitution value to four bounding boxes?
bullet seems to calculate collision restitution value like min(body1_restitution,body2_restitution)

edit: ok i see now that you did that

Kalinarm
Posts: 6
Joined: Tue May 08, 2012 2:46 pm

Re: Problem to adjust collision behaviour

Post by Kalinarm » Tue May 08, 2012 7:32 pm

Thanks for reply. i didn't know that restitution factor was added.
I precise that the second code posted iterates 5 times, one for sphereShape and 4 for boxshape.

marios
Posts: 52
Joined: Mon Jul 19, 2010 3:11 am
Contact:

Re: Problem to adjust collision behaviour

Post by marios » Wed May 09, 2012 7:52 pm

I know that is not what you want, but can you change sphere shape to box shape and see if problem with restitution still occurs?

Kalinarm
Posts: 6
Joined: Tue May 08, 2012 2:46 pm

Re: Problem to adjust collision behaviour

Post by Kalinarm » Thu May 10, 2012 12:30 pm

i try with only box shape, and it does the same.
if you have any other test ideas, i would greatly appreciated them ;)
I don't have any ideas of making this works

Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Problem to adjust collision behaviour

Post by Flix » Sun May 13, 2012 8:15 am

I'd probably override the method that Bullet uses to calculate global friction/restitution values through a custom material callback and play around with the values a bit (AFAIK by default the combined friction/restitution is calculated by multiplying the friction/restitution of the two bodies, and probably the result is clamped to 0-1). You might try a linear combination of the values instead (with or without clamping). If you don't know how to do it, please browse the forum, or look closely at the Bullet demos (I'm sure some demo uses it).

Split impulse might probably help.

If there's no improvement you may try replacing the btSphereShape with a btMultisphereShape (with a single sphere inside it): in some (rare) cases somebody reported they behave better.

Post Reply