Problem with restitution and small time steps

timmyl17
Posts: 6
Joined: Sun Oct 30, 2011 12:33 am

Problem with restitution and small time steps

Post by timmyl17 »

Hi,

I'm having a problem with restitution when using small time steps. I've modified BasicDemo.cpp to demonstrate. I'm having problems actually uploading the file, but the important lines are below There's a static box (ground), and a sphere, each with a restitution coefficient of .98. So the sphere should be pretty bouncy, but it doesn't bounce at all. If I change the internal time step from 1/1000 to 1/60 (the default), there is some bounce, but for a restitution of .98 the bounce doesn't seem high enough to me. Am I misunderstanding something?

Thanks for the help!

Code: Select all

m_dynamicsWorld->stepSimulation(ms / 1000000.f, 10000, 1/1000.);
This line seems to be causing the problem. If I change it to

Code: Select all

m_dynamicsWorld->stepSimulation(ms / 1000000.f, 10000, 1/60.);
the ball bounces.

Code: Select all

btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
//	btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50);
	
	m_collisionShapes.push_back(groundShape);

	btTransform groundTransform;
	groundTransform.setIdentity();
	groundTransform.setOrigin(btVector3(0,-50,0));

	//We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
	{
		btScalar mass(0.);

		//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)
			groundShape->calculateLocalInertia(mass,localInertia);

		//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
		btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
		btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
		btRigidBody* body = new btRigidBody(rbInfo);
    body->setRestitution(.98);

		//add the body to the dynamics world
		m_dynamicsWorld->addRigidBody(body);
	}


	{
		//create a few dynamic rigidbodies
		// Re-using the same collision is better for memory usage and performance

		btCollisionShape* colShape = new btSphereShape(5);
		//btCollisionShape* colShape = new btSphereShape(btScalar(1.));
		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(5,20,5));


    //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
    btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
    btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
    btRigidBody* body = new btRigidBody(rbInfo);

    body->setRestitution(.98);

    m_dynamicsWorld->addRigidBody(body);
timmyl17
Posts: 6
Joined: Sun Oct 30, 2011 12:33 am

Re: Problem with restitution and small time steps

Post by timmyl17 »

Update: If I give the sphere a lot of downward velocity (200), then it will bounce once. So I'm assuming there's some threshold for how fast the object needs to be moving, or how much it has to penetrate, to activate restitution? But I'm not sure which threshold it is.