First of all congrats to everyone involved into the creation and maintenance of the bullet library.
I am trying to make a small game using bullet.
You control a flat box which you can rotate (pitch,roll) using the mouse. On top of the box is a ball.
So you have to balance the ball not fall outside.
I am trying to work out the mechanics so thats why the gameplay is not that great
I used a modification of the BasicDemo, with a few bits of the CCDDemo.
In essence I use a KINEMATIC boxshape as the platform and a sphere shape as a dynamic object. I change every frame the rotation of the kinematic object. the Gravity is 0,-10,0.
The problem is that If I rotate slightly the box the ball does not follow the box smoothly but makes little bounces giving the impression of unsmooth ball motion. If you make a big rotation the ball goes completely out of control.
This looks very unnatural and I am looking for a way to make the ball stick always onto the platform and to disallow bouncing. Any pointers how I could do that.
I am attaching a small executable which shows what I am taking about. Try to use the mouse to make the ball go from the left to the right side, or any sudden movements and you will see what I talking about.
Thanks for any help in advance
Oratio
Here are some various peaces of code which I use:
Code: Select all
void BasicDemo::clientMoveAndDisplay()
{
...
//KINEMATIC GROUND
btQuaternion kinRotationZ(btVector3(0,0,1),rotZ);
btQuaternion kinRotationX(btVector3(1,0,0),rotX);
//kinematic object
btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[0];
if (btRigidBody::upcast(colObj))
{
btTransform newTrans;
btTransform newTrans2(kinRotationX);
btRigidBody::upcast(colObj)->getMotionState()->getWorldTransform(newTrans);
newTrans.setRotation (kinRotationZ);
newTrans *= newTrans2;
btRigidBody::upcast(colObj)->getMotionState()->setWorldTransform(newTrans);
}
...
float dt = m_clock.getTimeMicroseconds() * 0.000001f;
m_clock.reset();
int maxSimSubSteps = 1;//m_idle ? 1 : 1;
if (m_dynamicsWorld)
m_dynamicsWorld->stepSimulation(dt, maxSimSubSteps, 1./60);
renderme();
glFlush();
glutSwapBuffers();
}
Code: Select all
void BasicDemo::initPhysics()
{
...
m_collisionConfiguration = new btDefaultCollisionConfiguration();
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
#define maxProxies 8192
btVector3 worldAabbMin(-10000,-10000,-10000);
btVector3 worldAabbMax(10000,10000,10000);
m_overlappingPairCache = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
m_solver = sol;
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_solver,m_collisionConfiguration);
m_dynamicsWorld->getDispatchInfo().m_enableSPU = true;
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
//KINEMATIC GROUND
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(30.),btScalar(1.),btScalar(30.)));
m_collisionShapes.push_back(groundShape);
btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0,-8,0));
btRigidBody* body = localCreateRigidBody(btScalar(0.),groundTransform,groundShape);
body->setCollisionFlags( body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
body->setActivationState(DISABLE_DEACTIVATION);
body->setRestitution (btScalar(0.f));
//create a few dynamic sphere rigidbodies (re-using the same sphere shape)
btCollisionShape* colShape = new btSphereShape(btScalar(2.0));
m_collisionShapes.push_back(colShape);
/// Create Dynamic Objects
btTransform startTransform;
startTransform.setIdentity();
btRigidBody* body2;
...
for (int k=0;k<ARRAY_SIZE_Y;k++)
{
for (int i=0;i<ARRAY_SIZE_X;i++)
{
for(int j = 0;j<ARRAY_SIZE_Z;j++)
{
startTransform.setOrigin(btVector3(
2.0*i + start_x,
2.0*k + start_y,
2.0*j + start_z));
body2 = localCreateRigidBody(1, startTransform,colShape);
body2->setRestitution (btScalar(0.f));
}
}
}
...
clientResetScene();
}