I have tried your algorithm, but pixels of the original image never get overwritten, I have a logical problem there but can't get it
so first
1. is colliding
2. get the intersected rect
3. modify pixels <-- not working probably
cRect Intersection(const cRect& boundsA, const cRect& boundsB)
{
int x1 = Maximum(boundsA.x, boundsB.x);
int y1 = Maximum(boundsA.y, boundsB.y);
int x2 = Minimum(boundsA.x + boundsA.w, boundsB.x + boundsB.w);
int y2 = Minimum(boundsA.y + boundsA.h, boundsB.y + boundsB.h);
int width = x2 - x1;
int height = y2 - y1;
if (width > 0 && height > 0)
{
cRect intersect;
intersect.x = x1;
intersect.y = y1;
intersect.w = width;
intersect.h = height;
return intersect;
}
else
{
cRect intersect;
intersect.x = 0;
intersect.y = 0;
intersect.w = 0;
intersect.h = 0;
return intersect;
}
}
// check collision function()
bool CheckCollisionNewBarriers(Ship *ship, vector<Barrier*> *barriers, CIwTexture *tex, uint8*pixels, uint32 pitch)
{
for (vector<Barrier*>::iterator itBarrier = barriers->begin(); itBarrier != barriers->end();)
{
for (list<Bullet*>::iterator it = ship->Bullets->begin(); it != ship->Bullets->end();)
{
if (IntersectsWith((*it)->BoundingRect, (*itBarrier)->BoundingRect))
{
cRect bounding = Intersection((*it)->BoundingRect, (*itBarrier)->BoundingRect);
Iw2DDrawRect(CIwFVec2(bounding.x, bounding.y),CIwFVec2(20,20));
int bpp = 4;
uint8 pixelOffset = bounding.x*bpp + bounding.y*pitch;
pixels[pixelOffset] = 0xff000000;
tex->ChangeTexels(pixels);
tex->Upload();
}
}
Crap, it lost my changes. Well, let me re-write...
What are you trying to do with this?
Iw2DDrawRect(CIwFVec2(bounding.x, bounding.y),CIwFVec2(20,20));
You don't need to draw a rectangle on the current surface. That should be handled by setting the pixels on the block texture.
Which leads me to...
int bpp = 4;
uint8 pixelOffset = bounding.x*bpp + bounding.y*pitch;
pixels[pixelOffset] = 0xff000000;
tex->ChangeTexels(pixels);
tex->Upload();
Youre on the right path, but you're only setting a single pixel. You need to set an area of pixels arond the interseciton point to be able to see the block's explosion. You may also want to use GetFormat() to determine bpp and the format of the pixels (ARGB or BGRA).
Finally, remember, once the bullet is in the block's bounding box, you'll want to test the pixels to see if it's not black, and then cause a collision.
I think you'r eon the right track, keep working at it.