Handling circle collisions

Started by
12 comments, last by ketek 18 years, 3 months ago
If savagebeastx doesn't use some weird graphics API, then the origin is most likley at the upper left corner of the window.
[s]--------------------------------------------------------[/s]chromecode.com - software with source code
Advertisement
No, the origin is in the center. I'm using OpenGL. The big circle is at the center.
Oh, ok. It looked like some window API graphics.
[s]--------------------------------------------------------[/s]chromecode.com - software with source code
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 topic is closed to new replies.

Advertisement