A 2D rigid body physics engine written in C++20, using SAT collision detection, XPBD constraint solving, and raylib for rendering.

std::shared_ptr / std::unique_ptr.yml filesFxArray and comprehensive linear-algebra utilities in Fx2D/Math.hThe repository keeps lib/imgui and lib/rlImGui as placeholder folders in Git, but it does not commit the third-party sources. Populate those folders locally before building.
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
chmod +x fxmake # Make executable
./fxmake # Build in Release mode
./fxmake debug # Build in Debug mode
./fxmake rebuild # Clean and rebuild
./fxmake clean # Clean build artifacts
#include "Fx2D/Core.h"
int main() {
// Load scene from YAML
auto scene = FxYAML::buildScene("./Scene.yml");
// Initialize renderer with 60 FPS target
FxRylbRenderer renderer(scene, 60);
// Start the simulation loop
renderer.run();
return 0;
}
For headless simulation, testing, or data collection.
int main() {
// Load scene from YAML
auto scene = FxYAML::buildScene("./Scene.yml");
const double dt = 0.001f; // Fixed time step in seconds
auto ball = scene.get_entity("ball"); // Get the poiner to the entity by name "ball"
for (size_t i = 0; i < 10; ++i) {
scene.step(dt); // Advance physics without rendering
std::cout<< ball->pose <<std::endl;
}
return 0;
}
To run an example, copy the main.cpp from examples to src/, build the project, and ensure Scene.yml and assets are accessible to the executable.
./Fx2D # Linux/macOS
./Fx2D.exe # Windows

| Doc | Description |
|---|---|
| scene_yml.md | Full reference for writing Scene.yml files — scene block, entities, geometry types, physics fields |
| xpbd_solver.md | How the XPBD solver works — per-substep pipeline, constraint kernel equations, constraint types |
| collision_resolution.md | Collision detection and response — SAT narrow phase, penetration correction, restitution & friction |
| raylib_renderer.md | Raylib renderer API — window setup, background, camera, draw callbacks |
| headless_mode.md | Running the simulation without a renderer for testing and data collection |
| math_utils.md | FxArray, vector/matrix math utilities, and helper functions |
| ToDo.md | Current feature and robustness roadmap for Fx2D |
See ToDo.md for the current feature and robustness roadmap.
BSD-3-Clause License
Contributions are welcome! Please follow the existing code style and conventions.
main, commit your changes, and open a pull request referencing the issue.