Developer guide:

poolvr.table: Model of the pool table’s geometry and other physical parameters

class poolvr.table.PoolTable(length=2.34, height=0.77, width=None, width_rail=0.0508, **kwargs)[source]

poolvr.physics: event-based Pool physics simulator

This module implements an event-based pool physics simulator based on the paper (available at http://web.stanford.edu/group/billiards/AnEventBasedPoolPhysicsSimulator.pdf):

AN EVENT-BASED POOL PHYSICS SIMULATOR
Will Leckie, Michael Greenspan
DOI: 10.1007/11922155_19 · Source: DBLP
Conference: Advances in Computer Games, 11th International Conference,
Taipei, Taiwan, September 6-9, 2005.
class poolvr.physics.PoolPhysics(num_balls=16, ball_mass=0.17, ball_radius=0.028575, mu_r=0.016, mu_sp=0.044, mu_s=0.2, mu_b=0.06, c_b=4000.0, E_Y_b=2400000000.0, g=9.81, initial_positions=None, use_simple_ball_collisions=False, **kwargs)[source]

Pool physics simulator

Parameters:
  • mu_r\mu_r, rolling friction coefficient
  • mu_sp\mu_{sp}, spinning friction coefficient
  • mu_s\mu_s, sliding friction coefficient
  • mu_b\mu_b, ball-to-ball collision friction coefficient
  • c_bc_b, ball material’s speed of sound
  • E_Y_b{E_Y}_b, ball material’s Young’s modulus
  • g – downward acceleration due to gravity
eval_accelerations(t, balls=None, out=None)[source]

Evaluate the linear accelerations of all balls at game time t.

Returns:shape (N, 3) array, where N is the number of balls
eval_angular_velocities(t, balls=None, out=None)[source]

Evaluate the angular velocities of all balls at game time t.

Returns:shape (N, 3) array, where N is the number of balls
eval_positions(t, balls=None, out=None)[source]

Evaluate the positions of a set of balls at game time t.

Returns:shape (N, 3) array, where N is the number of balls
eval_quaternions(t, out=None)[source]

Evaluate the rotations of a set of balls (represented as quaternions) at game time t.

Returns:shape (N, 4) array, where N is the number of balls
eval_velocities(t, balls=None, out=None)[source]

Evaluate the velocities of a set of balls at game time t.

Returns:shape (N, 3) array, where N is the number of balls
find_ball_states(t, balls=None)[source]

Determine the states (stationary, sliding, rolling, or spinning) of a set of balls at game time t.

Returns:dict mapping ball number to state
next_turn_time()[source]

Return the time at which all balls have come to rest.

reset(ball_positions)[source]

Reset the state of the balls to at rest at the specified positions

strike_ball(t, i, Q, V, cue_mass)[source]

Strike ball i at game time t. The cue strikes the ball at point Q = a \hat{i} + b \hat{j} + c \hat{k}, which is specified in coordinates relative to the ball’s center with the \hat{k}-axis aligned with the horizontal component of the cue’s impact velocity V = \vec{V}, i.e.

\hat{k} = - \frac{\vec{V} - (\vec{V} \cdot \hat{j}) \hat{j}}{ \| \vec{V} - (\vec{V} \cdot \hat{j}) \hat{j} \| }

and c > 0.

poolvr.game: Pool game classes which implement game rules, initial conditions, table setup, etc.

class poolvr.game.PoolGame(ball_colors=[14540254, 15658496, 238, 15597568, 15597806, 15628032, 60928, 12264004, 1118481, 15658496, 238, 15597568, 15597806, 15628032, 60928, 12264004], ball_radius=0.028575, table=None, **kwargs)[source]

Game state for a pool “game”

Parameters:
  • ball_colors – array defining a base color for each ball
  • stripe_colorsoptional map defining a stripe color for each ball that is striped
advance_time(interp=None)[source]

Advances the game time to the instant that all balls have come to rest.

initial_positions(d=None, out=None)[source]

Set balls to initial (racked) positions

reset()[source]

Resets the game state, which means: set balls in their initial stationary positions; reset physics engine.

poolvr.gl_rendering: OpenGL renderer, node-based scenegraph with glTF-like datatypes

class poolvr.gl_rendering.OpenGLRenderer(multisample=0, znear=0.1, zfar=1000, window_size=(960, 1080))[source]
render(meshes=None)[source]

Render the given meshes.

This method returns a managed context for drawing the frame. If used in a with-statement, the rendering takes place when the with block is exited.

Parameters:optional (meshes) – iterable collection of Mesh-like objects
class poolvr.gl_rendering.Program(vs_src, fs_src, parse_attributes=True, parse_uniforms=True)[source]

GLSL program

class poolvr.gl_rendering.Technique(program, attributes=None, uniforms=None, states=None)[source]

GL rendering technique (based off of Technique defined by glTF schema)

class poolvr.gl_rendering.Material(technique, values=None, textures=None)[source]
class poolvr.gl_rendering.Primitive(mode, indices, index_buffer=None, attribute_usage=None, **attributes)[source]
class poolvr.gl_rendering.Mesh(primitives, matrix=None)[source]
class poolvr.gl_rendering.Node(matrix=None)[source]

poolvr.primitives: Various primitive geometry classes for the OpenGL renderer and the physics engine

class poolvr.primitives.HexaPrimitive(vertices=None)[source]
class poolvr.primitives.CylinderPrimitive(radius=0.5, height=1.0, num_radial=12)[source]
class poolvr.primitives.SpherePrimitive(radius=0.5, widthSegments=16, heightSegments=12, phiStart=0.0, phiLength=6.283185307179586, thetaStart=0.0, thetaLength=3.141592653589793)[source]

Sphere geometry based on three.js implementation: https://github.com/mrdoob/three.js/blob/44ec6fa7a277a3ee0d2883d9686978655bdac235/src/geometries/SphereGeometry.js

class poolvr.primitives.PlanePrimitive(width=1.0, height=1.0, depth=0.0, **attributes)[source]
class poolvr.primitives.BoxPrimitive(width=1.0, height=1.0, length=1.0)[source]

poolvr.billboards: OpenGL billboard particle class which is used to render the balls

poolvr.ode_physics: Open Dynamics Engine (ODE)-based physics simulator (time-stepped)

Open Dynamic Engine-based pool physics simulator

class poolvr.ode_physics.ODEPoolPhysics(num_balls=16, ball_mass=0.17, ball_radius=0.028575, g=9.81, linear_damping=0.06, angular_damping=0.1, initial_positions=None, table=None, **kwargs)[source]