Я создаю куб (коробку в пуле) вот так
Код: Выделить всё
btRigidBody* createBox(float x, float y, float z, float mass) {
btTransform t;
t.setIdentity();
t.setOrigin(btVector3(x, y, z));
btBoxShape* box = new btBoxShape(btVector3(0.5, 0.5, 0.5));
btMotionState* motion = new btDefaultMotionState(t);
btVector3 inertia(0, 0, 0);
if (mass != 0.0) {
box->calculateLocalInertia(mass, inertia);
}
btRigidBody::btRigidBodyConstructionInfo rbinfo(mass, motion, box);
btRigidBody* rigidBody = new btRigidBody(rbinfo);
world->addRigidBody(rigidBody);
bodies.push_back(rigidBody);
return rigidBody;
}
Код: Выделить всё
bodies
также я создаю плоскость
Код: Выделить всё
btTransform t;
t.setIdentity();
t.setOrigin(btVector3(0.0, 0.0, 0.0));
btStaticPlaneShape* plane = new btStaticPlaneShape(btVector3(0, 1, 0), 0);
btMotionState* motion = new btDefaultMotionState(t);
btRigidBody::btRigidBodyConstructionInfo rbinfo(0.0, motion, plane);
btRigidBody* rigidBody = new btRigidBody(rbinfo);
world->addRigidBody(rigidBody);
я обновляю мир вот так
Код: Выделить всё
static auto start = std::chrono::high_resolution_clock::now();
float iTime = std::chrono::duration(std::chrono::high_resolution_clock::now() - start).count();
world->stepSimulation(iTime);
Код: Выделить всё
void getBoxMat(btRigidBody* body, glm::mat4& rmat) {
btTransform t;
if (body == nullptr) return;
if (body->getMotionState() == nullptr) return;
body->getMotionState()->getWorldTransform(t);
float mat[16];
t.getOpenGLMatrix(mat);
rmat = glm::make_mat4(mat);
rmat[1][1] *= -1;
}
Подробнее здесь: https://stackoverflow.com/questions/783 ... ics-engine