We create a global vector to store all of our rigid bodies (boxes).
The AddRigidBodies function
The AddRigidBodies function is changed to the following.
The only difference here from the previous SimpleBox demo is that now we reuse the box shape to create several rigid bodies. We alter their positions by using the loop variable. We add the rigid body to the global vector as shown in the code snippet below.
The ShutdownHavok function
This function is changed to the following.
We simply run a loop to remove reference of each rigidbody one by one.
The OnRender function
The only difference in this function is that instead of one box we run a loop to access the ith box rigid body and pass it to DrawBox function as follows.
That's all, the accompanying tutorial code should give you a number of boxes falling under gravity on the grid plane colliding with each other as shown in the following figure.
You can get the full source code from my github repo https://github.com/mmmovania/HavokPhysicsTutorials
Left click to rotate
Middle click to zoom
Right click to pan
In the next tutorial, I will show you how to pick a rigid body.