Skip to content

Repository files navigation

3D Physics Engine

Writing a 3D rigid-body physics engine from scratch in C++.

phys-engine demo

Bringup

Run raylib renderer:

cmake -S . -B build -DPHYS_BUILD_SANDBOX=ON
cmake --build build --target phys_sandbox
./build/phys_sandbox

For benchmarking:

cmake -S . -B build/release-bench -DCMAKE_BUILD_TYPE=Release \
  -DPHYS_BUILD_SANDBOX=OFF -DPHYS_BUILD_BENCHMARKS=ON

cmake --build build/release-bench --target phys_collision_bench -j 4
./build/release-bench/phys_collision_bench

# phys_collision_bench [steps] [sap|grid|tree] [mixed|spheres] \
#   [warmup] [narrowphase_workers] [solver_workers] [broadphase_workers] [--sleep]

Pipeline

PhysicsWorld::step(dt)
    |
    v
Integrate forces into linear / angular velocities
    |
    v
Update collider world transforms and AABBs
    |
    v
Broad phase -> candidate pairs
    |
    v
Narrow phase -> contact manifolds
    |
    v
Constraint solver -> corrected velocities
    |
    v
Integrate positions / orientations

See architecture, collision pipeline, and the concise performance optimization history for more.

Roadmap

Stage Scope
V0 Basic math, rigid bodies, gravity, semi-implicit Euler; then a simple debug renderer
V1 Spheres, AABBs, sphere-sphere contacts, basic impulse response
V2 Oriented boxes, SAT, angular dynamics, inertia, friction, multi-point manifolds
V3 Improved broad phase, sequential impulses, stable stacking, instrumentation
V4 Evaluate continuous collision detection and other differentiators; GJK + EPA and an experimental dynamic AABB tree are implemented

About

3D Physics Engine

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages