Home » Community » Forums » Math and Physics » Pool Cue Spin Physics
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Pool Cue Spin Physics
Post New Topic  Post Reply 
Could someone help please?

I am currently working on a 2D pool game using a product called Dark Basic. I have the basic game working and the general motion and collisions seem fine. The problem is I now want to account for spin (english). Since it is a 2D game I have really just used Trig to calculate the motion, rather than more complex vector physics. Really what I want is something that plays well, without necessarily being a true physics simulation.

So I guess my question is - is there a simple way I can adjust the motion of the cue ball when it collides, to account for the spin on it. Below is a simplified section of the code, with comments that hopefully make sense. To keep it simple I was kind of thinking that maybe I could just consider what happens to the cue ball when it first collides, ignoring the effects on other balls. Note that the code below doesn't include the section for Wall collision (I thought it would make this already long post far too much).

Any help would be greatly appreciated

*************************************

FirstCollision = 1

`Do the movement of the balls and collision detection in steps, for increased accuracy

FOR l=1 TO numSteps `set to 30

`Loop through all balls `1=cueball
FOR x=1 TO numBalls

`Move the ball
INC balls(x).xPos,balls(x).xVel/numSteps
INC balls(x).yPos,balls(x).yVel/numSteps

`Control the shooting of the ball
...
...
...
shotAng = 360-(180-ATANFULL(mouseHoldX-MOUSEX(),mouseHoldY-MOUSEY()))
shotpower = 10 `constant for testing purposes

balls(1).xVel=SIN(shotAng)*shotPower
balls(1).yVel=COS(shotAng)*shotPower

`Loop through all balls
FOR y=1 TO numBalls

`Don't check collision between the same ball
IF y<>x
`Get distance of balls from each other
dist = SQRT((balls(x).xPos-balls(y).xPos)^2+(balls(x).yPos-balls(y).yPos)^2)

`If they are touching
IF dist < ballRad*2
`Get the angle between them
angleBetween = ATANFULL(balls(x).xPos-balls(y).xPos,balls(x).yPos-balls(y).yPos)

`Move the first ball back where it was
DEC balls(x).xPos,balls(x).xVel/numSteps
DEC balls(x).yPos,balls(x).yVel/numSteps

`Get the angles of the balls velocities
ang1 = ATANFULL(balls(x).xVel,balls(x).yVel)
ang2 = ATANFULL(balls(y).xVel,balls(y).yVel)

`Get the speed of the balls velocities, with a slowing factor
vel1 = SQRT(balls(x).xVel^2+balls(x).yVel^2)*0.9
vel2 = SQRT(balls(y).xVel^2+balls(y).yVel^2)*0.9

`Work out the new velocities of the balls using trig
velX2 = SIN(angleBetween)*COS(angleBetween-ang1)*vel1 + SIN(angleBetween+90)*SIN(360-(angleBetween-ang2))*vel2
velY2 = COS(angleBetween)*COS(angleBetween-ang1)*vel1 + COS(angleBetween+90)*SIN(360-(angleBetween-ang2))*vel2

velX1 = SIN(angleBetween+90)*SIN(360-(angleBetween-ang1))*vel1 + SIN(angleBetween)*COS(angleBetween-ang2)*vel2
velY1 = COS(angleBetween+90)*SIN(360-(angleBetween-ang1))*vel1 + COS(angleBetween)*COS(angleBetween-ang2)*vel2

****/
IF THIS IS THE FIRST COLLISION OF THE CUE BALL CHECK ALTER THE POST COLLISON
DIRECT/SPEED ACCORDING TO SPIN ON THE CUE BALL

HERE IS WHERE THE PROBLEM IS
****/
if FirstCollision = 1 and x = 1

FirstCollision = 0

endif

