Jump to content
  • Advertisement
Sign in to follow this  
Flawe

OpenGL 2D pixel collision detection

This topic is 4274 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

so I'm trying to play around with some small game thingy in OpenGL in 2D and I was wondering how can one do pixel-sensitive collision detection? I was thinking of having two layers, one for the background of the scene and one for the foreground with the objects that should collide. What's the best way of doing this? Is it by having multiple quads with a texture each or is it multi-texturing? Can you still do pixel-collision if you use multi-textures? Thanx

Share this post


Link to post
Share on other sites
Advertisement
I guess I am lost by what do you mean by pixel collision? If you mean that you want a object e.g. ship to collide with a wall? If so use a 2D array that holds all the objects locations and then you just test the current object's location to see if it hit with the other objects locations. But like I said I am unsure if thats what you are asking. HTH

Share this post


Link to post
Share on other sites
Well I'm using sprites so I'd like to test the pixels and not the bounding box/sphere. The alpha part of the texture should not be consider when doing the detection.

Share this post


Link to post
Share on other sites
Not sure if its possible or not, but why not split the sprites up into multiple bounding boxes, or any other way (there are more).

Share this post


Link to post
Share on other sites
I guess that's one way of doing it. Won't it be hard to keep track of the bounding boxes if I have complex animations which need that bounding boxes to move around a lot?

What other options do I have? Haven't done this sort of thing before so I'm greatfully for any ideas.

Share this post


Link to post
Share on other sites
Hidden
Quote:
Original post by Flawe
Well I'm using sprites so I'd like to test the pixels and not the bounding box/sphere. The alpha part of the texture should not be consider when doing the detection.

In my humble opinion, this is a bit overkill. Not many classic 2D games have this type of collision detection which is done by looking at pixels, but if you insist then I think you must do this:

First, do the standard box/rectangle-overlapping type of collision detection. If this is true, then you can proceed to look at what pixels are in the colliding zones (you must look at both). If they are transparent, return false... if not return true.

This is the quickest solution I can come up with right now, but I think it's pretty slow if you need to do it many times per frame.

Share this post


Link to post
Plenty of information out there about this, [google] "pixel-perfect collision detection" and you'll get more than enough articles.

But, it's generally not necessary. You could use the 80% rule, where you just use a bounding box that is 80% of the size of actual image. It works pretty darn well, and is much easier. And note that this also has the advantage that you can now resolve the collision, where as with pixel-perfect collision, you don't actually have any information with which to bounce objects around, or even to push them apart so that they don't collide anymore.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!