Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Collision Detection

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    12

    Exclamation Collision Detection

    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)
    {
    glBegin(GL_QUADS);
    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);
    glEnd();
    glFlush();
    }

    Thanks in advance

  2. #2
    Intern Contributor
    Join Date
    Jul 2006
    Posts
    72
    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/col...tection/17005/ (did not read any of it myself, but glancing it - it seems to contain what you ask for).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •