PDA

View Full Version : Simple collision question?



Ace_Man
04-02-2000, 09:20 PM
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?

AndersO
04-02-2000, 11:21 PM
Well, no.

OpenGL draw suff, do your own collision checks.

David
04-02-2000, 11:48 PM
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.

ngill
04-04-2000, 05:31 AM
i don't remember but someone posted a link to nice 3d collision detection web page up...

it was a few days back

FATBUDDHA
04-04-2000, 06:58 AM
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. http://www.opengl.org/discussion_boards/ubb/smile.gif