Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Pool/Snooker/Billiards Physics Demo

Author
Message
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 24th Jan 2004 16:42 Edited at: 24th Jan 2004 21:04
I managed to come up with some pool physics throughout yesterday and today, they may not be entirely accurate as I couldn't find anything on the internet about pool physics apart from some 90 degree velocity rule. I know real balls spin, but I haven't taken that into account yet. Therefore I had to go by some guessing and trial and error to get the right physics.

I have had some problems with the balls sticking to each other, I managed to pretty much eliminate this bug by doing 10 collision checks each loop, and moving the balls at 1/10th the visible speed. Obvoiusly it may still happen as in real life there are infinate collision checks , just turn the variable "numSteps" up if you find them sticking.

Please give me credit if you use this code in any way (one name springs to mind ).

LMB to control cue ball
Spacebar to reset balls

Download:
http://www.freewebs.com/thedarkbasicplace/forumstuff/pool.rar

Updated Version:


Do you bite your thumb at me sir?

Athelon XP 1600 Plus (1.4ghz) - ATI Radeon 9600 Pro - 256mb RAM
OutLand
20
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: uk,wales
Posted: 24th Jan 2004 19:41
Very Nice Seems very accurate to me.
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 24th Jan 2004 20:44
damn good work!


GO TO THE ETERNAL DESTINY FORUMS!!! http://forums.eternaldestinyonline.com
Do it now!!!
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 24th Jan 2004 21:03
Thanks. I have now uploaded an exe (.rar format) for anyone without dbpro, also I have changed the code a bit, the friction doesn't use curvevalue() now, there is another row of balls and the balls lose energy when they hit each other. I'm hoping this proves for a more realistic demo :S.

Do you bite your thumb at me sir?

Athelon XP 1600 Plus (1.4ghz) - ATI Radeon 9600 Pro - 256mb RAM
Uber Krystoff
20
Years of Service
User Offline
Joined: 3rd Feb 2004
Location:
Posted: 6th Feb 2004 20:31
"in real life there are infinate collision checks..."
actually there aren't... i think...

Einstien's theory of general realativity says that nothing can go faster than the speed of light and that things moving faster move slower through time. This is because its just like in DB. assuming you have to objects moving at two different speeds, one at 10mph, the other at 5mph. the the universe has a giant loop and is revolving, every other loop the 10mph object moves 1 unit, and every 4th time the 5mph object moves a unit.

move object 1,10
move object 2,5

see the similarity? assuming this and that the speed of light is moving every single revolution of the code we can determain that the sync rate of the universe is:
S=sync rate
C=speed of light
U=single unit in space
M=one mile (c being in miles per second)
S=c*(M/U)

so the universe has a limited sync rate... hmmm god must be one good programmer to have made the whole thing in 7 days.... wow.

mebbe hes the archietect

There are 10 types of people in the world, those who understand binary and those who don't.
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 6th Feb 2004 20:42
K, that had nothing to do with my code , though it was interesting to hear. But who says light, or anything, moves in steps? What if they all move in infinitly small steps all the time, ie. constantly.

Do you bite your thumb at me sir?
The Basics of DBPro Tutorial, on my site now!
Athelon XP 1600 Plus (1.4ghz) - ATI Radeon 9600 Pro - 256mb RAM
D Man
21
Years of Service
User Offline
Joined: 3rd Oct 2002
Location: Germany
Posted: 6th Feb 2004 20:49
That would be not possible assuming that the quantum theory is true .

God is real, unless declared integer.
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 6th Feb 2004 21:17
K, I don't have a clue about that though. Science in yr 11 is crap.

Do you bite your thumb at me sir?
The Basics of DBPro Tutorial, on my site now!
Athelon XP 1600 Plus (1.4ghz) - ATI Radeon 9600 Pro - 256mb RAM
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Feb 2004 21:52 Edited at: 6th Feb 2004 21:55
Quote: "god must be one good programmer to have made the whole thing in 7 days.... wow."


Centuries later, we're still awaiting the patch.

But in theory, anything travelling faster than light would distort its shape. There was an example I saw once stating that a 20ft pole could fit length-wise completely inside a barn only 15ft in depth. If you could move the pole through the barn at whatever the insane speed was, theoretically the entire pole would be inside the barn for a fraction of a nanosecond. But now we're just getting off topic.

I looked through your code, but I don't quite get this line.
FOR l=1 TO numSteps

It controls accuracy in what aspect?

"eureka" - Archimedes
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Feb 2004 21:58
Dummy me, I should've read the whole post. I see what you did.

"eureka" - Archimedes
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 23rd Feb 2004 23:00
Pretty good,abit buggy with some angles..or it may have just been the friction I adjusted,I got balls moving continuasly till they hit something using tableFriction AS FLOAT = 0.0005

And I dunno how you got this to run initially,as there is an endif that shouldnt be there in the code!!...........


The endif before the Next i shouldnt be there, should be deleted..

djwheeler
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 23rd Feb 2004 23:28
0.0005 friction is hardly anything at all :S thats why the balls didnt appear to slow down .

The endif is meant to be there. I'll show you...

`If the loop is on the last step...
IF l=numSteps : `1 ifs open
`Draw graphics
IF x=1 : `2 ifs open
INK RGB(255,255,0),0
ELSE
INK RGB(255,255,255),0
ENDIF : `1 ifs open

CIRCLE balls(x).xPos,balls(x).yPos,ballRad
IF MOUSECLICK()=1 THEN LINE balls(1).xPos,balls(1).yPos,balls(1).xPos+SIN(shotAng)*shotPower*3,balls(1).yPos+COS(shotAng)*shotPower*3 : `This if has a then, therefore it doesnt need an endif

`Control ball friction
totalVel = SQRT(balls(x).xVel^2+balls(x).xVel^2)
DEC balls(x).xVel,tableFriction*totalVel*(balls(x).xVel/totalVel)
DEC balls(x).yVel,tableFriction*totalVel*(balls(x).yVel/totalVel)
ENDIF : ` No ifs open, et voila

Trying is the first step towards faliure.
The Basics of DBPro Tutorial, on my site now!
Athelon XP 1600 Plus (1.4ghz) - ATI Radeon 9600 Pro - 256mb RAM
Raver
20
Years of Service
User Offline
Joined: 7th Dec 2003
Location: leeds
Posted: 24th Feb 2004 20:14
Well,thats very interesting, because if I put the endif back in,it says comand line out of place error!! If I take the endif out its fine!

So really it beats me!! Whats this code for, is it DBpro or DB Classic?? And I have to set the friction to that to make the ball go any reasonable distance!!

djwheeler
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 24th Feb 2004 22:37
It's DBPro of course, wouldn't work in classic. Very odd.

Trying is the first step towards faliure.
The Basics of DBPro Tutorial, on my site now!
Athelon XP 1600 Plus (1.4ghz) - ATI Radeon 9600 Pro - 256mb RAM
xtom
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 18th Mar 2004 18:38
Very nice. If I have time I might expand this into a mini multiplayer pool game. Would be a nice little game to play in work when things are quiet.

Login to post a reply

Server time is: 2024-05-11 11:33:41
Your offset time is: 2024-05-11 11:33:41