SimpleSimulationEngine
minimalistic engine for physical simulations, numerical math and games in C++ ( python, lua ) using SDL2 and OpenGL for visualization
Install / Use
/learn @ProkopHapala/SimpleSimulationEngineREADME
Simple Simulation Engine
a minimalistic engine for:
- Physical simulations
- Numerical math
- Game development
- Computer graphics
- Educational purposes
Table Of Contents
<!-- TOC --> <!-- /TOC -->Structure and Dependecies
- Computational core is written in C/C++11. It should have no dependencies on external libraries. Even C++STL is avoided where possible. Attempt is made to optimize simultanously run-time speed, code length, compilation time, and interal interdependece of modules. In that respect especially tradeoffs for using templates and class hierarchies are considered.
- C/C++ part is compiled using CMake 2.8 and tested with gcc 5.4.0 on Ubunt 16.04. Code::Blocks project is generated by
cmake .. -G "CodeBlocks - Unix Makefiles". There are several CMake projects for different parts which differ in dependencies - Standalone apps, games and demos use SDL2 and OpenGL 1.2 and 4.0 for Graphical user interface. Some other dependencies (e.g. SDL2-net, SDL2-image, SDL2-ttf) may be added to particular build target but are not required globaly.
- There is stand allone set GPU accelerated simulations using OpenCL
- Some apps use embeded Lua3.2 for scripting, but it is not globally required.
- Python 2.7 + numpy + matplotlib is used to make convenient science/engineering packeges partialy wrappaing the C/C++ core libraries.
- In addition there are some documents using iPython (Jupyter) and javascript+WebGL for rendering interactive 3D graphics and editors of glsl shaders on web. These are independent on the rest.
Compilation
- tested on Ubunu 16.04 64bit)
quickstart
- make sure you have installed
gcc >=5.4.0,CMake >2.8,libglew-dev,SDL2-dev - got to
cpp/Builds/sketches_SDL/create subdirectoryBuild - from
cpp/Builds/sketches_SDL/Buildgenerate makefiles bycmake .. -G "CodeBlocks - Unix Makefiles" - in the same directory compile the project
make. The compiled binaris are stored incpp/Build
remarks
- you may also load Code::Blocks project
cpp/Builds/sketches_SDL/SimpleSimulationEngine.cbpand compile particular build target from Code::Blocks - If
cmakeormakefails due to some dependencies, you may try compile just part of the project (e.g.cpp/Build/libs) which has less dependencies - you may also remove problematic build targets by commenting out particular parts of
CMakeFile.txt
optional
- If you were able to compile
sketches_SDLyou may try compile applications and games incpp/Builds/apps/or the whole project in the same way just incpp/Builds/all/(you will needliblua5.2-devandlibtolua5.2-dev) - You may try compile OpenCL demos in
cpp/Build/sketches_OCLin the same way. This will require properly installed GPU drivers and opencl libraris. These are platform dependent. Personally I tested withnvidia-opencl-dev.- Note: be very carefull when installing GPU drivers on linux, ou can easily brak the system (I did 3 times). In my case
nvidia-opencl-devinstalled dependecieslibcuda-378 nvidia-378 nvidia-opencl-icd-378 nvidia-prime nvidia-settings opencl-headers. I also addednvidia-modprobe. When you break your system this make help:
there are many guides for installing GPU drivers on linux. I found particularily helpfull and working this onesudo apt-get autoremove --purge nvidia-* sudo stop lightdm sudo apt-get install xserver-xorg-video-nouveau
- Note: be very carefull when installing GPU drivers on linux, ou can easily brak the system (I did 3 times). In my case
Content
<font color="green"> This is work in progress. Often particular modules of the engine are functional, but they are not put together to build an unified system and work together. </font>
C++ part
-
- 2d vector, 3d vector, 3x3 matrix, 4x4 matrix, Quaternions
- Fast math rutines with approximations of some functions ( e.g. goniometry, Error function ... )
- Functions with derivatives ( like tresholds and sigmoides, and Lorenzieans etc. )
- Composing of complicated 1D,2D,3D functions from simple primitives with analytic gradients
- Splines in 1D, 2D 3D, e.g. cubic hermite spline <font color="green" size=2> (other splines needs to be systematized) </font>
- [Simplex noise] (cpp/common/math/Noise.h)
- Basic linear algebra ( matrix multiplication, transpose, GaussJordan solver, Biconjugate gradinet iterative solver, Fitting, Jacobi matrix diagonalization), and N-dimensional vectors
- Minimalistic Fourier transform, with FFT for $2^N$ elemetns
-
Math solvers
- Brent line search
- Stochastic optimization
- iterative non-linear gradient based optimization using FIRE (faster and more robust CG, comparable and sometimes better than BFGS)
- Variable step ODE integrator by Runge–Kutta–Fehlberg
-
Computational Geometry
- Basic 2d and 3d shapes computational geometry, ray tracing, Covex polygons, polygon Mesh and regular polyhedra
-
Spatial datastructures - <font color="green" size=2> This needs cleanup, there is too many duplicite methods/versions. Especially, Rulers should be splited from data. </font>
- Various methos for acceleration of local interactions and nearest neighbor search e.g. HashMap, nD BoundigSphere hierarchy, and grids.
- Various grids (trinagular, rectangular, cubic, and triclinc )
- Some maps suport raymarching/rasterization e.g. trinagular and cubic
-
Physical simulations
- Rigid-Body dynamics in 2D and 3D - with application in RigidBody molecular dynamics, Flight dynamics and vehicle on tarrain, and Sailing
- SoftBody dynamics with Truss simulation (e.g. for something like BridgeBuilder)
- Molecular mechanics used there
- simulation of hydraulic errosion for terrain generation
-
GUI and interfaces
-
Graphics
- OpenGL 1.2/2
- OpenGL 3+
- Examples of Rendering meshes, rendering to texture, instances, bilboards
- ScreenSpace ambient occlusion
- Ray-Traced analytic primitives e.g. Spherical atoms
- Ray-Marching of analytical functions e.g. molecular orbitals.
- <font color="green" size=2>TODO: (in-shader Constructive solid geometry CGS)</font>
- Terrain rendering from heightmap texture with logaritmic depth buffer for large scenes
- Angularly sensitive bilboards (impostors) for rendering Vegetation and clouds
-
Apps and Games
- Molecular editors with Rigid Body Molecular dynamics (coarse grained=>faster, no need for intramoleculer forcefiel) with python interface, and normal Soft Body Molecular mechanics
- 3D subsonic aircraft combat simulator
- 2D Sail-ships simulator with multiplayer and battleship simulator
- [Land-Combat tactical simulator](cp
