[Change] Cleaned up collision a little.
This commit is contained in:
parent
68b51e61bc
commit
1578278f00
@ -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) {
|
const glTexture* bt, const int bsx, const int bsy, const Vec2* bp) {
|
||||||
|
|
||||||
int x,y;
|
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.
|
// a - cube coords.
|
||||||
int ax1 = (int)VX(*ap) - (int)(at->sw)/2;
|
ax1 = (int)VX(*ap) - (int)(at->sw)/2;
|
||||||
int ay1 = (int)VY(*ap) - (int)(at->sh)/2;
|
ay1 = (int)VY(*ap) - (int)(at->sh)/2;
|
||||||
int ax2 = ax1 + (int)(at->sw) - 1;
|
ax2 = ax1 + (int)(at->sw) - 1;
|
||||||
int ay2 = ay1 + (int)(at->sh) - 1;
|
ay2 = ay1 + (int)(at->sh) - 1;
|
||||||
|
|
||||||
// b - cube coords.
|
// b - cube coords.
|
||||||
int bx1 = (int)VX(*bp) - (int)(bt->sw)/2;
|
bx1 = (int)VX(*bp) - (int)(bt->sw)/2;
|
||||||
int by1 = (int)VY(*bp) - (int)(bt->sh)/2;
|
by1 = (int)VY(*bp) - (int)(bt->sh)/2;
|
||||||
int bx2 = bx1 + (int)(bt->sw) - 1;
|
bx2 = bx1 + (int)(bt->sw) - 1;
|
||||||
int by2 = by1 + (int)(bt->sh) - 1;
|
by2 = by1 + (int)(bt->sh) - 1;
|
||||||
|
|
||||||
// Check if bounding boxes intersect.
|
// Check if bounding boxes intersect.
|
||||||
if((bx2 < ax1) || (ax2 < bx1)) return 0;
|
if((bx2 < ax1) || (ax2 < bx1)) return 0;
|
||||||
if((by2 < ay1) || (ay2 < by1)) return 0;
|
if((by2 < ay1) || (ay2 < by1)) return 0;
|
||||||
|
|
||||||
// Define the remaining binding box.
|
// Define the remaining binding box.
|
||||||
int inter_x0 = MAX(ax1, bx1);
|
inter_x0 = MAX(ax1, bx1);
|
||||||
int inter_x1 = MIN(ax2, bx2);
|
inter_x1 = MIN(ax2, bx2);
|
||||||
int inter_y0 = MAX(ay1, by1);
|
inter_y0 = MAX(ay1, by1);
|
||||||
int inter_y1 = MIN(ay2, by2);
|
inter_y1 = MIN(ay2, by2);
|
||||||
|
|
||||||
// Real vertical sprite value (flipped).
|
// Real vertical sprite value (flipped).
|
||||||
int rasy = at->sy - asy - 1;
|
rasy = at->sy - asy - 1;
|
||||||
int rbsy = bt->sy - bsy - 1;
|
rbsy = bt->sy - bsy - 1;
|
||||||
|
|
||||||
// Set up the base points.
|
// Set up the base points.
|
||||||
int abx = asx*(int)(at->sw) - ax1;
|
abx = asx*(int)(at->sw) - ax1;
|
||||||
int aby = rasy*(int)(at->sh) - ay1;
|
aby = rasy*(int)(at->sh) - ay1;
|
||||||
int bbx = bsx*(int)(bt->sw) - bx1;
|
bbx = bsx*(int)(bt->sw) - bx1;
|
||||||
int bby = rbsy*(int)(bt->sh) - by1;
|
bby = rbsy*(int)(bt->sh) - by1;
|
||||||
|
|
||||||
for(y = inter_y0; y <= inter_y1; y++)
|
for(y = inter_y0; y <= inter_y1; y++)
|
||||||
for(x = inter_x0; x <= inter_x1; x++)
|
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)) &&
|
if((!gl_isTrans(at, abx + x, aby + y)) &&
|
||||||
(!gl_isTrans(bt, bbx + x, bby + y)))
|
(!gl_isTrans(bt, bbx + x, bby + y)))
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user