Skip to content

abubahmed/2D-physics-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A sandbox 2D physics kinematics engine that simulates gravity, momentum, and collisions in real-time. Built with OCaml using the Core and Async libraries, with graphics rendering via OCaml Graphics.

The engine uses a timestep system that advances the simulation in discrete steps (default: 0.001s). Each timestep processes collision reactions, updates object velocities based on forces, and then updates positions. User interactions are handled through event-driven input listeners that asynchronously wait for mouse clicks and button events, allowing seamless object creation, dragging, and UI control without blocking the physics simulation loop.

Core Physics

  • vector.mli - 2D vector operations and transformations
  • units.mli - conversions between pixel coordinates and physics units
  • objects.mli - object types (Ball, Box, Line, Cup) with position, velocity, and physics properties
  • force.mli - force representation for applying physics effects to objects
  • collisions.mli - collision detection between objects (ball-ball, ball-line, ball-cup, etc.)
  • reactions.mli - collision response handling and reaction effects
  • step.mli - physics simulation time step execution

User Interface

  • click_state.mli - tracks user interaction state (creating objects, dragging, selecting)
  • click_interactions.mli - handles mouse click events and user input
  • panel.mli - UI components (buttons and text boxes)
  • canvas.mli - bounded area for managing and rendering physics objects
  • interface.mli - combines panel and canvas into a unified interface

Simulation Runtime

  • world_state.mli - simulation status tracking (In_progress, Paused, Clear, Failure)
  • world_graphics.mli - graphics initialization and rendering system
  • world.mli - main world container combining state, interface, and interaction handling
  • run.mli - main entry point that starts the simulation

Screenshot 1

Screenshot 2

Screenshot 3

Screenshot 4

Screenshot 5

Screenshot 6

About

Final project for 2025 Jane Street Summer Immersion Program. Codeveloped by Bari LeBari.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors