Physics System Update
Now that we have a way to generate collision manifolds for colliding objects and a way to apply impulses to rigidbodies, we must make some modifications to the physics system to actually use these features. Most of this work will consist of modifying our physics loop, but we also need to add a few class variables.
As we are applying gravity to objects resting on each other, we might experience sinking. Sinking simply means that objects that should rest on top of each other sink through each other. We can fix this using Linear Projection. To perform linear projection, when a collision has happened, we will move both the objects a little along the collision normal. This slight adjustment to position will fix sinking problems for now.
We will update our physics loop to perform the following steps:
- Find and store pairs of colliding rigidbodies
- Accumulate forces acting on the rigidbodies
- Apply impulses to resolve collisions
- Update the position of every rigidbody
- Correct sinking...