MA FinalProject

download MA FinalProject

of 12

Transcript of MA FinalProject

  • 8/10/2019 MA FinalProject

    1/12

    Ma 1

    3D Pool Simulation

    Jia Ming Simon Ma

    CMPS 162

    Final Project

  • 8/10/2019 MA FinalProject

    2/12

    Ma 2

    Table of Contents

    Abstract and history---------------------------------------------------------------- 3 ~ 4

    Introduction -------------------------------------------------------------------------- 4~5

    How to Use-----------------------------------------------------------------------------5~ 6

    Physics implementation ------------------------------------------------------------- 6~8

    Implementation detail-------------------------------------------------------------- 8~9

    Result ----------------------------------------------------------------------------------9~10

    Conclusion and problem ----------------------------------------------------------- 11

    Reference ---------------------------------------------------------------------------- 12

  • 8/10/2019 MA FinalProject

    3/12

    Ma 3

    Abstract and history

    Pool, also more formally known as pocket, is the family of cue sports and games

    played on a pool table having six receptacles called pockets along the rails, into which

    balls are deposited as the main goal of play. Popular versions include eight-ball and

    nine-ball.

    The History of billiards is long and very rich. The game has been played by kings

    and commoners, presidents, mental patients, ladies, gentlemen, and hustlers alike. It

    evolved from a lawn game similar to the croquet played some-time during the 15th

    century in Northern Europe and

    probably in France. Play moved indoors

    to a wooden table with green cloth to

    simulate grass, and a simple border was

    placed around the edges. The balls were

    shoved, rather than struck, with

    wooden sticks called "maces." The term "billiard" is derived from French, either from

    the word "billart", one of the wooden sticks, or "bille", a ball.

    In the United States, though the original "pool" game was played on a pocketless

    carom billiards table, the term later stuck to all new games of pocket billiards as the

    sport gained in popularity, and so outside the cue sports industry, which has long

    favored the more formal termpocket billiards, pool has remained the common name for

    the sport.

    Figure 1: Michael Phelan's Billiard Saloon[1]

  • 8/10/2019 MA FinalProject

    4/12

    Ma 4

    There are hundreds of pool games. Some of the more well known include eight-ball,

    nine-ball, ten-ball, straight pool, and one-pocket.

    There are also hybrid games combining aspects of both pool and carom billiards, such as

    American four-ball billiards, cowboy pool and bottle pool.[2]

    Introduction

    This project is going to simulate a Eight-ball pool game.

    8 ball pool is the most popular billiard game in the world and one of the most

    popular games in the US. Being the least difficult pool game, 8 ball pool is commonly

    played by professionals as well as by amateurs and recreational players.

    Equipment:8 ball pool is played with a set of 15 object balls divided into two

    groups of solid colored balls and striped balls. Each player is assigned a group of object

    balls.

    Game Objectives : The objective of the game is to sink the 8-ball in a pocket after

    sinking the entire group of object balls.

    BCA 9 Ball Pool Rules : According to the BCA 8 ball pool rules, the game begins

    with an opening break shot, which its purpose is to break open the rack of balls. The

    player who was chosen to break open the game is required to send an object ball to a

    pocket or cause at least four object balls to hit the cushions. In 8 ball pool, as long as a

  • 8/10/2019 MA FinalProject

    5/12

    Ma 5

    player succeeds in making a legal shot, he is entitled to continue shooting at the table. A

    failure in making a legal shot, also known as foul, leads to a switch of turns between the

    players.

    Choice of Group of Object Balls : The choice of group of balls is made after the

    opening break shot with the first legally pocketed object ball. From that point and on,

    the players may pocket only the assigned group of object balls, otherwise it is a foul.

    Pocketing the 8-Ball :The first player who had pocketed his assigned group of

    object balls can try to pocket the 8-ball. Before shooting the 8-ball, the player has to

    announce a certain pocket. Pocketing the 8-ball to a different pocket than the

    announced one is a foul. If the 8-ball has been pocketed to the announced pocket, the

    shooting player wins the game.[3]

    In my program, the groups of balls are simply divided into two color group

    instead of strip and solid.

    How to Use

    This program REQUIRES : GLUTlibrary,C++ compiler (Visual C++ 2011 tested).

    1) Start the program, all the pool balls are already

    put in the correct position. In case of starting a

    new game, press 'x' button, and everything will

    be reset.

    Figure 2 : Behind the white ball view

  • 8/10/2019 MA FinalProject

    6/12

    Ma 6

    Figure 3 : Behind the white ball view

    2) Press 'c' button to switch between "Top view" and "Behind the white ball view".

    Hold the right mouse button and move the mouse to rotate the camera in

    "Behind the white ball view mode". Hold the middle mouse button and move up

    or down to zoom in or out.

    3) click on the white ball in "Top View" mode (if click

    left mouse button in "Behind the white ball view",

    it will automatically switch to "Top view" mode)

    with left mouse button, hold it and drag back.

    The yellow dash line represents the direction of

    white ball if you release the left button now. The

    more you drag back, the more powerful this

    release is.

    4) If foul happens, the other user is able to move the white ball with arrow keys,

    and submit the position by pressing 'F1' button.

    Physics implementation

    Ball movement:

    Poll ball movement can be considered as a regular 2D motion with constant

    acceleration or deceleration. Since the friction affects to pool balls are "rolling friction",

    the friction is not constant. In my program, I simply subtract 1/10 of the velocity, and set

    the velocity to 0 when the magnitude of velocity is very close to 0.

    The acceleration, velocity, and time relationship for 2D motion is :

  • 8/10/2019 MA FinalProject

    7/12

    Ma 7

    Figure 4 : Reflection

    () ()

    where V(t) is the current velocity, V(0) is the initial velocity, a is the acceleration, and t is

    the time. And based on my ideas, ( ) () () for every 10 milliseconds.

    Rolling effect:

    In the real world, the ball is rolling but not sliding. In order to represent this I am

    going to use quaternion on each pool ball. The matrix is :

    1-2y2-2z

    22xy-2wz 2xz+2wy 0

    2xy+2wz 1-2x2-2z

    2 2yz+2wx 0

    2xz-2wy 2yz-2wx 1-2x2-2y

    2 0

    0 0 0 1

    w = cosf( fAngle/2) x = axis.x * sinf( fAngle/2 ) y = axis.y * sinf( fAngle/2 )

    z = axis.z * sinf( fAngle/2 )

    So, by multiplying this matrix with any current matrix to rotate a object around any axis

    to represents the rolling of ball.

    Collision:

    Reflection :

    Reflection happens when a pool ball hit

    the side edge cushions. Reflection ideally

    doesn't change the magnitude of velocity, but

  • 8/10/2019 MA FinalProject

    8/12

    Ma 8

    Figure 5 : Ball collision

    only reverses one of its velocity component. For example, if a ball hit the top cushion as

    the figure on the right shows, the X component of velocity remains and reverse the Y

    component. The resulting velocity is the velocity when pool ball bounces back. So, for

    the reflection happens on side edges, flip the x component; for reflection happens on

    top or bottom edges, flip the z component.

    Ball collision :

    When one pool ball hits another ball, the velocity

    of both balls change. Based on the conservation of

    momentum equation "m1v1i+ m2v2i= m1v1f+ m2v2f" ,

    the mass are all equal, so the velocity equation becomes :

    v1i+ v2i= v1f+ v2f. The easiest way to calculate the final

    velocity is to break the velocity into two components.

    One component is along the connected line between two centers of balls; the other one

    is perpendicular to it. When the collision happens, swaps the components along the

    center connection, and then the sum of two components of one ball is its velocity.

    Implementation detail

    My goal is to implement a program to simulate a pool game in 3D. Due to the

    limitation of time, I decided to make the program works first. In other words, I will

    simply draw the table and balls. After the program runs, I can start implementing the

  • 8/10/2019 MA FinalProject

    9/12

    Ma 9

    Figure 6 : initial screen of running program

    physics effect including collision, reflection, and position changing. Eventually, set the

    rules for pocket and foul.

    The second step is to add more detail into the program. The first thing to

    implement is the rolling effect of each poll ball. The pool balls are rolling instead of

    sliding in real life. The solution to this is to rotate the coordinate before each rendering,

    and pop the original matrix back after rendering. The second improvement is to add

    more polygons when drawing the pool table.

    Result

    Since the time is really limited, I was not able to implement all the features.

    However, the basic program is working perfectly, and the physics calculation correct

    besides the rolling effect. Here are

    some actual screenshot of running

    program.

  • 8/10/2019 MA FinalProject

    10/12

    Ma 10

    Figure 7 : Top view mode/ break shot

    Figure 8 : Screenshot

  • 8/10/2019 MA FinalProject

    11/12

    Ma 11

    Conclusion and problem

    This program is running good with corrected physical collision. The ball will be

    identified as pocketed if it hits the pocket position. However, this program is not

    perfectly finished yet.

    The first problem is the animation. I was initially using FLTK and GLUT library for

    this program. I was thinking to have a GUI for user to control how the program runs

    easier. But the animation control of FLTK is much different from original GLUT, and I was

    having a big problem when I was doing assignment 2's animation. So I decided to get rid

    of FLTK, and use GLUT as my platform. As the result of this, it took me several days to

    convert all the code I wrote in FLTK to GLUT.

    The second problem is the rolling effect. I totally understand the concept of

    quaternion, and I was planning to use it for ball rolling effect. However, the matrix

    calculation and the conversation from concept to reality cost me a lot of time. And due

    to the limited time, I had to give up implement this even though I almost finished.

    Eventually, I used traditional glRotate() method to get the ball rolling effect correctly.

    The lat problem is the shooting control. Currently, the shooting is forced to be in

    "top view mode". But what I want is a way of shooting way that can be performed in

    both "top view mode" or "behind the white ball mode".

    Hopefully I am able to fix all those problems in the future, and make this

    program perfect.

  • 8/10/2019 MA FinalProject

    12/12

    Ma 12

    Reference

    [1].Phelan, Michael. Michael Phelan's Billiard Saloon. 1859. Photograph. New York Public

    Library Picture, New York.

    [2]."History Of Pool." The History of Pool, Billiards, English Billiards, Snooker, Eight-Ball, Cue

    Stick, Billiard Congress of America TheBilliard Shop. N.p., n.d. Web. 09 June 2012.

    .

    [3].

    "8 Ball Pool Background & Rules." 8 Ball Pool Background & Rules. N.p., n.d. Web. 09

    June 2012. .