OpenGL Pool

CSC471 - Spring 2006
Broc Miramontes


Overview

This project used OpenGl to implement a game of pool. The game consisted of being able to place your ball behind the intial break point, shooting a pool break and allowing the user to play out a game of pool with very basic rules. The user is able to aim his shots using keyboard commands and determine the power of his shot by holding the g key.

Motivation & Methods

The idea for this project came from the want of learning how to use collision detection. This program involves sixteen balls having the possibility to collide and effect each other. Much of the preparation for this program was spent looking through old physics books and reading up on the conservation of momentum and vector math. I decided to not really concentrate on trying to find things that explained to me how to do the collision detection, but rather just figure it out myself. I think a fairly good job considering the program runs at decent speed, there is very little clipping and the collisions are very consistent. The collisions were my main focus, but I also put lots of work into setting up the table and pool cue. I did not use many resources beside what I learned in class and what I found in the physics book. I really only grabbed some textures from a site;

Physics

All of the physics modeling in this program came from the principles of conservation of momentum, vector math to calculate the transfer of energy and the concept of velocity to describe the objects motion. Equal amounts of energy must enter and leave a closed system. Using this idea I used basic physics laws to calculate how each ball would react. I assumed all the masses of all the balls were the same. I also used constant ratios to describe the effects of friction and loss of energy from sound or anywhere else energy may be lost. This simplified my physics equations down to just needing to know the vector describing each objects velocity and the angle at which the balls collide at. The main equation I used just projected the amount of one balls velocity in the direction of collision onto the other ball. To calculate to all the collisions that could occur it took an N*N approach, where I had to check each ball against each other ball. Because the number of balls is so small this wasn't an issue.

Controlling Pool

Control Modes

This pool games has two possible control modes. At the beginning of each game, or when the cue ball is pocketed, the game enters scratch mode. View mode is set to Birds eye for this mode. This allows the user to move the ball behind the break point and set the cue where ever he chooses to place it. The second mode is the actual game play mode where the user can aim and take a pool shot. Default view mode is set to the low angle eye. The user can momentarily switch to bird eye view by holding 'f.' While the ball is in motion all commands are blocked, except for switching views and turning off and on the velocity vectors.

Scratch Mode

Play Mode

Download

You can download the Windows executable version of pool here. This version has been tested on WindowsXP and requires OpenGL and GLUT libraries.

Screenshots

     

Resources