Simple Billiard Physics?

Monkey Forums/Monkey Programming/Simple Billiard Physics?

zoqfotpik(Posted 2012) [#1]
Is there a function that someone has for simple round object collision, perhaps factoring in different sizes and masses?

I've looked around here and I'm not seeing one, but don't I remember some simple one from Max?

I don't quite need the Box2D level of precision or anything like that, but perhaps I should just bite the bullet and implement that. How difficult is it to get working?


muddy_shoes(Posted 2012) [#2]
Both Box2D and Fling come with demonstration code. As long as you're reasonably comfortable with high-school physics terminology, or at least willing to hit Google a few times while learning, it should be pretty easy to take one of the tests/demos and use it as a base for whatever you want to do.


Jesse(Posted 2012) [#3]
I made the pool game in the apps section without knowing any kind of physics or vector math. I had to google tutorials and learn what I now know. it is fun now but it was a pain gathering all of the information to study. specially when most of the information is very technical.
if you want to avoid all of the head aches of learning the subject you can download the basic example in the Blitzbasic code archives:

http://www.blitzbasic.com/codearcs/codearcs.php?code=415#comments

That is not going to get you the results for a decent pool game but it'll get you started.


zoqfotpik(Posted 2012) [#4]
Thank you.

I've implemented Verlet physics and back-stepping sphere collision in the past, I just don't want to worry with it right now. I'll check out your example and then probably end up installing Box2D.


zoqfotpik(Posted 2012) [#5]
Jesse, that link was just perfect for what I wanted. Eventually I will hook in Fling but right now that doesn't matter.


Gerry Quinn(Posted 2012) [#6]
Probably it's similar to the link above, but I found the following page:
http://codeflow.org/entries/2010/nov/29/verlet-collision-with-impulse-preservation/
very helpful for programming my Tilt Maze game.


Volker(Posted 2012) [#7]
programming my Tilt Maze game

I stopped my project in this direction, because
it's very hard to handle fast moving objects in Monkey
(Frame-rate instability).
http://www.monkeycoder.co.nz/Community/posts.php?topic=2152&


benmc(Posted 2012) [#8]
I wrote a Pool game for Android in Java a couple years ago, and had to work with really slow rendering problems of old devices.

To handle elastic ball collisions and the physics, on each update or render I would calculate how far each ball had to move in that step, then I would programatically calculate every baby-step each ball had to make from point A to B to check for collisions, so that way it didn't matter how slowly it rendered, the collisions would always happen correctly.

It turned into about 5-10 extra computations per ball per render, and it worked well.


Jesse(Posted 2012) [#9]
zoqfotpik glad it helped.

the pool game I have in the Apps section here uses elastic dynamic collision. The collision is calculated once per object to collided with and finds the exact(closest floating point possible) point of collision. it's not optimized since it checks for every object(wall and ball) for every ball. It would have been better to use tiles but it works fine as is. It finds the exact point of collision no matter how fast the balls are traveling checking with 26 walls and 15 balls.

I wrote most of the math and logic needed for the pool game in examples in the BlitzBasic code archives:

ball to line wall:
http://www.blitzbasic.com/codearcs/codearcs.php?code=2841

moving ball to moving ball:
http://www.blitzbasic.com/codearcs/codearcs.php?code=2843

ball to circle wall:
http://www.blitzbasic.com/codearcs/codearcs.php?code=2842

ball to arc wall:
http://www.blitzbasic.com/codearcs/codearcs.php?code=2858


Gerry Quinn(Posted 2012) [#10]
I had no real physics problems in Tilt Maze. I calculate the physics five times between frames. While I try to use the frame time as given by Millisecs(), I limit it to the range 33-100 ms.

Of course I'm using Flash, not to mention only a single ball, so HTML5 may have stuttering problems I didn't see.


zoqfotpik(Posted 2012) [#11]
To check for billiard collisions you could check for segment collisions of a rectangle with distance traveled as width and diameter of ball as height, then check the circles on both ends. Seems to me that would be a real quick way to do quick and dirty swept area collisions for balls.


Gerry Quinn(Posted 2012) [#12]
That's what I did, except that I treated balls as point objects and expanded the obstacles by the radius of the ball. So the ball is really a point bouncing between barriers that are larger than the visible ones.