Sphere restitution 1 causes bouncing height to vary strongly

benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland

Sphere restitution 1 causes bouncing height to vary strongly

Post by benelot »

Hello,

I wanted to create an example to show how restitution scales with the chosen time step. Therefore I wanted to simulate an everbouncing sphere on ground. I set the ground and sphere to restitution 1, which should result in a sphere bouncing always to the same height. However, this does not seem to work properly as well. Thinking that my example is somehow broken, I changed the SimpleBox example in ExtendedTutorials to do the same, and indeed, the sphere bounces for a while to the correct height, then the drops about 20%, then after a while even 50% and then the sphere stops to bounce completely.

Replace the initPhysics and renderScene methods in simple box with the following:

Code: Select all

void SimpleBoxExample::initPhysics()
{
	m_guiHelper->setUpAxis(1);

	createEmptyDynamicsWorld();
	
	m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);

	if (m_dynamicsWorld->getDebugDrawer())
		m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints);

	///create a few basic rigid bodies
	btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
	m_collisionShapes.push_back(groundShape);

	btTransform groundTransform;
	groundTransform.setIdentity();
	groundTransform.setOrigin(btVector3(0,-50,0)); 
	{
		btScalar mass(0.);
		btRigidBody* ground = createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1));
		ground->setRestitution(1.0f);
	}


	{
		//create a few dynamic rigidbodies
		// Re-using the same collision is better for memory usage and performance
        btSphereShape* colShape = new btSphereShape(2);
		 
		m_collisionShapes.push_back(colShape);

		/// Create Dynamic Objects
		btTransform startTransform;
		startTransform.setIdentity();

		btScalar	mass(1.f);

		//rigidbody is dynamic if and only if mass is non zero, otherwise static
		bool isDynamic = (mass != 0.f);

		btVector3 localInertia(0,0,0);
		if (isDynamic)
			colShape->calculateLocalInertia(mass,localInertia);


		startTransform.setOrigin(btVector3(btScalar(-10), btScalar(10), btScalar(-10)));
		btRigidBody* box = createRigidBody(mass,startTransform,colShape);
		box->setRestitution(1.0f);
		box->setCcdMotionThreshold(100000.0f);
		box->setCcdSweptSphereRadius(100.0f);
		box->setActivationState(DISABLE_DEACTIVATION);
		gBox = box;
	}

	m_dynamicsWorld->getSolverInfo().m_splitImpulse = 1;

	m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld);
}


void SimpleBoxExample::renderScene()
{
	b3Printf("Height: %f",gBox->getWorldTransform().getOrigin().y());
	CommonRigidBodyBase::renderScene();	
}
Should this be the normal behavior? The restitution seems to decay strongly at some points in time, but I can not see why.

Any help is appreciated.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland

Re: Sphere restitution 1 causes bouncing height to vary stro

Post by benelot »

I even applied the fixes proposed here:
http://bulletphysics.org/Bullet/phpBB3/ ... rte#p24631

It basically proposes to enable split impulse and disable CCD. However, this seems not to fix the problem. I could reproduce the problem using the Sequential Impulse Solver, the Danzig Solver and Lemke Solver, but not with the NNCG Solver. The NNCG Solver causes the ball to bounce higher and higher. What am I doing wrong?

As proposed by:
http://bulletphysics.org/Bullet/phpBB3/ ... rte#p25191

It works much better with a multisphere shape:

Code: Select all

		btVector3 pos(0,0,0);
		btScalar radius(1.0);
		btMultiSphereShape* colShape = new btMultiSphereShape(&pos, &radius,1);
Jez Hammond
Posts: 7
Joined: Tue Apr 12, 2016 12:53 pm

Re: Sphere restitution 1 causes bouncing height to vary stro

Post by Jez Hammond »

Perhaps try with a skin of 0.0 on both rigids.

Failing that I think perpetual bouncing is such a rare case that it might be ok to very slightly throttle a force on contact started/ended (for example).
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland

Re: Sphere restitution 1 causes bouncing height to vary stro

Post by benelot »

Thanks, I will try, but you are right, that is a strange case anyway. I thought it might be sort of a unit test case if it restores full height properly.