Now, I am not a native c++ programmer (tried everything for a while before c/c++) so my code might have errors that it probably shouldn't.
I tried the http://bulletphysics.org/mediawiki-1.5. ... ello_World example in regards to setting up a plane and a sphere dropping on it, to test out some settings, but instead of using a fixed loop, I inserted it into a simple opengl program, which renders only a line for the plane and the dropping sphere.
My code to initialize bullet is:
Code: Select all
btBroadphaseInterface* broadphase = new btDbvtBroadphase();
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-10,0));
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
btRigidBody::btRigidBodyConstructionInfo
groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);
btCollisionShape* fallShape = new btSphereShape(0.10f);
btDefaultMotionState* fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,50,0)));
btScalar mass = 0.10f;
btVector3 fallInertia(0,0,0);
fallShape->calculateLocalInertia(mass,fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia);
btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI);
dynamicsWorld->addRigidBody(fallRigidBody);
dynamicsWorld->getDispatchInfo().m_allowedCcdPenetration = 0.0001f;
And the code inside my loop is:
Code: Select all
float dt = (btScalar)m_clock.getTimeMicroseconds() * 0.000001f;
m_clock.reset();
dynamicsWorld->stepSimulation(dt);
btTransform trans;
fallRigidBody->getMotionState()->getWorldTransform(trans);
glBegin(GL_LINES); //Draw our plane
glVertex3f(-1,0,0);
glVertex3f(1,0,0);
glEnd();
drawSphere(0.10f, 30, 30, trans.getOrigin().getX(), trans.getOrigin().getY(), trans.getOrigin().getZ());
Code: Select all
void drawSphere(btScalar radius, int lats, int longs, btScalar _x, btScalar _y, btScalar _z)
I compiled bullet and the sample in both mingw32 and visual studio 2010 with the same effect.