`Set the balls' velocities
balls(x).xVel = velX1
balls(x).yVel = velY1
balls(y).xVel = velX2
balls(y).yVel = velY2
...
...
...

*************************************

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Hiya,

You only want to have the spin effect the ball movement on a collision correct? Even in 3D I'd probably fake this instead of trying to use friction between ball-wall, ball-ball (and the always present ball-floor)

Essentially, you want the angle of reflection change depending on how much spin you put on the ball. I'm not sure if you already have a coefficient of restitution in your calculation..ok, you are using 0.9 to dampen your speed factor. What I'm suggesting would be something similar but a bit more dynamic. Depending on the spin you put on the ball, the angle of reflection could change from 0 to so many degrees. You would have to play a bit with it to see what looks realistic though (the downside of faking physics :) ).

It gets more complicated if you want to be able to curve the ball or create back/front spin. For this you could play with the coefficient of restitution and have it dynamic so that a backspin on a ball hitting the wall brings it higher then 1 (normally it should be [0,1]). It wouldn't be totally realistic since a ball hitting a wall with front speed will normally bounce back normally and then the spin will cause the linear momentum to increase while it's angular momentum decreases until there is no spin anymore at which point it will slow down using the dampening factor (resistance). But I'd rather start something simple and get it working, then hard with nothing ever working properly :)

You need to take into account that a ball hitting a ball will have less change in angle then a ball hitting a wall (less friction).

Shadx

 User Rating: 1068   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Thanks Shadx,

I think the main problem is my brainpower to be honest. I have managed to get something that works, but only in certain situations. Basically I have a clause that is executed the first time the cue ball collides (at the moment just with another ball not walls). This sets sidespin and a speed adjustment factor. Like this (the variables angleBetween and ang1 are as in the original post):

**********************************************************************
if FirstCollision = 1 and x = 1

sidespin# = 100

velX1 = SIN(angleBetween+90 + sidespin#) * SIN(360-(angleBetween-ang1 - sidespin#))*vel1
velY1 = COS(angleBetween+90 + sidespin#) * SIN(360-(angleBetween-ang1 - sidespin#))*vel1

`-ve for topspin
velX1 = velX1 * -0.9
velY1 = velY1 * -0.9

endif

**********************************************************************

Now if the cue ball is coming from the left and strikes the object ball directly in the centre, the cue ball has topspin and slight sidespin and correctly rolls forward at a slight angle after impact. However if it strikes at a different angle things come out wrong. Or if the cue ball comes from the right or from above or below then things are wrong in some scenarios. The idea of the speed adjustment is that the more topspin or backspin on the cue ball the closer this adjustment will be to +/- 1.

I guess I would need to consider the angle between the balls on impact and the direction the cue ball was travelling in. Since this is the first impact the object ball will be stationary. Then adjust how this calculation is done accordingly.

The problem is I can't work out what needs to change when. Probably this introduction of sidespin into the equation is the wrong way to do it, but by trial and error I tried this and as it worked (albeit it in only a few scenarios).

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Ideally, you would implement a sphere/sphere collision response with friction, using an impulse-momentum approach. This is not out of the realm of possibility for billiards. It can be a bit tricky to deal with static friction. You might want to look at Jeff Lander's article at Gamasutra:

Physics on the Back of a Cocktail Napkin

This requires a free registration.

Graham Rhodes
Principal Scientist
Applied Research Associates, Inc.

 User Rating: 1788   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Thanks for the article! I'll take a closer look at it tonight. As it turns out, I'm also making a pool game/project. I implemented what I have so far with no spin. The balls do roll, but the angular velocity is calculated from the linear velocity instead of calculated independently (through force or impulse). I would love to make it look a bit more realistic but due to lack of time(and part of it understanding), I coudln't do so.

This project is for the new Physics class at Gameversity.com, so far it's a blast!

Regards,
Shadx

 User Rating: 1068   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Hello!

I am making a pool game too (MPool).
My situation is almost similar to the situation that Shadx have.
Now I'm planning to implement the spinning of a balls and I am thinking about how to make it in a better way.

Thanks to grhodes_at_work for the interesting link.

Maybe, information from THIS website could also be useful.

-----------------------------------------
I'm sorry if my english is not too good.
http://hydrophane.fatal.ru
http://hydrophane.fatal.ru/mpool/mpool_006.zip

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may not post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: