-1

I'm playing around with Bullet, I have a ground-floor and a ball, and I want the ball to fall and bounce on the ground. However this doesn't happen, even with very high values of m_restitution, which is supposed to regulate the bounciness.

Any clue why this is happening? This is torturing me for some hours now with no luck.

btBroadphaseInterface* broadphase = new btDbvtBroadphase();

btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();

btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);

btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;

dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);

dynamicsWorld->setGravity(btVector3(0,+9.8,0)); // GLWidget - y axis points downwards !!!


/////////////////////////////////////////////////////////////////////////////
////  Ground  ///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0,0,0)));

btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0,0,0));

groundRigidBodyCI.m_restitution     = 1.0f;
groundRigidBodyCI.m_friction        = 3.0f;
groundRigidBodyCI.m_rollingFriction = 3.0f;
groundRigidBodyCI.m_mass            = 0.0f;

btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);

dynamicsWorld->addRigidBody(groundRigidBody);


/////////////////////////////////////////////////////////////////////////////
////  Ball  /////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

btDefaultMotionState* ballMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0,-100,0)));

btScalar ballMass = 1;
btVector3 ballInertia;//(0,0,0);
ballShape->calculateLocalInertia(ballMass, ballInertia);

btRigidBody::btRigidBodyConstructionInfo ballRigidBodyCI(ballMass, ballMotionState, ballShape, ballInertia);
groundRigidBodyCI.m_restitution   = 1.0f;
ballRigidBodyCI.m_friction        = 1.0f;
ballRigidBodyCI.m_rollingFriction = 1.0f;

btRigidBody* ballRigidBody = new btRigidBody(ballRigidBodyCI);
dynamicsWorld->addRigidBody(ballRigidBody);


//Without the next it doesn't bounce at all
//With it, it bounces just a TINY little bit
dynamicsWorld->getSolverInfo().m_splitImpulse = false;
dim_tz
  • 1,451
  • 5
  • 20
  • 37

1 Answers1

4

OK, the above code should work in theory, but I'm not sure why it doesn't work.

As said, the property that regulates bounciness is m_restitution. This can be set in two ways. The first way is noted in the question-post. The other way is the following:

groundRigidBody->setRestitution(1.0);
ballRigidBody->setRestitution(1.0);

...and it works. Based on what I read on the net (e.g. here), both ways should be fine, but in my case it works only with the second way. I'm using bullet-2.82-r2704 on Ubuntu.

This happens only with the m_restitution property, All the other properties are set fine in the way of my question-post.

Plus, the line dynamicsWorld->getSolverInfo().m_splitImpulse = false; is not needed any more.

Community
  • 1
  • 1
dim_tz
  • 1,451
  • 5
  • 20
  • 37