Kmullins:I am a little confused about the "'contactPointToballCenter" that Steve mentioned.... Also, I've never taken any physics classes but could you point me in the right direction on the term "Resolution Velocity" you mentioned?
contactPointToBallCenter was a descriptive name that represents a vector between the spot on the ball that first contacts an object to the ball's center of mass. Usually it is called the "collision Normal" or "contact Normal". It is used to help determine the "rebound" or "deflection" direction that the ball will travel after collision. That direction is what I referred to as resolution Velocity (as in "collision resolution"). The velocity vector the ball takes after the collision.
Here's why finding the collision normal is important. If a ball is rolling towards a wall but at an angle (not perp, not parallel), there is a component of it's velocity that is parallel to the wall and a component of its velocity that is perpendicular to the wall. These two components add up to make up the ball's velocity vector. After collision, only the component that is perpendicular to the wall is reversed. The component that runs parallel remains as it was. If the wall happened to run along the x axis (and your working a 2d game) then the after collision velocity is (x,-y) where (x,y) was the velocity before the collision. So when the wall runs along x, or y axis, it is relatively easy to resolve the new velocity. But when the wall runs along at an arbitrary angle, you must use a coordinate framework that relates the velocity components not to x & y but to that of parallel & perpendicular so that after collision you can reverse the perpendicular component. The "collision normal" or "contactPointToballCenter" is part of that perpendicular component. Now, unlike a wall, when two balls collide, they do not reverse their perpendicular components but they trade perpendicular components with each other(assuming equal mass). Both of their parallel components remain just as before the collision. When this trade occurs, it looks just like two pool balls hitting each other would.
Here is a link to a site that gives a basic overview
here is code I use to separate the balls at collision for secondary collisions only. For a primary collisions (cue ball to target ball) I back the cue ball up along its velocity vector just far enough to where they touch. In pool, luckily, the target ball is always stationary for a primary collision.
| 1 |
//determine collision normals |
| 2 |
Vector3 iNorm = spheres[h].currentState.position - spheres[i].currentState.position; |
| 3 |
float distance = iNorm.Length(); |
| 4 |
iNorm.Normalize(); |
| 5 |
Vector3 hNorm = Vector3.Normalize(spheres[i].currentState.position - spheres[h].currentState.position); |
| 6 |
|
| 7 |
//reposition balls to not penetrate |
| 8 |
float penetration = radiusSum - distance; |
| 9 |
spheres[i].currentState.position -= 0.5f * penetration * iNorm; |
| 10 |
spheres[h].currentState.position -= 0.5f * penetration * hNorm; |
This is not accurate enough for realistic collision resolution but accurate enough for all those secondary balls colliding on the pool table and maybe accurate enough for your use.