No, Jonathan, but you were CLOSE
What you would have to do is the following
typedef struct
{
int x,y,radius;
}OBJECT;
OBJECT stuff[2];
Should this work?
typedef struct
{
int x,y,radius;
}OBJECT;
OBJECT stuff[2];
if ((stuff[1].x-stuff[2].x)^2+(stuff[1].y-stuff[2].y)^2) <= (stuff[1].radius + stuff[2].radius)^2
{
// we have a collision
}
Hope I''ve helped.
FReY
Collision detection
Ooops, the above should''ve read as follows:
----------------------------------------------------------------------------------------
typedef struct
{
int x,y,radius;
}OBJECT;
OBJECT stuff[2];
if ((stuff[1].x-stuff[2].x)^2+(stuff[1].y-stuff[2].y)^2) <= (stuff[1].radius + stuff[2].radius)^2
{
// we have a collision
}
----------------------------------------------------------------------------------------
Hope I''ve helped.
FReY
----------------------------------------------------------------------------------------
typedef struct
{
int x,y,radius;
}OBJECT;
OBJECT stuff[2];
if ((stuff[1].x-stuff[2].x)^2+(stuff[1].y-stuff[2].y)^2) <= (stuff[1].radius + stuff[2].radius)^2
{
// we have a collision
}
----------------------------------------------------------------------------------------
Hope I''ve helped.
FReY
Thanx!
That should be pretty fast right?
btw. how do u check if the "circle" hits a wall?
========================
Game project(s):
www.fiend.cjb.net
Edited by - JonatanHedborg on 5/6/00 4:58:30 AM
That should be pretty fast right?
btw. how do u check if the "circle" hits a wall?
========================
Game project(s):
www.fiend.cjb.net
Edited by - JonatanHedborg on 5/6/00 4:58:30 AM
The way to do that would be to find the distance from the centre of the object to the line/interval , and compare this distance with your bounding circle''s radius (if it is less than the radius, a collision has occurred)
Sorry I can''t remember the formula for distance from a point to a line off the top of my head (too early in the morning here )... it should be pretty easy to find though.
-------------
squirrels are a remarkable source of protein...
Sorry I can''t remember the formula for distance from a point to a line off the top of my head (too early in the morning here )... it should be pretty easy to find though.
-------------
squirrels are a remarkable source of protein...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement