
The following is how I have created my collision world and added the objects to it:
Code: Select all
	bt_collision_configuration = new btDefaultCollisionConfiguration();
	bt_dispatcher = new btCollisionDispatcher(bt_collision_configuration);
	btVector3 worldAabbMin(-scene_size, -scene_size, -scene_size);
	btVector3 worldAabbMax(scene_size, scene_size, scene_size);
	bt_broadphase = new bt32BitAxisSweep3(worldAabbMin, worldAabbMax, max_objects, 0, true);
	bt_collision_world = new btCollisionWorld(bt_dispatcher, bt_broadphase, bt_collision_configuration);
	if (debug) {
		bt_collision_world->setDebugDrawer(&collision_debug_drawer);
	}
	btCollisionObject* sphere = new btCollisionObject();
	sphere->getWorldTransform().setOrigin(btVector3((btScalar)-2, (btScalar)2, (btScalar)4));
	btSphereShape* sphere_shape = new btSphereShape(1);
	sphere->setCollisionShape(sphere_shape);
	bt_collision_world->addCollisionObject(sphere);
	btCollisionObject* box = new btCollisionObject();
	box->getWorldTransform().setOrigin(btVector3((btScalar)2, (btScalar)2, (btScalar)4));
	btBoxShape* box_shape = new btBoxShape(btVector3((btScalar)1, (btScalar)1, (btScalar)1));
	box->setCollisionShape(box_shape);
	bt_collision_world->addCollisionObject(box);
Code: Select all
	void CollisionDebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& color) {
	//std::cout << to.x() << "," << to.y() << "," << to.z() << "\n";
	unsigned int VBO2, VAO2;
	GLfloat points[6];
	points[0] = from.getX();
	points[1] = from.getY();
	points[2] = from.getZ();
	points[3] = to.getX();
	points[4] = to.getY();
	points[5] = to.getZ();
	glGenVertexArrays(1, &VAO2);
	glGenBuffers(1, &VBO2);
	glBindVertexArray(VAO2);
	glBindBuffer(GL_ARRAY_BUFFER, VBO2);
	glBufferData(GL_ARRAY_BUFFER, sizeof(points), &points, GL_STATIC_DRAW);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (void*)0);
	glEnableVertexAttribArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glDrawArrays(GL_LINES, 0, 2);
	glBindVertexArray(0);
	glDeleteBuffers(1, &VBO2);
	glDeleteVertexArrays(1, &VAO2);
}
