Results 1 to 6 of 6

Thread: Collision detection

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2002
    Location
    Kristiansand,Norway
    Posts
    25

    Collision detection

    Hi!

    If I have e.g one ball and three boxes moving around in an OpenGL application, I'd like to detect when the ball collides with the various boxes.

    I would like to know which box the ball has collided into, and perform some actions based on this.

    Can anyone guide me to a nice tutorial on this? Or maybe you can even give me a code snippet?

    Thanks!!

    Best regards,
    Torbjørn

  2. #2
    Senior Member Regular Contributor
    Join Date
    May 2002
    Location
    York, UK
    Posts
    128

    Re: Collision detection


  3. #3
    Junior Member Newbie
    Join Date
    Sep 2002
    Location
    Kristiansand,Norway
    Posts
    25

    Re: Collision detection

    I think I have gotten a bit further by reading lesson 30 at nehe.gamedev.net.

    My application makes it possible to actually just use speres. For each frame I can check if the distance between e.g. two balls is smaller than radiusBall_1+radiusBall_2.

    I guess I can use this function:
    void gluSphere( GLUquadricObj *qobj,
    GLdouble radius,
    GLint slices,
    GLint stacks )

    for drawing the spheres, but how can I check the position of the spheres at each frame?

    Is there some function like
    "glGetPosition(GLUquadricObj *qobj)" existing?

    So: How can I check the position of the sphere?

    Thanks!

    Torbjørn

  4. #4
    Senior Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    184

    Re: Collision detection

    you need to keep track of the balls position yourself. maybe make some kind of structure like this:
    Code :
    typedef struct
    {
       float posx, posy, posz;
    }object_t;
    and have one instance of object_t for each sphere. when you move the sphere's, change the values in the struct. then to draw them, translate to the position. that way you'll know where all the balls are at any given time.

    b

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Collision detection

    Maybe you should go back through the lesson's 1 to 30....

    You would see how to keep track of an object, via variables.

    example:

    GLfloat object[2][3]; create two objects with 3 variables.

    object[0][0] = x data object 1
    object[0][1] = y data
    object[0][2] = z data

    object[1][0] = x data object 2
    object[1][1] = y data
    object[1][2] = z data

    // moving things around.
    // First object, note when accessing a array, it starts at 0 not 1.
    glPushMatrix();
    glTranslatef( object[0][0], object[0][1], object[0][2]); // move our object
    gluSphere( .............); // add relivent data for sphere.
    glPopMatrix();

    // Draw second sphere
    glPushMatrix();
    glTranslatef( object[1][0], object[1][1], object[1][2]); // move our object
    gluSphere( .............); // add relivent data for sphere.
    glPopMatrix();


    Originally posted by torbjorn:
    I think I have gotten a bit further by reading lesson 30 at nehe.gamedev.net.

    My application makes it possible to actually just use speres. For each frame I can check if the distance between e.g. two balls is smaller than radiusBall_1+radiusBall_2.

    I guess I can use this function:
    void gluSphere( GLUquadricObj *qobj,
    GLdouble radius,
    GLint slices,
    GLint stacks )

    for drawing the spheres, but how can I check the position of the spheres at each frame?

    Is there some function like
    "glGetPosition(GLUquadricObj *qobj)" existing?

    So: How can I check the position of the sphere?

    Thanks!

    Torbjørn

  6. #6
    Junior Member Newbie
    Join Date
    Sep 2002
    Location
    Kristiansand,Norway
    Posts
    25

    Re: Collision detection

    Thanks guys!

    I guess I should run through all of the nehe-lessons

    Anyway, I think I'll be able to solve my task now!

    Thanks!

    Torbjørn

Similar Threads

  1. Collision Detection
    By ardalanbiz in forum OpenGL: General
    Replies: 5
    Last Post: 02-07-2004, 02:49 PM
  2. Collision detection.... please help
    By Music_Man in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 11-28-2002, 06:38 PM
  3. collision detection
    By imported_robert in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 02-17-2001, 03:09 AM
  4. collision detection
    By chip in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-08-2000, 07:09 AM
  5. collision detection contest: collision crazy
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-19-2000, 02:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean