Skip to content

About

A billiards physics simulation using a C physics engine wrapped with SWIG for Python, served through a lightweight Python web server with an HTML/JavaScript frontend.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pool Physics Simulation

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.


Features

  • 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

Technologies Used

  • 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

Project Structure

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

Requirements

  • Python 3.11
  • SWIG
  • Clang
  • Make
  • Linux or macOS (recommended)

Build Instructions

Compile the physics library and Python bindings:

make

If an error occurs during compilation, run the following command:

export LD_LIBRARY_PATH=$PWD/backend

This will:

  1. Compile the C physics engine
  2. Generate SWIG Python bindings
  3. Build the shared library
  4. Start the Python simulation server

Running the Simulation

After building, the server starts automatically:

python3 backend/server.py 55483

Open a browser and navigate to:

http://localhost:55483

You will see the pool simulation interface.


How it works

  1. The C physics engine (phylib.c) performs all physics calculations.
  2. SWIG generates wrapper code to expose C functions to Python.
  3. Python acts as a controller and web server.
  4. The frontend (HTML/JS) sends user actions to the server.
  5. The server updates the simulation and returns new state data.

Learning Goals

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

Author

Sukhman Dhaliwal Bachelor of Computing – Computer Science University of Guelph

About

A billiards physics simulation using a C physics engine wrapped with SWIG for Python, served through a lightweight Python web server with an HTML/JavaScript frontend.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages