This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
poolvr.py is a VR pool/billiards simulator written in Python. It features an event-based physics engine based on the paper "An Event-Based Pool Physics Simulator" by Leckie & Greenspan.
python setup.py install# VR mode (requires pyopenvr)
poolvr
# Non-VR mode
poolvr --novr
# See all options
poolvr -h# Run all tests from the test directory
cd test && pytest
# Run a single test
cd test && pytest test_physics.py::test_strike_ball
# Run with a specific collision model
cd test && pytest --collision-model=fsimulated
# Generate and save plots
cd test && pytest --save-plots
# Run with OpenGL rendering
cd test && pytest --renderThe physics engine uses Fortran for performance-critical collision calculations. Shared libraries (_collisions.so, _poly_solvers.so) are built from .f90 files in poolvr/physics/.
Physics Engine (poolvr/physics/):
__init__.py-PoolPhysicsclass: main event-based physics simulator that manages ball states and determines collision sequencesevents.py- Event hierarchy:PhysicsEventbase class with specialized events (BallSlidingEvent,BallRollingEvent,BallSpinningEvent,BallRestEvent,BallCollisionEvent,SegmentCollisionEvent,CornerCollisionEvent)collisions.py- Ball-ball collision model (Python wrapper + Fortran implementation incollisions.f90)poly_solvers.py- Quartic/polynomial solvers for collision time calculation (Fortran inpoly_solvers.f90)
Ball Collision Models (configured via --collision-model):
simple- SimpleBallCollisionEventsimulated- SimulatedBallCollisionEvent (Python implementation)fsimulated- FSimulatedBallCollisionEvent (Fortran implementation)
Game Layer (poolvr/):
game.py-PoolGame: high-level game state, ball positions/velocities/quaternionstable.py-PoolTable: table geometry, pocket positions, cushion boundariesapp.py/glfw_app.py- Main application loop with GLFW window management__main__.py- CLI entry point with argument parsing
Rendering (poolvr/):
gl_rendering.py- OpenGL mesh/material/renderer abstractionsgl_primitives.py- Basic geometric primitivesgl_techniques.py- Shader techniques (Lambert, EGA, etc.)pyopenvr_renderer.py- OpenVR integration for VR headsetsshaders/- GLSL vertex/fragment shaders
CueStrikeEventinitiates ball motion- Ball transitions through motion states:
BallSlidingEvent->BallRollingEvent->BallRestEvent(orBallSpinningEvent) PoolPhysics._determine_next_event()finds earliest collision or state transition- Collision events (
BallCollisionEvent,SegmentCollisionEvent,CornerCollisionEvent) spawn child motion events
Tests use pytest fixtures defined in test/conftest.py:
pool_physics- Parametrized across collision models (simple, simulated, fsimulated)pool_table- Standard pool table geometryplot_energy,plot_motion_timelapse- Enable with--save-plotsor--show-plotsgl_rendering- Enable with--renderor--vr