Hiy guys,
I am working on a game and I want my space craft to have 6 shields
(front,front right, rear right, rear, etc.)
The problem is doing the collision detect, I have code which is fast for
checking if the shields are hit at all but finding the angle of the
collision is non trivial.
I basicly check a line against a circle with this code, this includes
scaling code but don't worry about that, the circle has radius s
// screen position of object
x3=((list[i]->x/vs)*202)+202;
y3=((list[i]->y/vs)*235)+235;
x1=202;
y1=235; // start point of line
x2=202+(500*cos(a1));
y2=235+(500*sin(a1)); // end point of line
u =(x3 - x1)*(x2 - x1) + (y3 - y1)*(y2 - y1);
u/=(x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
if ((u>=0)&&(u<=1))
{
xi = x1 + u *(x2 - x1);
yi = y1 + u *(y2 - y1);
r=sqrt(((xi-x3)*(xi-x3))+((yi-y3)*(yi-y3)));
if (r<=s)
{
// hit
}
}
I know I can get rid of the sqrt but the problem is a line intersects a
circle at two points and I need to find out the first point impacted.


|