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();
}
Any help is appreciated.