Jump to content
  • Advertisement

Archived

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

Stefaniii

Per pixel collision detection using textured quads?

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

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
Advertisement
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
Great thanks, that''s exactly what I was looking for. It''ll be much faster reading directly from memory and I won''t have to parse the bmp file.

Share this post


Link to post
Share on other sites

  • 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!