Dear community,

I'm currently programming a 3D game in pure C++ with OpenGL, GLM, ASSIMP, SFML & BulletPhysics.

But now, I'm at a point, where I'm done with it, 'cause I couldn't get the problem or find something on the internet, which can lead into the direction of a fix.

I've got a problem with updating my meshs model matrix with the world matrix, getting from the btMotionState of a btRigidBody, to render it via shader.

The shader computes the vertex location like

gl_Position = projection_mat4 * view_mat4 * model_mat4 * vec4(position, 1.0);

Where projection is computed by glm::perspective(...), view by glm::lookAt(...) and model by the physics system, see below.

So far, I'm creating the whole physics world in a class called "PhysicsManager".

It's a test and so it **creates the whole bullet physics system** like that:

m_broadphase = new btDbvtBroadphase(); m_collisionConfiguration = new btDefaultCollisionConfiguration(); m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); btGImpactCollisionAlgorithm::registerAlgorithm(m_dispatcher); m_solver = new btSequentialImpulseConstraintSolver(); m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration); m_dynamicsWorld->setGravity(btVector3(0.0f, -9.81f, 0.0f)); // Floor m_groundShape = new btStaticPlaneShape(btVector3(0, 1, 0), 1); m_groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, -1))); btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, m_groundMotionState, m_groundShape, btVector3(0, 0, 0)); m_groundRigidBody = new btRigidBody(groundRigidBodyCI); m_dynamicsWorld->addRigidBody(m_groundRigidBody); // Model as a sphere in BulletPhysics m_fallShape = new btSphereShape(1); m_fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(8, 50, 8))); btScalar mass = 2; btVector3 fallInertia(0, 0, 0); m_fallShape->calculateLocalInertia(mass, fallInertia); btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass, m_fallMotionState, m_fallShape, fallInertia); m_fallRigidBody = new btRigidBody(fallRigidBodyCI); m_dynamicsWorld->addRigidBody(m_fallRigidBody); // GLDebugDrawer from the demos of the Bullet 3.X github page glDebugDrawer = GLDebugDrawer(); glDebugDrawer.setDebugMode(btIDebugDraw::DBG_DrawAabb | btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawConstraints | btIDebugDraw::DBG_DrawConstraintLimits | btIDebugDraw::DBG_DrawNormals); m_dynamicsWorld->setDebugDrawer(&glDebugDrawer);

And I'm **updating the world** each frame with

m_dynamicsWorld->stepSimulation(1.0f / 60.0f, 10);

After that, I'm **updating the meshs model matrix** with

btTransform trans; m_game->m_physics->m_fallRigidBody->getMotionState()->getWorldTransform(trans); trans.getOpenGLMatrix(glm::value_ptr(m_medikits[0].m_model));

where "m_model" is a glm::mat4 initialised as "m_model = glm::mat4()".

Then **rendering** is done via

glBindVertexArray(mesh->vao); glBindTexture(GL_TEXTURE_2D, mesh->tex); GLuint uniform_model = glGetUniformLocation(p_shader, "model"); glUniformMatrix4fv(uniform_model, 1, GL_FALSE, glm::value_ptr(p_objects->at(i).m_model)); glDrawArrays(GL_TRIANGLES, 0, mesh->size); glBindVertexArray(0); glBindTexture(GL_TEXTURE_2D, 0);

So I bind all the stuff of the 3D mesh, draw it and unbind it.

**Problem is:**

Why is my rendering not aligned with the physically computed bounding boxes?

(I mean not perfectly aligned like origin/center of mass but not anywhere near the collision box?)

Can anyone give me a hint or something like that?

Here's a picture of what I mean:

Cheers,

NightDreamer