working code
Code: Select all
//...
//create World
btDefaultCollisionConfiguration* config = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(config);
btBroadphaseInterface* broadphase = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver();
btDiscreteDynamicsWorld* world = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, config);
world->setGravity(btVector3(0,-10,0));
//create Object
btCollisionShape* shape = new btBoxShape(btVector3(1,3,1));
btTransform transform;
transform.setIdentity();
btVector3 localInertia(0,0,0);
shape->calculateLocalInertia(40.0f, localInertia);
btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(50,50,50)));
btRigidBody* body = new btRigidBody( btRigidBody::btRigidBodyConstructionInfo(40.0f, motionState,shape, localInertia));
world->addRigidBody(body);
btVector3 position = body->getCenterOfMassPosition();
std::cout << position.getX() << " " << position.getY() << " " << position.getZ() << std::endl;
for(int i = 0; i < 100; ++i)
{
world->stepSimulation(6,10);
position = body->getCenterOfMassPosition();
std::cout << position.getX() << " " << position.getY() << " " << position.getZ() << std::endl;
}
//...
Code: Select all
class World
{
btDefaultCollisionConfiguration* m_Config;
btCollisionDispatcher* m_Dispatcher;
btBroadphaseInterface* m_Interface;
btSequentialImpulseConstraintSolver* m_Solver;
btDiscreteDynamicsWorld* m_World;
public:
World()
{
m_Config = NULL;
m_Dispatcher = NULL;
m_Interface = NULL;
m_Solver = NULL;
m_World = NULL;
}
void init()
{
m_Config = new btDefaultCollisionConfiguration();
m_Dispatcher = new btCollisionDispatcher(m_Config);
m_Interface = new btDbvtBroadphase();
m_Solver = new btSequentialImpulseConstraintSolver();
m_World = new btDiscreteDynamicsWorld(m_Dispatcher, m_Interface, m_Solver, m_Config);
m_World->setGravity(btVector3(0,-10,0));
}
~World()
{
delete m_Config;
delete m_Dispatcher;
delete m_Solver;
delete m_Interface;
delete m_World;
}
void addObject(btRigidBody* body)
{
m_World->addRigidBody(body);
}
void update()
{
m_World->stepSimulation(20,10);
}
};
Can someone tell me where the problem is and how i can fix the problem?