нашол вот такое...
The simplest form of collision-detection I know of uses bounding circles. I'm assuming you're doing a 2-Dimensional game but the same procedure works just as well in 3D (except then they're called bounding spheres, not circles!).
Let's say every moving piece of your game is represented by a GameObject class, which has an x and a y co-ordinate, plus a radius that describes a circle big enough to completely surround the GameObject. You keep all your GameObjects in an array:
GameObject[] objects;
Collision Detection can be computationally expensive if you have a lot of moving objects because in the exhaustive case you have to compare every object with every other object.
int i,j,dx,dy,r1s;
GameObject g1, g2;
for ( i = 0 ; i < objects.length-1 ; i ++ ) {
g1 = objects[i];
// calculate the radius squared
r1s = g1.radius * g1.radius;
for ( j = i+1 ; j < objects.length ; j ++ ) {
g2 = objects[j];
// calculate the distance between the 2 objects
dx = g1.x - g2.x;
dy = g1.y - g2.y;
// if the distance squared is less than both of
// the radii squared, the circles overlap (collision!)
if ( ( (dx * dx) + (dy * dy) ) < ( r1s + (g2.radius * g2.radius) ) ) {
doCollision( g1, g2 );
}
}
}
This is the easiest way to do things, but of course it only works well with objects that are perfectly round ( PacMan ! ). What you should do if you need more accurate Collision Detection is use this method first to see if any of the bounding spheres overlap. If they do, use a more precise (and more computationally intensive) C.D. method like line or polygon intersection.
|
если я правильно перевожу, то здесь пишется что ето для круглых обектов тоесть центром столкновения есть точка(не полигоны)?
меня впринцыпе ето устраивает... ещёбы ктото обяснил как ето использовать в програме))