- Raylib for rendering
- SAT for collision detection
- Sutherland-Hodgman Polygon Clipping for contact points
- Spatial Hashing for optimization
- nlohmann/json for JSON Parsing
- IMGUI for UI
- Rigidbody Physics
- Linear
- Angular
- Circle, Box and Convex Polygons Colliders
- Sequential Impulse Solver
- Constraints
- Distance
- Fixed and Rolling Pins
- Joints
- Motor
- Controllers
- Motor Controller
- Engine Editor
- Body Placing
- Constraint Building
- Debugging
- JSON Scene Loading and Saving
- Clone the repository:
git clone https://github.com/Lucas19919/PhysicsEngine.git - Navigate to the directory:
cd PhysicsEngine - Configure and build:
mkdir buildcd buildcmake ..cmake --build .
A GameObject is the fundamental base object of the engine. This was based on Unity's system of GameObjects and works in a similar way. Each GameObject holds Components and Constraints, which define how the GameObject interacts with the physics environment.
A Group is essentially a folder of objects. A Group can be created via the Hierarchy.
A Generator is a specific type of GameObject which can generate an
A Prefab is a saved Group of objects which can be instantiated all at once. An example of this is the default car Prefab in the Prefabs folder. Prefabs are created by saving a Group.
A Component is added to a GameObject and defines various elements and the interaction with the physics environment.
The Transform is the default Component and defines the position, rotation, and scale of the object. The Transform is fundamental and, hence, cannot be deleted.
The Rigidbody is the core of the physics engine. Here all physics parameters are set, which are then used by the solver. The Rigidbody is divided into 3 sections:
- Properties: Mass, Restitution, Friction, Inertia, Is Gravity Applied?
- Linear State: Velocity Vector, Acceleration Vector, Net Force
- Angular State: Angular Velocity, Angular Acceleration, Net Torque
Note: A Rigidbody with 0 mass will be considered a static object. Applying a Net Force or Torque does not mean continual application. A Net Force or Torque is no different from applying an acceleration, as these are cleared every frame.
A Collider is the primary collision object in the engine. It does not need to match with the render shape of the object.
- Circle: Defines a circular collider by the radius.
- Box: Defines a rectangular collider by a 2D size vector.
- Polygon: Defines a convex polygon by a list of points (not currently supported in the editor).
Defines the rendered view of the GameObject and its RGBA color.
Used to control Motors via keybinds. Currently a premature Component hardcoded to A and D.
A Constraint defines the motion of a GameObject.
- Distance: Defines the set distance between 2 GameObjects.
- Pins: Represents a point where an object is fixed (Fixed or Rolling in X or Y).
- Joints: Acts as a joint between objects; allows free rotation.
- Motor: Acts as a small motor applying a set torque per frame.
- Ctrl + N: Create new Scene
- Ctrl + S: Save Scene
- G: Select translation Gizmo
- E: Select rotation Gizmo
- S: Select scaling Gizmo
- R: Reset Scene
- Space: Pause Scene
- DELETE: Delete selected GameObject
The editor is made up of various "Panels". To manipulate a scene, use the top bar:
- File: New, Save, or Load scenes.
- Edit: Undo and Redo functionality.
- Theme: Switch themes (RETRO is default).
- Window: Close panels or reset layout.
- World: Set physics environment size in meters or pixels.
- Hierarchy: List of all current GameObjects, Generators, or Prefabs.
- Inspector: Edit Components and Constraints attached to an object.
- Performance: Breakdown of solver timing (Integration, Narrowphase, Broadphase) and current FPS.
- Viewport: The main scene view. Supports panning (Middle Mouse) and zooming (Scroll).
- Scene Manager: Load scenes from assets or custom folders.
- Debug: Toggle debug rendering modes and physics configurations.
- Constraints: Manage, highlight, and delete active scene constraints.
The engine uses a GameObject/Component architecture based on Unity. Physics are managed by a World class via the World.step(dt) pipeline:
- Clear all caches
- Update velocity from acceleration and external forces
- Broadphase: Spatial hash grid and AABB bounds check
- Narrowphase: SAT collision detection and Sutherland-Hogman clipping
- Warmstart constraints
- Solve constraints iteratively via a sequential impulse solver
- Update positions from velocity
- Update sleep conditions for Rigidbodies
- Cleanup
- Rework Constraint solver to separate position/velocity
- Motor controller (for robotic arms, etc.)
- CCD (Continuous Collision Detection)


