Real-time 3D Physics Engine

Go Back
Github

In order to increase my familiarity with game physics. I decided to create a custom 3D physics engine. This physics engine was implemented in an existing game engine called the Legion Engine. The following is a description of the notable features I implemented:

1. Collision Detection Middlephase and Narrowphase:

After doing research on known collision detection techniques, I was presented with the choice of using either the Gilbert-Johnson-Keerthi or the Seperating Axis Test. The main reason why I ended up choosing SAT is because of sources mentioning it to be more portable to the GPU. Although I did not intend on integrating compute shaders, I wanted to leave the potential to do so open.


Another reason why I chose to use the SAT is because I was made aware of a GDC talk titled “Physics for Game Programmers:The Separating Axis Test between Convex Polyhedra”. It talks about how edge checks for the separating axis test can be optimized by checking if it creates a valid separating axis. We are able to tell its valid if the combination of the 2 edges create a minkowski face. An edge check between 2 cube colliders with 24 edges using the brute force method takes on average 0.350 ms. The optimized version only takes 0.058ms on average. The test was done using an Intel Core i7-7700 HQ.


In order to get the contact points of the collision, the Sutherland-Hodgman Mesh Clipping algorithm was used. In my implementation of this algorithm, in order to create numerically robust contacts, the clipping planes are considered to be 'thick' this means that there are cases where the edge being clipped is considered to be on the clipping plane. In this case, the edge is not clipped.

2. Collision Resolution

For collision resolution, I decided that I would implement sequential impulses with feature-id warm starting. The reason behind choosing this solver is mostly due to the availability of resources for implementation and explanation of this particular collision solver. Another reason is due to the possibility of extending sequential impulses solver to solve the large mass ratio using the featherstone algorithm.


As shown in the video, the physics engine is able to reach comparable stability with unity's implementation of PhysX3.4. In order to ensure the correctness of the test, the parameters of both physics engines are matched as close as possible. This includes parameters such as the number of solver iterations, the contact offset, the mass of the objects, etc.

3. Convex Hull Generation

In order to support collision detection for complex geometry I decided to implement the quickhull algorithm. As seen in the video the implementation was able to robustly handle meshes with varying shapes and complexity.