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 5 of 5

Thread: Simple collision question?

  1. #1
    Intern Contributor
    Join Date
    Mar 2000
    Posts
    94

    Simple collision question?

    Is there an easy way to do collision in OpenGl. I'm not talking complex 3D collision....

    I've written a very simple(if not crude) game with a bouncing ball(actually a squae) that bounces around the screen and tries to hit squares at the top...you have a moving platform to catch and reflect it at the bottom(remeber Arkanoid?)....Anyway, I can't sem to get anywhere near accurate results. Everything is drawn with Quads..the platform, the "ball" and the blocks at the top of the screen(all in 2D) This is how I do my testing...

    I test whether the upper left corner of the bouncing block is greater then the lower right corner of the target and if the upper right corner of the bouncing block is less than the lower right corner of the target and if the top of the block is equal to the bottom of the target.....(And that's just for the bottom side of the target!)

    I'm sure that sounds confusing and very crude testing but it's the only way I could think of doing it(obviously I'm a begginner=).

    So, is there anyway I can define a region of my screen and have OpenGl keep up with whether my little block is whithin that region? (Sorry about all the details) Any help would be greatly appreciated...Is there a GLUT function call or something?

  2. #2
    Junior Member Regular Contributor
    Join Date
    Feb 2000
    Posts
    154

    Re: Simple collision question?

    Well, no.

    OpenGL draw suff, do your own collision checks.

  3. #3
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Stafford, UK
    Posts
    60

    Re: Simple collision question?

    2d collision is fairly simple. For each object have a centre point and a radius. To check whether a collision has occured measure the distance between the centre point of an object and all other objects and compare the distance to that of the object with the smallest radius. If the distance is equal to or less than the radius then a collision has occured.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Mar 2000
    Location
    Aurora, Illinois, USA
    Posts
    192

    Re: Simple collision question?

    i don't remember but someone posted a link to nice 3d collision detection web page up...

    it was a few days back
    Navreet Gill [img]/forum/images/%%GRAEMLIN_URL%%/smile.gif[/img]

  5. #5
    Intern Newbie
    Join Date
    Mar 2000
    Location
    UK
    Posts
    36

    Re: Simple collision question?

    Actually there is an OpenGL way of doing things although you probably won't like it.

    Basically you can use the "selection" mode (I don't have time to explain it all here, but you should be able to find links on it somewhere!)

    What you do is set up four clipping planes (or more) that defines the shape of your ball. Then enter selection mode. Draw all of the walls (using the glLoadName() function for each one). Then look into the selection buffer, to see which wall (if any) has been collided with.

    This is a pretty awquard solution to a fairly simple problem though. I'd stick with the method David mentioned.

Posting Permissions

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