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 0.1.0
)

Build

Compile your project

cmake -Stestbed -Bbuild
cmake --build build --parallel 4
./build/bin/Testbed

Quick Start

Your first physics simulation

#include <dura2d/dura2d.h>

int main() {
    // Set up the world with gravity
    d2World world({0.F, -9.8F});
 
    // Create a circular body (Shape, Position, Mass)
    d2Body * pBody = world.CreateBody(d2CircleShape(45), {0, 0}, 10.F);
 
    // Simulate the physics for 5 seconds
    for (int i = 0; i < 60 * 5; ++i)
    {
        // Update the world for the next time step
        world.Step(1.F / 60.F);

        d2Vec2 pos = pBody->GetPosition();

        printf("Position: (%.2f, %.2f)\n", pos.x, pos.y);
    }
 
    return 0;
}

API Reference

World Class

The main physics simulation container

// Quick start with the World class
auto world = d2World();
world.SetGravity({0.F, -9.81F});
world.Step(1.F / 60.F);

RigidBody Class

Physical objects with mass and velocity

auto body = world.CreateBody(d2CircleShape(45), {0, 0}, 10.F);
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 →