Archived

This topic is now archived and is closed to further replies.

Stefaniii

Per pixel collision detection using textured quads?

Recommended Posts

Is there any way to retrieve the pixels from a texture so that I can check whether the non-transparent parts of two textures are colliding? Bounding box collision aren''t really enough when using more complex shapes.

Share this post


Link to post
Share on other sites
Ok I think I''ve answered my own question for this. What I''m going to do is create bit masks for every sprite I load and store them in parallel and use them for collision detection. It won''t use much memory, since I only need 1 bit per pixel.

Does anyone have a guide or tutorial on how to create a bitmask from a graphics file like a bmp?

Share this post


Link to post
Share on other sites
quote:
Original post by Stefaniii
Ok I think I''ve answered my own question for this. What I''m going to do is create bit masks for every sprite I load and store them in parallel and use them for collision detection. It won''t use much memory, since I only need 1 bit per pixel.

Does anyone have a guide or tutorial on how to create a bitmask from a graphics file like a bmp?


That''s probably the best way to do it. As for actually creating the bitmask, you should probably use the texture itself, not the BMP file in case you later want to change file formats.

Look into IDirect3DTexture9::GetSurfaceLevel() and IDirect3DSurface9::LockRect()

These will allow you to read in the pixel data from a texture directly (and write to it too, for that matter). I strongly recommend only using this at load time. If you later decide you need to draw on a texture while the game is running, look into render targets.

Share this post


Link to post
Share on other sites