ferox icon indicating copy to clipboard operation
ferox copied to clipboard

A lightweight 2D physics engine written in C, for educational purposes.

c-krit/ferox

version badge codefactor badge code-size badge license badge

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.

DocumentationExamplesPrerequisites

Features


Since this project was made to learn how a physics engine works, I am not planning to add a lot of features to it.

  • 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

License

MIT License