Fx2D

A 2D physics simulator written in C++ (20).

Examples

image

Key Features

Dependencies

Building

Method 1: CMake

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j

Method 2: Using fxmake

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

Quick Start

Basic Usage

#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;
}

Running Examples

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

truck

License

BSD-3-Clause License

Todo

Contributing

Contributions are welcome! Please follow the existing code style and conventions.