View Full Version : Collision Detection

01-05-2013, 05:01 AM
Hi I am making a 3D game where a ball is kicked towards a wall with 3 targets which have points in them.

I am looking to do a collision detection with 2 sphere the ball and the target.

I am using gluPerspective(45.0f, fAspect, 1.0, 600.0);

void ball(void)
GLUquadricObj *qobj;
qobj = gluNewQuadric();
glTranslatef(40.0, -30.0, 200.0);
glColor3f(1, 1, 1);
gluSphere(qobj, 5, 50, 50);

void fivePoints(void)
GLUquadricObj *qobj;
qobj = gluNewQuadric();
glTranslatef(16, -4, -120);
gluQuadricNormals(qobj, GLU_SMOOTH);
glColor4f(1, 1, 1, 1);
gluSphere(qobj, 5, 50, 50);

How would I do the code in order to make it collide so if the ball hits the target the ball returns back to its original place.

Also I would like to do collision detection with the front wall so if the ball hits the front wall the ball should also return back to the same place.

void Wall(void)
glVertex3f(-120.0, -50.0, -500.0);
glVertex3f(-120.0, 50.0, -500.0);
glVertex3f(120.0, 50.0, -500.0);
glVertex3f(120.0, -50.0, -500.0);

Thanks in advance

01-05-2013, 07:19 AM
This is not an OpenGL question. OpenGL is for graphics - it draws stuff.

http://www.gamedev.net/forum/20-math-and-physics/ would be a more appropriate place to ask ... or google for simple examples.

For example: http://nehe.gamedev.net/tutorial/collision_detection/17005/ (did not read any of it myself, but glancing it - it seems to contain what you ask for).