Handling circle collisions
If savagebeastx doesn't use some weird graphics API, then the origin is most likley at the upper left corner of the window.
this is the function i use to detect collision beetween spheres
this function uses the concept of midrange osculation plane
( i don't know how else to call it ).
Note that this function gives correct result even
with high speed for both spehres.
int C2DPhysicEngine::SphereSphereCollTest( CParticle *A,
CParticle *B )
{
Vector P,Q,Dir,MidPoint;
double eps = 0.000001f;
Dir = A->Position-B->Position;
Dir.Normalise();
P=B->Position+B->GetRadius()*Dir;
Q=A->Position-A->GetRadius()*Dir;
MidPoint = ( Q + P ) *0.5f;
if ( ( MidPoint-P ) * Dir <= eps )
{
// length of vector
Vector W=Q-P;
// relative penetration depth
Vector RelDist=W.Length()*Dir;
// sphere collided , handle
// repositioning and collision response
return 1;
}
return 0;
}
this function uses the concept of midrange osculation plane
( i don't know how else to call it ).
Note that this function gives correct result even
with high speed for both spehres.
int C2DPhysicEngine::SphereSphereCollTest( CParticle *A,
CParticle *B )
{
Vector P,Q,Dir,MidPoint;
double eps = 0.000001f;
Dir = A->Position-B->Position;
Dir.Normalise();
P=B->Position+B->GetRadius()*Dir;
Q=A->Position-A->GetRadius()*Dir;
MidPoint = ( Q + P ) *0.5f;
if ( ( MidPoint-P ) * Dir <= eps )
{
// length of vector
Vector W=Q-P;
// relative penetration depth
Vector RelDist=W.Length()*Dir;
// sphere collided , handle
// repositioning and collision response
return 1;
}
return 0;
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement