# 2D polygon intersection problem

I have to make a 2D game but I have not learnt collision detection. Are there any functions in OpenGL/GLUT lib that is able to detect if a polygon intersects or so called “collide” with each other??
If there isnt then what can I use for this intersection detection ??

For example the player must not walk through walls and objects. Not sure if polygon intersection is the right stuff to use for this case. If there are better methods out there please tell me about it

opengl is just a graphic library and it has nothing to do with collision detection.
There is a lot of collision detection library on the net like OPCODE : http://www.codercorner.com/Opcode.htm

to do collision detection, u should create a bounding box or bounding sphere for each object in the virtual scene and then test if this boxes or spheres collide together.

#ifdef COLLISION
float tmp_dx, tmp_dy;
for(int k=0; k<BNUM-1; k++){
for (int l=k+1; l<BNUM; l++){
if((ball[k].x+BSIZE > ball[l].x-BSIZE && ball[k].x-BSIZE < ball[l].x+BSIZE)&&
(ball[k].y+BSIZE > ball[l].x-BSIZE && ball[k].y-BSIZE < ball[l].y+BSIZE)){
if(ball[k].x - ball[l].x > ball[k].y - ball[l].y){
if(ball[l].x > ball[k].x){
ball[l].x=ball[k].x+2BSIZE;
}else{
ball[l].x=ball[k].x-2
BSIZE;
}
tmp_dx=ball[l].dx;
ball[l].dx=ball[k].dxPERCENT_AFTER_BOUNCE;
ball[k].dx=tmp_dx
PERCENT_AFTER_BOUNCE;
}else{
if(ball[l].y > ball[k].y){
ball[l].y=ball[k].y+2BSIZE;
}else{
ball[l].y=ball[k].y-2
BSIZE;
}
tmp_dy=ball[l].dy;
ball[l].dy=ball[k].dyPERCENT_AFTER_BOUNCE;
ball[k].dy=tmp_dy
PERCENT_AFTER_BOUNCE;
}
num_bounce++;
ball[k].collided=1;
ball[l].collided=1;
break;
}
}
}
#endif

try this. Only strange phenomenon it has is it only works for top-left half triangle of a rectangle. :S