Archived

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

pixel collision.. is it the math or the lPitch

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

Below is some code I have been trying to hammer out for the past few daze. Searching on here hogging bandwidth doesn't seem to help, so here goes. The first part initializes the hitmap, as suggested in a previous thread. For debrugging purposes, I made the bitmaps an arbitrary 128x128 in size. The bitmap is 24bit, screen is opened up at 800x600x16 in dx7 mode. It is using a black (RGB(0,0,0)) colorkey. int InitCollisions(DD7S obj, int *hitmap) { int i; int j; COLORREF dt; HDC hdc; obj->GetDC(&hdc); for (j=0; j < 128; j++) for (i=0; i < 128; i++) { dt = GetPixel(hdc,i,j); if (dt == RGB(0,0,0)) hitmap[(j*128)+i] = 0; else hitmap[(j*128)+i] = 1; } obj->ReleaseDC(hdc); } This second part, I am using GetDC rather than lock/unlock.. why? I don't care about speed yet, this is initialization stuff anyway before the main loop. I am trying to get the math of this, I thought I had a simple formula figured out to get the crossing region within the bounding boxes and it partly works. The bitmap goes almost halfway into the other bitmap before colliding, less the blank space around it, I bet it is colliding in the center of the tile. Please help. Thanx int Collide(int *hitmap1, int *hitmap2, int sx, int sy, int dx, int dy) { int i, j, mx, my, nx, ny, ecx, ecy; // intense debrugging int col=0; mx = 0; my = 0; // mx and my always at origin of virtual collision mask map(VCMM) nx = abs(sx-dx); // nx = offset from border of tile1 into tile2 ny = abs(sy-dy); // ny = offset from border of tile1 into tile2 ecx = (128-nx); // compute width of overlapping virtual tiles ecy = (128-ny); // compute height of overlapping virtual tiles if ((nx >= 128) || (ny >= 128)) return(0); // trivial rejection for (j=ny; j < ecy; j++) for (i=nx; i < ecx; i++) if (hitmap1[(j*128)+i] & hitmap2[(j*128)+i]) return 1; return col; } I fseek, therefore I fam. [edited by - drarem on June 28, 2002 3:33:20 AM]

Share this post


Link to post
Share on other sites
Newer code, has the exact same effect.


int Collide(int *hitmap1, int *hitmap2, int sx, int sy, int dx, int dy) {
int i, j, ms, me, nx, ny, ecs, ece; // intense debrugging
int col=0, ncx=0, ncy=0;

// mx = 0; my = 0; // mx and my always at origin of virtual collision mask map(VCMM)

nx = abs(sx-dx); // nx = offset from border of tile1 into tile2
ny = abs(sy-dy); // ny = offset from border of tile1 into tile2
ece = 128; // end
ecs = (nx); // start
me = 128; // end
ms = (ny); // start

if ((nx >= 128) || (ny >= 128)) return(0); // trivial rejection
ncx=nx; ncy=ny;
for (j=ms; j < me; j++)
for (i=ecs; i < ece; i++) {
if (hitmap1[(j*128) + i] & hitmap2[(ncy*128) + ncx])
return 1;
ncx++;
if (ncx >= (ece)) { ncx=nx; ncy++; }
}
return col;
}

I fseek, therefore I fam.

Share this post


Link to post
Share on other sites
Getting closer! Coming from the top and bottom, collisions work great now, only the sides I need to work out. If anyone makes lots of money with this code, please gimme some. lator


int Collide(int *hitmap1, int *hitmap2, int sx, int sy, int dx, int dy) {
int i, j, ms, me, nx, ny, ecs, ece; // intense debrugging
int col=0, ncx=0, ncy=0;

// mx = 0; my = 0; // mx and my always at origin of virtual collision mask map(VCMM)

nx = abs(sx-dx); // nx = offset from border of tile1 into tile2
ny = abs(sy-dy); // ny = offset from border of tile1 into tile2
ece = 128; // end
ecs = (nx); // start
me = 128; // end
ms = (ny); // start

if ((nx >= 128) || (ny >= 128)) return(0); // trivial rejection
ncx=0; ncy=0;

for (j=ms; j < me; j++)
for (i=ecs; i < ece; i++) {
if (hitmap1[(j*128) + i] & hitmap2[(ncy*128) + ncx])
return 1;
ncx++;
if (ncx >= (ece-nx)) { ncx=0; ncy++; }
}
return col;
}

I fseek, therefore I fam.

Share this post


Link to post
Share on other sites