Jump to content
  • Advertisement
Sign in to follow this  
Sync Views

precise collision checking

This topic is 3880 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

Each collision-able object has a vector containing: struct bbox{int x, y, w, h;}; Ive got a function for checking for a collision useing these vectors but I want a way to generate the vector from a sprite useing as few boxes as possible (eg not useing a new box for every pixel). The vector need to cover every pixel that isn't transparent (both alpha layer and colour keys need to work). I'm useing DirectX9 (90% of grafics are useing Direct3D)

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Sync Views
Ive got a function for checking for a collision useing these vectors but I want a way to generate the vector from a sprite useing as few boxes as possible (eg not useing a new box for every pixel).

The vector need to cover every pixel that isn't transparent (both alpha layer and colour keys need to work).


You'll probably want to clarify what you mean here. Do you mean you want vectors coming from the face of a quad, one for each nontransparent pixel? Or are you intersecting a quad with a single vector, and want to determine the pixel transparency of the quad at the point it intersects?

Share this post


Link to post
Share on other sites
So you want to use a ton of bounding boxes representing the pixels to get that pixel perfect collision? That'd be inefficient no matter what.

You don't need to limit your collision detection to rays and bounding boxes. Why not just cast a ray against the quad, determine where it intersects, and using the texture coordinates of that location, look up the pixel in the texture?

[Edited by - gharen2 on February 6, 2008 2:28:21 PM]

Share this post


Link to post
Share on other sites
???

Ive not got a clue what you mean? What do you meen by ray? Do you have a link to a good pixel perfect 2d collision system useing that?

Share this post


Link to post
Share on other sites
Pixel-precise collision detection is usually done using... pixels. Of course, a smart person will first check the bounding boxes of two sprites: if these don't collide, no pixels can collide, so no further pixel checks are required, you simply give a negative reply.

If the bounding boxes do collide, then you only need to compare pixels in the overlapping area. In 99% of the cases, it's best to just use pixel-pixel checks: if both are solid, then the sprites collide and you can bail out of the check with a positive reply. Using bounding boxes for per-pixel checks only adds overhead and makes things more complicated.


However, you may want to reconsider the need for pixel-precise collision detection. For many gameplay purposes, a single bounding box is more than sufficient. In most other cases, you can get away using a few more precise boxes, for example when hitting different bodyparts is important.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sync Views
???

Ive not got a clue what you mean?


That's ok, I don't entirely understand what you're trying to ask :)

Quote:
Original post by Sync Views
What do you meen by ray? Do you have a link to a good pixel perfect 2d collision system useing that?


A ray is well... a ray. A 3D line. But my suggestion actually doesn't help you much, because I misunderstood what you were trying to ask.

So to be clear, you have two 2D sprites, and want to check if their pixels overlap to determine collision between them, correct?

If so, Captain P's answer is perfect. So to combine our two ideas: when two boxes overlap, for each pixel that overlaps, look up the corresponding value in the textures. If they're both nontransparent, a collision occurred.

But Captain P is right, that's woefully inefficient. It's better to do more crude collisions against smaller boxes that loosely surround the sprite. 95% of the time the user won't notice the difference, and it'll be WAY faster.

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!