PDA

View Full Version : Need help detecting collision



dellatorre
02-07-2010, 07:45 AM
I have a moving cube and a fixed cube. I'm trying to figure out how to detect when my moving cube hits the fixed cube.

here is my moving cube:

//red car
//back
glColor3f( 1, 0, 0 );
glBegin( GL_POLYGON );
glVertex3f( -1,3,-1 );
glVertex3f( 1,3,-1 );
glVertex3f( 1,5,-1 );
glVertex3f( -1,5,-1 );
glEnd();
//bottom
glColor3f( 1, 0, 0 );
glBegin( GL_POLYGON );
glVertex3f( -1,3,1 );
glVertex3f( 1,3,1 );
glVertex3f( 1,3,-1 );
glVertex3f( -1,3,-1 );
glEnd();
//right
glColor3f( 1, 0, 0 );
glBegin( GL_POLYGON );
glVertex3f( 1,3,-1 );
glVertex3f( 1,3,1 );
glVertex3f( 1,5,1 );
glVertex3f( 1,5,-1 );
glEnd();
//left
glColor3f( 1, 0, 0 );
glBegin( GL_POLYGON );
glVertex3f( -1,3,1 );
glVertex3f( -1,3,-1 );
glVertex3f( -1,5,-1 );
glVertex3f( -1,5,1 );
glEnd();
//top
glColor3f( 1, 0, 0 );
glBegin( GL_POLYGON );
glVertex3f( -1,3,-1 );
glVertex3f( 1,3,-1 );
glVertex3f( -1,3,-1 );
glVertex3f( -1,3,1 );
glEnd();
//front
glColor3f( 1, 0, 0 );
glBegin( GL_POLYGON );
glVertex3f( 1,3,1 );
glVertex3f( -1,3,1 );
glVertex3f( -1,5,1 );
glVertex3f( 1,5,1 );
glEnd();

glEnable( GL_TEXTURE_2D);


and my fixed cube:

glPushMatrix();
glDisable(GL_TEXTURE_2D);
glTranslatef(-30.0, -50.0, -20.0);
glutSolidCube(3.0);
glEnable(GL_TEXTURE_2D);
glPopMatrix();

can anyone help me with this? thanks