[Change] Cleaned up collision a little.

This commit is contained in:
Allanis 2013-02-27 00:05:52 +00:00
parent 68b51e61bc
commit 1578278f00

View File

@ -15,42 +15,47 @@ int CollideSprite(const glTexture* at, const int asx, const int asy, const Vec2*
const glTexture* bt, const int bsx, const int bsy, const Vec2* bp) {
int x,y;
int ax1, ax2, ay1, ay2;
int bx1, bx2, by1, by2;
int inter_x0, inter_x1, inter_y0, inter_y1;
int rasy, rbsy;
int abx, aby, bbx, bby;
// a - cube coords.
int ax1 = (int)VX(*ap) - (int)(at->sw)/2;
int ay1 = (int)VY(*ap) - (int)(at->sh)/2;
int ax2 = ax1 + (int)(at->sw) - 1;
int ay2 = ay1 + (int)(at->sh) - 1;
ax1 = (int)VX(*ap) - (int)(at->sw)/2;
ay1 = (int)VY(*ap) - (int)(at->sh)/2;
ax2 = ax1 + (int)(at->sw) - 1;
ay2 = ay1 + (int)(at->sh) - 1;
// b - cube coords.
int bx1 = (int)VX(*bp) - (int)(bt->sw)/2;
int by1 = (int)VY(*bp) - (int)(bt->sh)/2;
int bx2 = bx1 + (int)(bt->sw) - 1;
int by2 = by1 + (int)(bt->sh) - 1;
bx1 = (int)VX(*bp) - (int)(bt->sw)/2;
by1 = (int)VY(*bp) - (int)(bt->sh)/2;
bx2 = bx1 + (int)(bt->sw) - 1;
by2 = by1 + (int)(bt->sh) - 1;
// Check if bounding boxes intersect.
if((bx2 < ax1) || (ax2 < bx1)) return 0;
if((by2 < ay1) || (ay2 < by1)) return 0;
// Define the remaining binding box.
int inter_x0 = MAX(ax1, bx1);
int inter_x1 = MIN(ax2, bx2);
int inter_y0 = MAX(ay1, by1);
int inter_y1 = MIN(ay2, by2);
inter_x0 = MAX(ax1, bx1);
inter_x1 = MIN(ax2, bx2);
inter_y0 = MAX(ay1, by1);
inter_y1 = MIN(ay2, by2);
// Real vertical sprite value (flipped).
int rasy = at->sy - asy - 1;
int rbsy = bt->sy - bsy - 1;
rasy = at->sy - asy - 1;
rbsy = bt->sy - bsy - 1;
// Set up the base points.
int abx = asx*(int)(at->sw) - ax1;
int aby = rasy*(int)(at->sh) - ay1;
int bbx = bsx*(int)(bt->sw) - bx1;
int bby = rbsy*(int)(bt->sh) - by1;
abx = asx*(int)(at->sw) - ax1;
aby = rasy*(int)(at->sh) - ay1;
bbx = bsx*(int)(bt->sw) - bx1;
bby = rbsy*(int)(bt->sh) - by1;
for(y = inter_y0; y <= inter_y1; y++)
for(x = inter_x0; x <= inter_x1; x++)
// Computer offsets for surface before passing to TransparentPixel test.
// Compute offsets for surface before passing to TransparentPixel test.
if((!gl_isTrans(at, abx + x, aby + y)) &&
(!gl_isTrans(bt, bbx + x, bby + y)))
return 1;