A lightweight 2D collision detection and physics library written in C.
WARNING: This library is in an early alpha stage, use it at your own risk.
Documentation — Examples — Prerequisites
Features
NOTE: Since this project was made for me to learn how a physics engine works, I am planning to add only the most basic features.
- Broad-phase collision detection with spatial hashing algorithm
- Narrow-phase collision detection with SAT (Separating Axis Theorem)
- 'Sequential Impulse' iterative constraint solver
- Semi-implicit (symplectic) Euler integrator
- Support for collision event callbacks
Prerequisites
- GCC version 9.4.0+
- GNU Make version 4.1+
- Git version 2.17.1+
$ sudo apt install build-essential git
Optional
Make sure you have installed raylib 4.0.0+ to compile all examples.
Building
This project uses GNU Make as the build system.
$ git clone https://github.com/c-krit/ferox
$ cd ferox
$ make
You can also build this library as standalone-mode to avoid raylib.h
header inclusion and functions that depend on raylib:
$ make BUILD=STANDALONE
Compiling into WebAssembly
Compiling for the Web requires installation of the Emscripten SDK.
$ git clone https://github.com/emscripten-core/emsdk && cd emsdk
$ ./emsdk install latest
$ ./emsdk activate latest
$ source ./emsdk_env.sh
After setting up the environment variables for Emscripten SDK, do:
$ make PLATFORM=WEB
Cross-compiling for Windows
You may need to recompile raylib for Windows before building this library.
$ git clone https://github.com/raysan5/raylib && cd raylib/src
$ make -j`nproc` CC=x86_64-w64-mingw32-gcc AR=x86_64-w64-mingw32-ar OS=Windows_NT
Make sure to set the value of RAYLIB_PATH
variable to cross-compile for Windows:
$ make PLATFORM=WINDOWS RAYLIB_PATH=../raylib
References
- Apple Inc. (2021), SKPhysicsBody | Apple Developer Documentation
- Bostock, Mike. (2018, January 23), Sutherland–Hodgman Clipping
- dyn4j. (2011, November 11), Contact Points Using Clipping
- dyn4j. (2010, January 01), SAT (Separating Axis Theorem)
- Catto, Erin. (2006), Fast and Simple Physics using Sequential Impulses
- Catto, Erin. (2019), How Do Physics Engines Work?
- Catto, Erin. (2005), Iterative Dynamics with Temporal Coherence
- Chou, Ming-Lun. (2014, January 7), Game Physics: Stability – Warm Starting
- Coumans, Erwin. (2010, July 26), Collision Detection: Contact Generation and GPU Acceleration
- Hastings, Erin & Mesit, Jaruwan. (2005). Optimization of large-scale, real-time simulations by spatial hashing
- Fiedler, Glenn. (2013, February 24), Collision Response and Coulomb Friction
- Fiedler, Glenn. (2004, June 10), Fix Your Timestep!
- Fiedler, Glenn. (2004, June 01), Integration Basics
- Gaul, Randy. (2013, April 06), How to Create a Custom Physics Engine
- Gaul, Randy. (2013, July 16), Separating Axis Test (SAT) and Support Points in 2D
- Gregorius, Dirk. (2013), The Separating Axis Test between Convex Polyhedra
- Macdonald, Tristam. (2009, October 01), Spatial Hashing
- Manzke, Michael. (2016, February 22), Multiple Contact Resolution
- NVIDIA Corporation. (2017, May 12), NVIDIA PhysX 3.4.0 API Documentation
- Rees, Gareth. (2019, February 09), How do you detect where two line segments intersect?
- Scratchapixel. (n.d.), A Minimal Ray-Tracer: Rendering Simple Shapes (Sphere, Cube, Disk, Plane, etc.)
- Tonge, Richard. (2013), Iterative Rigid Body Solvers
- Unity Technologies. (2018, April 04), Unity Manual: Physics Reference 2D
- Virtual Method Studio. (2017, November 21), Physics 101 #3: Solvers
License
MIT License