Networked 2D Physics Simulation


One of our assignments for the MEng course this year was a 2D ball physics simulation written in C++. We were allowed to use any graphics API we wanted, so I opted for OpenGL 4 as I fancied getting some experience with the latest version.

This coursework offered some different challenges from the golf ball physics simulation I developed last year because there was a focus on realistic collision detection and response between multiple objects at the same time.

The simulation also had to be networked using the Berkeley sockets library (C sockets). The server would perform all physics calculations and send the latest object states over a network to each of its clients. The clients would render the scene and send user input data back to the server to be used in its calculations. This meant you could have multiple people interacting with the simulation across many computers simultaneously.

The fun part of the project came near the end when I added a rope into the simulation. It looks quite nice from the video, but as you can see an energy gain in one of the springs will sometimes lead to the rope spiraling out of control as the extra force is applied to the adjacent springs.

You’ll notice some weird behavior towards the end of the video: balls falling through the enclosure, rope self-destructing, terrible collision detection/response etc. This is due to me intentionally lowering the number of physics steps that happen per second. This leads to better performance but less realism, so the right balance must be struck when deciding your physics step in a real-time application.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s