Archived

This topic is now archived and is closed to further replies.

dynamicman

pool balls

Recommended Posts

As a small note, I am very new to this "physics" stuff. This is more of a question regarding architecture though.. I am playing pool and lets say I am breaking. This will result in a sort of domino effect (one ball hits another, but hits another.. then hits another..etc). The moving object (the cue ball) will exert a force on a set of ball(s) (on first contact). callback system: When a ball is hit, we call a callback function for the "hit" ball, tell it what force is acting on it and let it decide what to do. This is done recursively to calculate the new positions of each ball as one ball hits another (domino effect). 1) are there any drawback to this method? 2) Something that I am not aware of (eg. is it that strait forward)? 3) Are there other methods for solving this sort of problem? correct me if I''m wrong.. but this goes under rigid body linear physics correct?

Share this post


Link to post
Share on other sites
I guess a followup delema is how an actual physics engine will handle this sort of task? I''ve seen in many articles/books the following:

while(game not done){
-grab input
-...
-update new positions
-handle physics
-...
-render
}

But this does not seem to be an effective way of handling physics. Physics is not a step on its own, but integrated into the "update new positions" step am I not right?

eg. you do not update your physics.. you handle them as part of your position updates.

Share this post


Link to post
Share on other sites
Doing them in separate steps is not a perfect approach, but often it''s good enough. I did my physics code that way. The point is that you have a very tiny change in time between each frame, and update your world in tiny steps. Correct me if I am wrong, but that is even a "real" mathematical method called Euler integration.

About that recursive callback thing, it probably will work, but be sure that you don''t get infinite loops. (Ball 1 hits ball 2, ball 2 hits ball 3, ball 3 hits ball X and ball X hits ball 1.)

The simplest method (but quite unefficient) is to check each object separately, and apply all the forces on it, not caring what happens to the others. Let''s call it "Who hit me?". Your approach is the inverse of this: "Who did I hit?"

In my physics code, I go through all possible collisions, not through all objects, and apply the collision forces to both of the colliding objects at once. Newton was nice enough to prove that the forces affecting both objects are equally strong, so I only need to calculate them once. This method can of course be applied to your recursive system too. I just have a bad feeling about the callbacks. It sounds a little complicated, and bug-catching.

Share this post


Link to post
Share on other sites
So what your saying is for every object (in this case a ball) instead of directly moving the ball and trying to affect other things in the world (eg pool table), we collect all forces applied to that ball which includes its forward momentum and move it accordingly?

-for all balls a
--calculate its forward velocity and store it
--for all other balls b
---store ball b''s force exterted onto ball a and store it.
--with all the forces stored, calculate the position of ball a

Is this the right idea?

Share this post


Link to post
Share on other sites
If you''re new to physics, then your approach is a good first start, though as juuso says you will need very small time steps to minimize numerical problems.

If you do not handle the case of collision stacks or "simultaneous interlocking contact" (multiple objects in contact with one another simultaneously such that some of the objects cannot move independent of the others) then there is a high likelihood that you will simulate some inconsistent motion. But to deal with collision stacks properly requires a much more sophisticated approach that you won''t be able to code until you gain some experience with the simpler methods.

http://d6.com/users/checker/dynamics.htm

You can find a BUNCH of software tools and research papers here on the subject. This is mostly very advanced material, but you may find it helpful or interesting.

http://www.cs.unc.edu/~geom/collide/index.shtml





Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites
I''m currently making a physics sim for billiards and this is the way I did it.

Each frame calculate the time delta between frames.

Calculate the movement vector for each ball by multiplying its velocity vector by the time delta.

Loop through every combination of balls and test if their movement vectors intersect such that they will collide (essentially have to do calculations in 3 dimensions, 2D dimensions of pool table + time). Create a list of all detected collisions and the number of seconds until they occur. Then select the collision that will occur first, update all balls by their velocity vector * number of seconds until first collision. Then update the velocity vectors of the 2 colliding balls accordingly, then subtract the number of seconds that elapsed from the frame time delta. Continue this process until the frame time delta = 0. Then draw the balls, and move onto the next frame.

If no collisions are detected you can update the positions of all balls by their movement vector and proceed to the next frame.

Currently my code does not take into account friction, but it should be easy to add this in when doing the movement calculations.

Share this post


Link to post
Share on other sites
From the info you guys have given me, it seems like it is very important to find the first point of impact in any system and generally handle collision detection with respect to a list of ordered contacts. This would be an accurate way of simulating a system. (please correct me if I''m wrong)

Other cases involve hittubg two things at the same time, but these cases depend on accuracy more than anything (eg. an epsilon).

The fast and dirty (but might not be the most accurate) way is to calculate collision per object (rather than ordered per collision). This is the method which I sort of outlined above. I''m thinking this is faster because there is no extra sorting and logic involved.

Thanks for all your help guys! I''ve learned something.

Share this post


Link to post
Share on other sites