Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 16 December 1999 - 01:00 AM
Posted 13 December 1999 - 02:53 AM
-Good Luck!-
-SonicSilicon
Posted 15 December 1999 - 06:13 PM
Posted 16 December 1999 - 01:00 AM
personally, i would do it this way...
struct Coordinate2d
{
double x;
double y;
};
struct Ball
{
Coordinate2d Position;
Coordinate2d Velocity;
double Radius;
};
there could be more, but this simple model will let us do most of the physics we want to, (minus the really icky stuff dealing with spin and rotational effects)
we will further simplify our model by saying that there are no frictional effects.
and so, based on two balls with current positions, and current velocities, we know the following.
at time t, the position of a ball is
x=x0+dx*t, y=y0+dy*t, where x0,y0 is the original position, dx, dy representing the velocity of the ball, and t the time elapsed.
also, we know that the balls collide when the distance between them is the sum of their radiuses.
the distance formula: a*a+b*b=c*c
where a is the difference in x positions, and b is the difference in y positions, and c is the distance
so, for two balls, BallA, and BallB, here are some more equations:
(BallA.Radius+BallB.Radius)*((BallA.Radius+BallB.Radius)=( (BallA.Position.x+BallA.Velocity.x * t)-(BallB.Position.x+BallB.Position.x * t) ) * ( (BallA.Position.x+BallA.Velocity.x * t)-(BallB.Position.x+BallB.Position.x * t) ) + ( (BallA.Position.y+BallA.Velocity.y * t)-(BallB.Position.y+BallB.Position.y * t) ) * ( (BallA.Position.y+BallA.Velocity.y * t)-(BallB.Position.y+BallB.Position.y * t) )
now, you do a lot of expansion, and a lot of plugging and chugging, then you have to solve for t using the quadratic equation. if the solution for t is imaginary, then a collision will never occur. if there is a negative solution, ignore it. only a positive, real solution matters. if you have a positive, real solution, then the collision will occur at that time.
when a collision occurs, assuming a totally elastic collision, impart all of the momentum on one ball on the opposite ball, and the job is done.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.