PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Collision on rotated surfaces?

Hi! I need to get a pixel from a rotated surface (i need for my pixel perfect collision detection routine).

In order to get a pixel color, i must create a raster object from a surface object, right? The problem is that blitted image is rotated and raster object isn't :)

So my routine can't check mask on both surfaces, because they are two different pictures

Do you have any suggestion to get pixel color from a rotated surface??

Thanks in advance for your time!
You can create a temporary surface, then draw your rotated surface on it as a bitmask. Then just use this new surface to check if the pixel is set or not. Simple! ;)
Yep, just made 30 seconds ago :D

I hope all that real-time rotating/temp-drawing won't kill my framerate!

Thanks for your support anyway ;)
Groan..damn'd explorer :D
You could create a bunch of buffered bitmasks for the surface angles you want to use (I'd say make 1 every 10 degrees) and store them somewhere, then just use them depending on the angle you want.

Speed has a price! ;) Memory is the price to pay. :)
kornalius wrote:
Speed has a price! ;) Memory is the price to pay. :)


When I want cut down the price I do the following :wink:

Code:
ui16 dy, dx;
ui16 tTotalW = SomeSurf->GetWidth();
ui16 tTotalH = SomeSurf->GetHeight();
Surface::LockInfo buf;
Pixel res;
SomeSurf->Lock(buf);
for(dy = 0; dy < tTotalH; dy++)
{
for(dx = 0; dx < tTotalW; dx++)
{
res = buf.pixels[dx+tTotalW*dy];
if(res != 0xf81f)//Color(255, 0, 255) or your custom mask color
{
//Do something with res pixel
}
}
}
SomeSurf->Unlock();


With this you can access to the surface's Pixels.
I think to make collision detection for rotated ones, it's better to look into the code of BlitRotated, adopt it to our needs (Or how it's called) and compare some resulting "res" Pixels.
It would be faster than blitting, and take less space than prerotated masks.

But the price still in there. It would be the coding price :D