# worldwalker2000/simplephysics architecture

> Architecture diagram of the GitHub repository worldwalker2000/simplephysics, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/worldwalker2000/simplephysics
- Repository: https://github.com/worldwalker2000/simplephysics

## Overview

##### Project type and purpose
- This is a standalone C++ desktop application (“SimplePhysics”) that provides an interactive editor to build rigid-body structures and then runs a constraint-based physics simulation on them.
- Key features (from the README):
– An editor/UI for designing custom mechanical assemblies
– A simulation engine based on the “Constrained Dynamics” paper by Witkin & Baraff

##### File structure
- Top-level files (single‐directory codebase)
– main.cpp        → application entry point, event loop, UI/simulation orchestration
– system.cpp/h    → core data structures: bodies, joints, system state
– constraints.cpp/h → constraint formulation and solver routines
– forces.cpp/h      → definitions of force generators (e.g., gravity, springs)
– la.cpp/h          → linear algebra utilities (vectors, matrices, solvers)
– constraints.hpp / forces.hpp / la.hpp → public headers for each module
– Makefile         → build rules
– README.md        → overview & usage
- No separate “gui” or “render” folder is present, so the editor and rendering logic is likely embedded in main.cpp or linked in at compile time via an external graphics library.

##### Insights from the README
- Confirms two primary subsystems:
a. Editor/UI for scene construction
b. Physics engine for constrained dynamics simulation
- Points to an underlying academic algorithm, implying the presence of a constraint solver, force evaluator, and numerical integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    UI["UI / Editor Module"]:::ui
    Controller["Simulation Controller"]:::controller
    System["System Module"]:::engine
    Constraint["Constraint Solver"]:::engine
    Force["Force Evaluator"]:::engine
    LA["Linear Algebra Library"]:::support
    Graphics["Graphics API"]:::external
    Persistence["Scene Persistence"]:::external

    UI -->|"userInput()"| Controller
    Controller -->|"initialize()/loadScene()"| System
    Controller -->|"frameLoop()"| System
    System -->|"computeForces()"| Force
    Force -->|"forces" | System
    System -->|"solveConstraints()"| Constraint
    Constraint -->|"impulses" | System
    System -->|"updateTransforms()"| LA
    LA -->|"updatedData" | System
    System -->|"state" | Controller
    Controller -->|"renderScene()"| UI
    UI -->|"render calls" | Graphics
    Controller -->|"save/load()"| Persistence

    click UI "https://github.com/worldwalker2000/simplephysics/blob/master/main.cpp"
    click Controller "https://github.com/worldwalker2000/simplephysics/blob/master/main.cpp"
    click System "https://github.com/worldwalker2000/simplephysics/blob/master/system.cpp"
    click System "https://github.com/worldwalker2000/simplephysics/blob/master/system.hpp"
    click Constraint "https://github.com/worldwalker2000/simplephysics/blob/master/constraints.cpp"
    click Constraint "https://github.com/worldwalker2000/simplephysics/blob/master/constraints.hpp"
    click Force "https://github.com/worldwalker2000/simplephysics/blob/master/forces.cpp"
    click Force "https://github.com/worldwalker2000/simplephysics/blob/master/forces.hpp"
    click LA "https://github.com/worldwalker2000/simplephysics/blob/master/la.cpp"
    click LA "https://github.com/worldwalker2000/simplephysics/blob/master/la.hpp"

    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef controller fill:#90EE90,stroke:#333,stroke-width:1px
    classDef engine fill:#FFA500,stroke:#333,stroke-width:1px
    classDef support fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef external fill:#FFC0CB,stroke:#333,stroke-width:1px
```
