Real time 3D particles and rigid bodies simulation in OpenGL. Particles and bodies are affected by forces; various integration methods used in the simulation.
The project is implemented in C++/OpenGL and is structured in a main 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.
Some flag 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 code for 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 speed was not acceptable and there were some glitches with the plane response. So 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 definitely less clean than the first version, but the performance have increased, for the particle simulation, by some ten times, and by some three times for the object simulation. Unfortunately, the collision response is still not as stable as expected but the deadline for this project prevented me from putting more effort into it.
- 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