   Collision Detection
  I am trying to program a pong game, and I am using openGL and Glut for the graphics.In my main loop I draw the sprites and then test to see if they have collided, if so then I alter the velocites, either way I add to the coords of the ball and then redraw (to move the ball). Now, when I comment out the collide condition the ball moves across the screen fine, except it goes through the paddle. When I uncomment out the collide test, however, the ball just stays in the center, yet I can still move the paddles so the redraw portion is being exectuted properly. It seems as though the code after the test is not being executed. I am also lead to believe there is a problem with my collide function. Everything in the game is rectangluar even the ball (for now) and are initialize in a struct fyi. Here are my functions:bool Collide(Rect *object1, Rect *object2) { float left1, left2;    float right1, right2;    float top1, top2;    float bottom1, bottom2;    left1 = object1->x1 + object1->col_x_offset;    left2 = object2->x1 + object2->col_x_offset;    right1 =object1->x2 + object1->col_width;    right2 =object2->x2 + object2->col_width;    top1 = object1->y1+ object1->col_y_offset;    top2 = object2->y1 + object1->col_y_offset;    bottom1 = object2->y1 + object1->col_height;    bottom2 = object2->y2 + object2->col_height;    if (bottom1 < top2) return true;    if (top1 > bottom2) return true; if (right1 < left2) return true;    if (left1 > right2) return true;    return false;}void display(void){ glClear(GL_COLOR_BUFFER_BIT);  glClearColor(0.0,0.0,0.0,1.0);  glPushMatrix();  glBegin (GL_LINES);   glVertex2f(-3.0, 1.3);   glVertex2f(3.0, 1.3);   glVertex2f(-3.0,-1.3);   glVertex2f(3.0,-1.3); glEnd ();    glPopMatrix();  glPushMatrix(); glBegin(GL_QUADS);   glVertex3f(Paddle1.x1,Paddle1.y1,0.0);   glVertex3f(Paddle1.x1,Paddle1.y2,0.0);   glVertex3f(Paddle1.x2,Paddle1.y2,0.0);   glVertex3f(Paddle1.x2,Paddle1.y1,0.0);glEnd();    glPopMatrix(); glPushMatrix();glBegin(GL_QUADS);   glVertex3f(Paddle2.x1,Paddle2.y1,0.0);   glVertex3f(Paddle2.x1,Paddle2.y2,0.0);   glVertex3f(Paddle2.x2,Paddle2.y2,0.0);   glVertex3f(Paddle2.x2,Paddle2.y1,0.0);glEnd();    glPopMatrix(); glPushMatrix(); glBegin(GL_QUADS);   glVertex3f(ball.x1,ball.y1,0.0);   glVertex3f(ball.x1,ball.y2,0.0);   glVertex3f(ball.x2,ball.y2,0.0);   glVertex3f(ball.x2,ball.y1,0.0);glEnd();    glPopMatrix(); if (Collide(&ball,&Paddle1)){vx=-vx;vy=-vy;}    ball.x1=ball.x1+vx;   ball.x2=ball.x2+vx;   ball.y1=ball.y1+vy;   ball.y2=ball.y2+vy;glutSwapBuffers();}If anyone could provide me with any ideas that would be a huge help.Thanks   
  if (bottom1 < top2) return true;if (top1 > bottom2) return true;if (right1 < left2) return true;if (left1 > right2) return true;Reconsider this part of the Collide function.I haven't tested this on a machine but try replacing it with:if ((bottom1 < top2) || (top1 > bottom2))if ((right1 < left2) || (left1 > right2)) return true;edit: changed && to ||[Edited by - DrewGreen on June 2, 2006 12:55:05 PM];  should those be two seperate conditions which both return true or all one nested if statement?   ;  Come to think of it the &&s should probably be ||s.It's one nested statement. Sorry I should have explained - separating them out will lead to this implementation returning true in cases where there is no collision taking place. For example when the ball & paddle bounding box/collision rectangles satisfy the conditions for x (i.e. left & right) but not for y (top & bottom):  o ---or vice versa: ---    oA collision would be detected every time the two objects occupied rougly the same space on either the x or y axis. My fantastic ascii art shows a scenario where this would return true (more importantly, the ball would never go out of play)What you're after is the area where both of these are true (i.e. the intersection)[Edited by - DrewGreen on June 2, 2006 12:24:15 PM];  Yeah,I get the idea now, I guess just sitting down and being logical about it does work. The problem was that the function was over returning trues and thus the ball's velocity was constantly being reversed which lead to it not moving from the center of the screen.Thanks alot for your help.   