Need help detecting collision - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need help detecting collision

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 :-)

Comments

Sign In or Register to comment.