I am very new to bullet, and I want to use bullet for a kart game (see http://supertuxkart.berlios.de). So first an apology for asking stupid questions.
I've started by using a simple boxe for each kart, and without any collision detection (e.g. track) am just letting them fall down (a very simple first test ). I expected that only the z (gravity) coordinate would change. But I see that the other coordinates are changing as well, e.g. :
(format body 0: <x> <y> <z> dt <delta t>)
Code: Select all
body 0: 1.500000 -1.500000 -0.018948 dt 0.000000
body 0: 1.500000 -1.500000 -0.018948 dt 0.014394
body 0: 1.554279 -1.449197 -0.238790 dt 0.006532
body 0: 1.554279 -1.449197 -0.238790 dt 0.006405
body 0: 1.608559 -1.398393 -0.461356 dt 0.006611
body 0: 1.608559 -1.398393 -0.461356 dt 0.006349
If I set the kart start coordinates to 0/0/0, everything works as expected - x/y remain (nearly) 0 (rounding errors only), and the box is falling. So I guess I must be forgetting to reset the velocity(?) somewhere, or some functions are not doing what I expect them to do.
Secondly, if I use a 2nd kart (starting at -1.500000 -3.000000 -0.018948 ), this kart will first raise before starting to fall, and it is showing the same linear behaviour in the x/y coordinates but in the opposite direction compared with the kart above, e.g.:
Code: Select all
body 1: -1.500000 -3.000000 -0.018948 dt 0.000000
body 1: -1.500000 -3.000000 -0.018948 dt 0.014394
body 1: -1.554279 -3.050803 0.195446 dt 0.006532
body 1: -1.554279 -3.050803 0.195446 dt 0.006405
body 1: -1.608559 -3.101606 0.407115 dt 0.006611
Cheers,
Joerg
This is all the code using the bullet physics, nothing else (bullet related) happens in between.
World creation:
Code: Select all
m_dynamics_world = new btDiscreteDynamicsWorld();
m_dynamics_world->setGravity(btVector3(0.0f, 0.0f, -gravity));
Code: Select all
//x_* and y* are the minimum/maximum coordinates of the kart model
// resuling in a size of approx 3.5 x 2.2 (x/y direction)
btCollisionShape *box = new btBoxShape(btVector3(x_max-x_min,
y_max-y_min,
1.0f) );
sgCoord *pos=kart->getCoord();
btTransform trans;
trans.setIdentity();
trans.setOrigin(btVector3(pos->xyz[0], pos->xyz[1], pos->xyz[2]));
// it works as expected if I use:
// trans.setOrigin(btVector3(0.0f,0.0f,0.0f));
float mass=kart->getMass();
btVector3 inertia;
box->calculateLocalInertia(mass, inertia);
btRigidBody* kart_body = new btRigidBody(mass, trans, box, inertia);
kart_body->m_worldTransform.setRotation(btQuaternion(0,0,0,1));
kart_body->setLinearVelocity(btVector3(0.0f,0.0f,0.0f));
kart_body->setAngularVelocity(btVector3(0,0,0));
m_dynamics_world->addRigidBody(kart_body);
Code: Select all
int max_sim_sub_steps = 1;
int numSimSteps = m_dynamics_world->stepSimulation(dt,max_sim_sub_steps);
int numObjects = m_dynamics_world->getNumCollisionObjects();
for(int i=0; i<numObjects; i++)
{
btCollisionObject *obj = m_dynamics_world->getCollisionObjectArray()[i];
btRigidBody* body = btRigidBody::upcast(obj);
if(!body) continue;
const btVector3 &pos=body->getCenterOfMassPosition();
printf("body %d: %f %f %f dt %f\n",i, pos.x(), pos.y(), pos.z(),dt);
}