So I downloaded bullet today because I've heard nothing but good things about it. Unfortunately, after reading a quick tutorial, something went terribly wrong XD. So I created plane to serve as the ground and then added a sphere above it and let it fall onto the plane. It hits the ground like I'd expect and then just starts infinitely accelerating towards the negative x and keeping a constant z and y. Here is my code:
Code: Select all
physicsWorld::physicsWorld()
{
//create all the world components
bulletConfiguration = new btDefaultCollisionConfiguration();
bulletDispatcher = new btCollisionDispatcher(bulletConfiguration);
bulletBroadPhaseInterface = new btDbvtBroadphase();
bulletSolver = new btSequentialImpulseConstraintSolver();
//create the world
bulletWorld = new btDiscreteDynamicsWorld(bulletDispatcher,bulletBroadPhaseInterface,bulletSolver,bulletConfiguration);
bulletWorld->setGravity(btVector3(0,-10,0));
//here are some temp gemoetries
btTransform t;
t.setIdentity();
t.setOrigin(btVector3(0,0,0));
btStaticPlaneShape* plane = new btStaticPlaneShape(btVector3(0,1,0),0.0);
btMotionState* motionStatePlane = new btDefaultMotionState(t);
btRigidBody::btRigidBodyConstructionInfo info(0.0,motionStatePlane,plane);
btRigidBody* planeBody = new btRigidBody(info);
rigidBodies.push_back(planeBody);
bulletWorld->addRigidBody(planeBody);
addRigidSpehere(1, glm::vec3(0,3,0));
}
physicsWorld::~physicsWorld()
{
//delete everything
delete bulletWorld;
delete bulletConfiguration;
delete bulletDispatcher;
delete bulletBroadPhaseInterface;
delete bulletSolver;
//delete all the rigid bodies
for (int i = 0; i < rigidBodies.size(); i ++)
{
delete rigidBodies[i];
}
}
void physicsWorld::update(double time)
{
bulletWorld->stepSimulation(time);
}
btRigidBody* physicsWorld::addRigidSpehere(float rad, glm::vec3 position)
{
btTransform t;
t.setIdentity();
t.setOrigin(btVector3(position.x,position.y,position.z));
btSphereShape* sphere = new btSphereShape(rad);
//calculate inertia
btVector3 inertia(0.0,0.0,0.0);
sphere->calculateLocalInertia(1.0, inertia);
btMotionState* motionState = new btDefaultMotionState(t);
btRigidBody::btRigidBodyConstructionInfo info(1.0,motionState,sphere,inertia);
btRigidBody* sphereBody = new btRigidBody(info);
rigidBodies.push_back(sphereBody);
bulletWorld->addRigidBody(sphereBody);
return sphereBody;
}
Code: Select all
SceneRenderer.currentScene->PhysicsWorld->update(1.0/60.0);