3d Realtime Physic Simulation

A library for real time 3D particles and rigid bodies simulation in OpenGL, created as part of university coursework. In the simulation, particles and bodies respond to forces and are simulated using various integration methodsn.

This coursework project is implemented in C++/OpenGL and consists of a physics engine compiled in a DLL. The individual demos visible in the videos use the engine to perform the simulation, but they differ in the setup of the scene and in the functionalities of the engine they use.

Flags can be set on the physics engine to activate or deactivate some functionalities, like broad phase collision detection or the drawing of the bounding boxes. The individual demos doesn't do anything more than setting these flags accordingly to the goal of the specific demo and laying out the planes and the particles or cubes for the scene.

I wrote two versions of this engine. The first version was written with an object-oriented approach. A base class was used as a superclass for planes, particles and cubes and forces were also implemented as object with a class hierarchy. The overall idea was to delegate to the single instance the execution of all the integration, drawing and update. Custom made list (with some handy extra methods) were also used extensively to have a cleaner code. In this implementation, the mathematical library "vmath" has been used (and extended to implement the inversion operation on 3x3 matrix, only available on 4x4 matrix).

This design decision led to a good structured code, with a clean class structure, but the performance was not acceptable and there were some glitches with the plane response. In a second phase, the entire engine has been rewritten from scratch with a different approach. The mathematical library used is "WildMagic4". In this second version I decided to go back to a C style approach, with static functions acting on structs and arrays with a fixed size. The code is a bit more convoluted , but the performance have increased, for the particle simulation, by some ten times, and by some three times for the object simulation.

Main features

  • Euler, Midpoint and RK4 integration methods
  • Full 3D body implementation with inertial tensors
  • Particle and rigid body simulation
  • Visualisation of broad-phase (AABB with sweep and prune) body-to-body and narrow-phase body-to-plane collision detection
  • Body-to-plane collision response

Comments