A billiards (pool table) physics simulation built using a C physics engine, wrapped with SWIG for Python, and served through a Python web server with a browser-based interface.
This project demonstrates integration between C, Python, and JavaScript to create an interactive physics simulation.
- Custom C physics engine for billiards simulation
- SWIG interface to expose the C library to Python
- Python server to run and control the simulation
- HTML/CSS/JavaScript frontend for visualization
- Real-time interaction with simulated pool ball physics
- C – Physics engine implementation
- SWIG – Interface generation between C and Python
- Python 3 – Server and simulation control
- JavaScript – Client-side interaction
- HTML/CSS – Web interface
- Makefile – Build automation
A4/
├── backend/
│ ├── server.py # Python server
│ ├── Physics.py # Physics logic interface
│ ├── phylib.py # Generated Python bindings
│ └── phylib.db # Simulation data
├── frontend/
│ ├── index.html # Web interface entry point
│ ├── script.js # Client-side logic
│ └── styles.css # Web styling
├── native/
│ ├── phylib.c # Core physics engine
│ ├── phylib.h # Physics library header
│ ├── phylib.i # SWIG interface file
│ └── phylib_wrap.c # SWIG generated wrapper
├── makefile
└── README.md
- Python 3.11
- SWIG
- Clang
- Make
- Linux or macOS (recommended)
Compile the physics library and Python bindings:
makeIf an error occurs during compilation, run the following command:
export LD_LIBRARY_PATH=$PWD/backendThis will:
- Compile the C physics engine
- Generate SWIG Python bindings
- Build the shared library
- Start the Python simulation server
After building, the server starts automatically:
python3 backend/server.py 55483Open a browser and navigate to:
http://localhost:55483You will see the pool simulation interface.
- The C physics engine (phylib.c) performs all physics calculations.
- SWIG generates wrapper code to expose C functions to Python.
- Python acts as a controller and web server.
- The frontend (HTML/JS) sends user actions to the server.
- The server updates the simulation and returns new state data.
This project explores:
- Low-level physics simulation in C
- Python/C interoperability using SWIG
- Shared libraries
- Web-based visualization of simulations
- Multi-language software architecture
Sukhman Dhaliwal Bachelor of Computing – Computer Science University of Guelph