• Advertisement
Sign in to follow this  

Color Key Collision Detection Help

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

Hi, can someone show me how to do "color key" collision detection. I have a tile of type LPDIRECT3DTEXTURE9, and I need to get the color of the x, y pixel so I can check for collision, anyone can show me how? Thanks

Share this post


Link to post
Share on other sites
Advertisement
I don't know how color collision works, but if you want to get pixel values from a texture, you simply need to call LockRect on it and get its D3DLOCKED_RECT.
Then you can access the texture bits as you would with a normal array (size increment depends on texture format, of course).

Hope this helps :)

Share this post


Link to post
Share on other sites
Let say I loaded a 640x 480 image.bmp image as texture. How would I go about getting the Color value at that pixel x y from the D3DLOCKED_RECT object? Sorry, I am very new at Window Programming, sample code would help. Thanks!

Share this post


Link to post
Share on other sites
something like this should do the trick:


D3DXCOLOR IMAGE[256 * 256]; // assumes source image is R8G8B8
D3DLOCKED_RECT pLockedRect;

if(FAILED(Texture->LockRect(0, &pLockedRect, NULL, D3DLOCK_READONLY)))
return false;
for (int y=0; y<IMAGE_SIZE; y++){
for (int x=0; x<IMAGE_SIZE; x++){
D3DXCOLOR color = *((DWORD*)(((BYTE*)pLockedRect.pBits) + pLockedRect.Pitch*y + x*sizeof(DWORD)));
IMAGE[x + y*IMAGE_SIZE] = color * 255;
}
}
Texture->UnlockRect(0);




Hope this helps :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
can you explain what does this mean in details.
D3DXCOLOR color = *((DWORD*)(((BYTE*)pLockedRect.pBits) + pLockedRect.Pitch*y + x*sizeof(DWORD)));

I know you convert pLockedRect.pBits to BYTEs and pLockedRect.pBits represent the texture in bits.

what does pLockedRect.Pitch*y + x*sizeof(DWORD)) do??

Share this post


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

  • Advertisement