# Physics Simulations

## Overview

In my fifth semester I attended the Game Physics lecture, which teaches the basics of physics simulations such as mass-spring systems, rigidbodies and SPH. In this lecture there was an optional exercise part, that allowed us to implement some of those simulations ourselves. Because the course was very interesting and implementing the simulations from the lecture helps understanding the concepts, a few colleagues of mine and I took on the challenge.

The team consisted of three members and the workload was split up for each simulation:

## The Simulations

### Mass Spring System

The first task was to create a mass spring system. These are commonly used for simulations such as cloth and hair, so we simulated a simple system where mass points in a grid were randomly fixed. This produced a very interesting simulation, you can see it in action below. It is possible to drag the mouse to interact with it, springs are also color-coded and show the spring force in a nice way.

### Rigidbody (& collision)

The second simulation was about rigidbody force and collision, which is used for pretty much every solid object in physics engines. This simulation was overall the thoughest exercise, since there are a lot of calculations that have to be done in exactly the right order. We got this exercise to work just hours before the deadline and it certainly is not completely correct. The collision detection is somewhat incorrect and the collision response often a bit extreme. This could be tweaked with more damping, but there was no time to improve it further. The results here are not as pretty to look at, but you can still take a look below.

### Performant Collision Detection

The goal in this exercise was to build a performant collision detection algorithm for simple spheres. There are many ways to do this, but finding a good approach is crucial to a performant physics engine. We implemented a naive approach, a grid-based one and tried our luck at K/D trees. It was really interesting to see how much of a difference acceleration structures can make. In our tests the difference was up to 100x for large scenes, while the simulation remained stable and looked the same. You can also see the simulations and the test results below.

### Smoothe-Particle Hydrodynamics (SPH)

SPH simulations are commonly used for liquids and gases, but other things can be simulated with it as well. This last exercise was an extension to the previous one, the goal was to implement a functioning SPH system based on the acceleration structures we had already implemented beforehand. For this exercise I implemented a custom and improved system which can be found on the branch SPH_New. This is a more accurate and stable implementation and closer to what would be used in real applications. Below is a video of this system in action.

## Conclusion

The exercises where overall very interesting and gave me a good understanding for the algorithms and problems in physics simulations. The results for each task where almost all good and it was a good C++ finger practice. There are certainly some things that could be improved upon, such as fixing the rigidbody simulation, implementing K/D trees properly and using spacial hashing for the SPH system, but time constraints prevented us from doing so.

The project is available on GitHub and works with VS 2019, although there might be some tweaks needed for it to run on specific setups.

Data protection
I, Alexander Epple (Place of residence: Germany), process personal data to operate this website only to the extent technically necessary. All details in my privacy policy.