Dura2D

A lightweight, educational physics engine designed for game developers and simulation enthusiasts.

F1 Toggle UI
R Restart
S Step
P Pause/Resume
Keyboard shortcuts

Features

Easy Integration

Seamlessly add it to your existing projects with a simple API and built-in CMake support—quick to set up, easy to use.

Cross-Platform

Runs smoothly on Windows, macOS, and Linux with minimal setup, plus now supporting WebAssembly and Sony® PSP™.

Documentation

Getting Started

Installation

Add to your CMake project

include(CPM.cmake)
CPMAddPackage(
  NAME Dura2D
  GITHUB_REPOSITORY SOHNE/Dura2D
  VERSION 1.0.0
)

Build

Compile your project

cmake -B build
cmake --build build
./build/examples/demo

Quick Start

Your first physics simulation

#include <dura2d/dura2d.hpp>

int main() {
    // Initialize the physics world
    dura2d::World world(dura2d::Vec2(0.0f, -9.81f));
    
    // Create a dynamic body
    auto body = world.CreateBody(dura2d::BodyType::Dynamic);
    body->SetPosition(dura2d::Vec2(0.0f, 10.0f));
    
    // Add a circle shape
    dura2d::CircleShape circle(1.0f);
    body->SetShape(&circle);
    
    // Simulation loop
    while (running) {
        world.Step(1.0f / 60.0f);
    }
    
    return 0;
}

API Reference

World Class

The main physics simulation container

// Quick start with the World class
auto world = dura2d::World();
world.SetGravity({0.0f, -9.81f});
world.Step(1.0f / 60.0f);

RigidBody Class

Physical objects with mass and velocity

auto body = world.CreateBody(dura2d::BodyType::Dynamic);
body->SetPosition({10.0f, 20.0f});
body->AddForce({0.0f, -10.0f});

Shapes

Geometric shapes for collision detection

dura2d::CircleShape circle(1.0f);
dura2d::BoxShape box(2.0f, 1.0f);
body->SetShape(&circle);

Joints

Constraints between bodies

auto joint = world.CreateJoint<dura2d::RevoluteJoint>(
    bodyA, bodyB, anchor
);

Examples

Demo Preview

Basic Physics Demo

Simple demonstration of gravity and collision

View Source →
Demo Preview

Chain Simulation

Connected bodies with constraints

View Source →
Demo Preview

Soft Body Simulation

Deformable bodies with physics-based animation

View Source →