How to integrate Bullet Physics in to Directx
Hi, Can anyone please explain how to properly integrate Bullet physics engine with both Directx 11 or 12 using simple example ? Need step by step procedure. Thank you.
Sign in to comment
Chosen Answer
When you develop an application, you'll usually want to split it up into functional parts. Integrating a physics engine in your game should not have anything to do with whatever graphics API you are using. The physics engine is usually used when you update your game logic. The graphics API you use, such as direct3d 11 or 12, is used when you render your scene. Rendering your scene is only reading the state of your application, set when you updated the game logic. For example, you have a vertex buffer that gets updated with the physics engine. You will have one copy of the vertex buffer in memory on the CPU side, such as a vertex array. You update that vertex array with the physics engine, then when the time comes to render your frame, your graphics api will copy that vertex buffer (or the parts that have changed) to the GPU memory, and render it. I've never personally used the bullet engine, so i can't give you anything more than broad advice. A lot of times for animation, when vertices are changing often, it would be a better idea to do the actual animation in the vertex shader so that you are not constantly uploading new vertex buffers every frame. The vertex buffer was probably not the best example. A better example would be collision detection, since that' a pretty big feature in physics engines. You could keep a local copy of the vertex buffer around on the CPU side if you were doing triangle to triangle collision, or you would have a bounding box/sphere for a broad representation of your model, which you would pass to the physics engine, along with velocities and directions and other models that it might collide with. All this can be done separately from directx 11 or 12
Hi I worked on bullet physics with directx-11 two years back, and think can provide some help on the subject. So I would say the most difficult part is setting up Bullet Physics with your project (building all the dlls + including source files (which files!!)), I loathe this stage of development **sighs**. But working with bullet physics is quite convenient when it comes to rendering. // function to get OpenGL matrix (yeah, not there yet) float m[16]; // basically stores the physics body's transform as matrix physicsBody->getWorldTransform().getOpenGLMatrix(m); // convert to direct-x matrix (column major) XMFLOAT4X4 matrix; matrix._11 = m[0]; matrix._12 = m[4]; matrix._13 = m[8]; matrix._14 = m[12]; matrix._21 = m[1]; matrix._22 = m[5]; matrix._23 = m[9]; matrix._24 = m[13]; matrix._31 = m[2]; matrix._32 = m[6]; matrix._33 = m[10]; matrix._34 = m[14]; matrix._41 = m[3]; matrix._42 = m[7]; matrix._43 = m[11]; matrix._44 = m[15]; // now update this matrix is the mesh's model matrix and will move with physics simulation And regarding how to use bullet physics, you can easily find decent tutorial online to get you started. A little demo I created experimenting with bullet vehicle physics: https://www.youtube.com/watch?v=B4I53jf_ZEI&list=PLV7vGiRv15kqsna7BgKN4cPcMWhYS6BUh&index=4