Adding Bullet physics to a graphics application
Before we conclude the business of this chapter, let's touch on one more topic, which is not a 3D rendering matter but links very closely to our 3D scene implementation. This recipe shows how to animate individual visual objects in our scene graph by using a rigid-body physics simulation library, Bullet
(https://github.com/bulletphysics/bullet3).
Getting ready
To compile the Bullet
library, we use a custom CMakeLists.txt
file, so it is useful to recall the general CMake workflow for third-party libraries covered in Chapter 2, Using Essential Libraries.
The demo application for this recipe can be found in the Chapter9/VK01_Physics
folder.
How to do it...
- To simulate a collection of rigid bodies, we implement the
Physics
class, which calls the appropriatelibBullet
methods to create, manage, and update physical objects:struct Physics { Â Â Physics() Â Â :Â collisionDispatcher(&collisionConfiguration...